summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2013-03-02 23:27:50 +0100
committerSylvain Munaut <tnt@246tNt.com>2013-03-02 23:27:50 +0100
commit0d0d34af05b68d57f97030e401b1cd2a95e58d9b (patch)
tree98b9a3a3ef9df9910779db2b6a9aca9662980fcd /lib
Initial import
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/CMakeLists.txt44
-rw-r--r--lib/iqbalance_fix_cc.cc87
-rw-r--r--lib/iqbalance_optimize_c.cc127
3 files changed, 258 insertions, 0 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
new file mode 100644
index 0000000..2c4e2b9
--- /dev/null
+++ b/lib/CMakeLists.txt
@@ -0,0 +1,44 @@
+# Copyright 2011 Free Software Foundation, Inc.
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+
+########################################################################
+# Setup library
+########################################################################
+include(GrPlatform) #define LIB_SUFFIX
+add_library(gnuradio-iqbalance SHARED iqbalance_fix_cc.cc iqbalance_optimize_c.cc )
+target_link_libraries(gnuradio-iqbalance ${Boost_LIBRARIES} ${GRUEL_LIBRARIES} ${GNURADIO_CORE_LIBRARIES} ${LIBOSMODSP_LIBRARIES})
+set_target_properties(gnuradio-iqbalance PROPERTIES DEFINE_SYMBOL "gnuradio_iqbalance_EXPORTS")
+
+########################################################################
+# Install built library files
+########################################################################
+install(TARGETS gnuradio-iqbalance
+ LIBRARY DESTINATION lib${LIB_SUFFIX} # .so/.dylib file
+ ARCHIVE DESTINATION lib${LIB_SUFFIX} # .lib file
+ RUNTIME DESTINATION bin # .dll file
+)
+
+########################################################################
+# Build and register unit test
+########################################################################
+find_package(Boost COMPONENTS unit_test_framework)
+
+include(GrTest)
+set(GR_TEST_TARGET_DEPS gnuradio-iqbalance)
+#turn each test cpp file into an executable with an int main() function
+add_definitions(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN)
+
diff --git a/lib/iqbalance_fix_cc.cc b/lib/iqbalance_fix_cc.cc
new file mode 100644
index 0000000..04389cc
--- /dev/null
+++ b/lib/iqbalance_fix_cc.cc
@@ -0,0 +1,87 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013 Sylvain Munaut <tnt@246tNt.com>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_io_signature.h>
+#include "iqbalance_fix_cc.h"
+
+
+iqbalance_fix_cc_sptr
+iqbalance_make_fix_cc (float mag, float phase)
+{
+ return gnuradio::get_initial_sptr (new iqbalance_fix_cc(mag, phase));
+}
+
+
+iqbalance_fix_cc::iqbalance_fix_cc (float mag, float phase)
+ : gr_sync_block ("fix_cc",
+ gr_make_io_signature(1, 1, sizeof (gr_complex)),
+ gr_make_io_signature(1, 1, sizeof (gr_complex))),
+ d_mag(mag),
+ d_phase(phase)
+{
+ message_port_register_in(pmt::mp("iqbal_corr"));
+ set_msg_handler(pmt::mp("iqbal_corr"),
+ boost::bind(&iqbalance_fix_cc::apply_new_corrections, this, _1));
+}
+
+
+iqbalance_fix_cc::~iqbalance_fix_cc()
+{
+ /* Nothing to do */
+}
+
+
+void
+iqbalance_fix_cc::apply_new_corrections (pmt::pmt_t msg)
+{
+ if (!pmt_is_f32vector(msg))
+ return;
+
+ this->set_mag(pmt_f32vector_ref(msg, 0));
+ this->set_phase(pmt_f32vector_ref(msg, 1));
+}
+
+
+int
+iqbalance_fix_cc::work (int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ const gr_complex *in = (const gr_complex *) input_items[0];
+ gr_complex *out = (gr_complex *) output_items[0];
+ int i;
+
+ const float magp1 = 1.0f + this->d_mag;
+ const float phase = this->d_phase;
+
+ for (i=0; i<noutput_items; i++) {
+ gr_complex v = in[i];
+ out[i] = gr_complex(
+ v.real() * magp1,
+ v.imag() + phase * v.real()
+ );
+ }
+
+ return noutput_items;
+}
diff --git a/lib/iqbalance_optimize_c.cc b/lib/iqbalance_optimize_c.cc
new file mode 100644
index 0000000..17fcfc2
--- /dev/null
+++ b/lib/iqbalance_optimize_c.cc
@@ -0,0 +1,127 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2013 Sylvain Munaut <tnt@246tNt.com>
+ *
+ * This is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this software; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_io_signature.h>
+#include "iqbalance_optimize_c.h"
+
+extern "C" {
+#include <osmocom/dsp/cxvec.h>
+#include <osmocom/dsp/iqbal.h>
+}
+
+#define FFT_SIZE 1024
+#define FFT_COUNT 4
+
+
+iqbalance_optimize_c_sptr
+iqbalance_make_optimize_c (int period)
+{
+ return gnuradio::get_initial_sptr (new iqbalance_optimize_c(period));
+}
+
+iqbalance_optimize_c::iqbalance_optimize_c (int period)
+ : gr_sync_block ("optimize_c",
+ gr_make_io_signature(1, 1, sizeof (gr_complex)),
+ gr_make_io_signature(0, 0, 0)),
+ d_period(period), d_first(true), d_mag(0.0f), d_phase(0.0f)
+{
+ message_port_register_out(pmt::mp("iqbal_corr"));
+}
+
+
+iqbalance_optimize_c::~iqbalance_optimize_c()
+{
+ /* Nothing to do */
+}
+
+
+void
+iqbalance_optimize_c::forecast (int noutput_items, gr_vector_int &ninput_items_required)
+{
+ unsigned ninputs = ninput_items_required.size ();
+ for (unsigned i = 0; i < ninputs; i++)
+ ninput_items_required[i] = FFT_SIZE * FFT_COUNT;
+}
+
+#include <stdio.h>
+int
+iqbalance_optimize_c::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+{
+ const gr_complex *in = (const gr_complex *) input_items[0];
+ const int N = FFT_SIZE * FFT_COUNT;
+ struct osmo_cxvec _sig, *sig = &_sig;
+ struct osmo_iqbal_opts opts;
+ float p[2];
+
+ if (!this->d_period)
+ return noutput_items;
+
+ if (this->d_count) {
+ int missing = this->d_period - this->d_count;
+
+ if (missing <= 0) {
+ this->d_count = 0;
+ return 0;
+ } else if (missing >= noutput_items) {
+ this->d_count += noutput_items;
+ return noutput_items;
+ } else {
+ this->d_count = 0;
+ return missing;
+ }
+ }
+
+ if (noutput_items < N)
+ return 0;
+
+ this->d_count += N;
+
+ memcpy(&opts, &osmo_iqbal_default_opts, sizeof(opts));
+ opts.fft_size = FFT_SIZE;
+ opts.fft_count = FFT_COUNT;
+ opts.start_at_prev = 0;
+
+ osmo_cxvec_init_from_data(sig, (float complex *)in, N);
+ osmo_iqbal_cxvec_optimize(sig, &p[0], &p[1], &opts);
+
+ if (this->d_first) {
+ this->d_first = false;
+ this->d_mag = p[0];
+ this->d_phase = p[1];
+ } else {
+ this->d_mag = (0.95f * this->d_mag ) + (p[0] * 0.05f);
+ this->d_phase = (0.95f * this->d_phase) + (p[1] * 0.05f);
+ }
+
+ printf("%d %e %e\n", this->d_period, this->d_mag, this->d_phase);
+
+ p[0] = this->d_mag;
+ p[1] = this->d_phase;
+ pmt::pmt_t msg = pmt::pmt_init_f32vector(2, p);
+ message_port_pub(pmt::mp("iqbal_corr"), msg);
+
+ return N;
+}