summaryrefslogtreecommitdiff
path: root/gr-analog
diff options
context:
space:
mode:
Diffstat (limited to 'gr-analog')
-rw-r--r--gr-analog/include/analog/CMakeLists.txt1
-rw-r--r--gr-analog/include/analog/fmdet_cf.h70
-rw-r--r--gr-analog/lib/CMakeLists.txt1
-rw-r--r--gr-analog/lib/fmdet_cf_impl.cc129
-rw-r--r--gr-analog/lib/fmdet_cf_impl.h62
-rw-r--r--gr-analog/python/qa_fmdet.py80
-rw-r--r--gr-analog/swig/analog_swig.i3
7 files changed, 346 insertions, 0 deletions
diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt
index 40af6e55d..3c049bfd3 100644
--- a/gr-analog/include/analog/CMakeLists.txt
+++ b/gr-analog/include/analog/CMakeLists.txt
@@ -88,6 +88,7 @@ install(FILES
ctcss_squelch_ff.h
dpll_bb.h
feedforward_agc_cc.h
+ fmdet_cf.j
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/analog
COMPONENT "analog_devel"
)
diff --git a/gr-analog/include/analog/fmdet_cf.h b/gr-analog/include/analog/fmdet_cf.h
new file mode 100644
index 000000000..6878775e6
--- /dev/null
+++ b/gr-analog/include/analog/fmdet_cf.h
@@ -0,0 +1,70 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * 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.
+ */
+
+#ifndef INCLUDED_ANALOG_FMDET_CF_H
+#define INCLUDED_ANALOG_FMDET_CF_H
+
+#include <analog/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief Implements an IQ slope detector
+ *
+ * input: stream of complex; output: stream of floats
+ *
+ * This implements a limiting slope detector. The limiter is in
+ * the normalization by the magnitude of the sample
+ */
+ class ANALOG_API fmdet_cf : virtual public gr_sync_block
+ {
+ public:
+ // gr::analog::fmdet_cf::sptr
+ typedef boost::shared_ptr<fmdet_cf> sptr;
+
+ /*!
+ * \brief Make FM detector block.
+ *
+ * \param samplerate sample rate of signal (is not used; to be removed)
+ * \param freq_low lowest frequency of signal (Hz)
+ * \param freq_high highest frequency of signal (Hz)
+ * \param scl scale factor
+ */
+ static sptr make(float samplerate, float freq_low,
+ float freq_high, float scl);
+
+ virtual void set_scale(float scl) = 0;
+ virtual void set_freq_range(float freq_low, float freq_high) = 0;
+
+ virtual float freq() const = 0;
+ virtual float freq_high() const = 0;
+ virtual float freq_low() const = 0;
+ virtual float scale() const = 0;
+ virtual float bias() const = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_FMDET_CF_H */
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt
index 258d5d67c..abceed3e1 100644
--- a/gr-analog/lib/CMakeLists.txt
+++ b/gr-analog/lib/CMakeLists.txt
@@ -114,6 +114,7 @@ list(APPEND analog_sources
ctcss_squelch_ff_impl.cc
dpll_bb_impl.cc
feedforward_agc_cc_impl.cc
+ fmdet_cf_impl.cc
)
list(APPEND analog_libs
diff --git a/gr-analog/lib/fmdet_cf_impl.cc b/gr-analog/lib/fmdet_cf_impl.cc
new file mode 100644
index 000000000..d3a58966b
--- /dev/null
+++ b/gr-analog/lib/fmdet_cf_impl.cc
@@ -0,0 +1,129 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008,2010,2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "fmdet_cf_impl.h"
+#include <gr_io_signature.h>
+#include <gr_math.h>
+
+namespace gr {
+ namespace analog {
+
+#define M_TWOPI (2*M_PI)
+
+ fmdet_cf::sptr
+ fmdet_cf::make(float samplerate, float freq_low,
+ float freq_high, float scl)
+ {
+ return gnuradio::get_initial_sptr
+ (new fmdet_cf_impl(samplerate, freq_low, freq_high, scl));
+ }
+
+ fmdet_cf_impl::fmdet_cf_impl(float samplerate, float freq_low,
+ float freq_high, float scl)
+ : gr_sync_block("fmdet_cf",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)),
+ gr_make_io_signature(1, 1, sizeof(float))),
+ d_S1(0.1), d_S2(0.1),
+ d_S3(0.1), d_S4(0.1)
+ {
+ const float h[] = { 0.003118678733, -0.012139843428, 0.027270898036,
+ -0.051318579352, 0.090406910552, -0.162926865366,
+ 0.361885392563, 0.000000000000, -0.361885392563,
+ 0.162926865366, -0.090406910552, 0.051318579352,
+ -0.027270898036, 0.012139843428, -0.003118678733};
+
+ //std::vector<float> taps(15);
+
+ d_freq = 0;
+ d_freqhi = freq_high;
+ d_freqlo = freq_low;
+ set_scale(scl);
+
+ //for(int i = 0; i < 15; i++) {
+ //taps[i] = h[i];
+ //}
+ // d_filter = gr_fir_util::create_gr_fir_ccf(taps);
+ }
+
+ fmdet_cf_impl::~fmdet_cf_impl()
+ {
+ }
+
+ void
+ fmdet_cf_impl::set_scale(float scl)
+ {
+ float delta = d_freqhi - d_freqlo;
+ d_scl = scl;
+ d_bias = 0.5*scl*(d_freqhi + d_freqlo) / delta;
+ }
+
+ void
+ fmdet_cf_impl::set_freq_range(float freq_low, float freq_high)
+ {
+ d_freqhi = freq_high;
+ d_freqlo = freq_low;
+ set_scale(d_scl);
+ }
+
+ int
+ fmdet_cf_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const gr_complex *iptr = (gr_complex*)input_items[0];
+ float *optr = (float*)output_items[0];
+ //const gr_complex *scaleiptr = (gr_complex*)input_items[0];
+
+ int size = noutput_items;
+
+ gr_complex Sdot, S0;
+ gr_complex S1=d_S1, S2=d_S2, S3=d_S3, S4=d_S4;
+ float d_8 = 8.0;
+
+ while(size-- > 0) {
+ S0 = *iptr++;
+
+ Sdot = d_scl * (-S0+d_8*S1-d_8*S1+S4);
+
+ d_freq = (S2.real()*Sdot.imag()-S2.imag()*Sdot.real()) /
+ (S2.real()*S2.real()+S2.imag()*S2.imag());
+
+ S4 = S3;
+ S3 = S2;
+ S2 = S1;
+ S1 = S0;
+
+ *optr++ = d_freq-d_bias;
+ }
+ d_S1 = S1;
+ d_S2 = S2;
+ d_S3 = S3;
+ d_S4 = S4;
+ return noutput_items;
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/fmdet_cf_impl.h b/gr-analog/lib/fmdet_cf_impl.h
new file mode 100644
index 000000000..01fce09dd
--- /dev/null
+++ b/gr-analog/lib/fmdet_cf_impl.h
@@ -0,0 +1,62 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008, 2012 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * 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.
+ */
+
+#ifndef INCLUDED_ANALOG_FMDET_CF_IMPL_H
+#define INCLUDED_ANALOG_FMDET_CF_IMPL_H
+
+#include <analog/fmdet_cf.h>
+//#include <filter/fir_filter.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace analog {
+
+ class fmdet_cf_impl : public fmdet_cf
+ {
+ private:
+ gr_complex d_S1, d_S2, d_S3, d_S4;
+ float d_freq, d_freqlo, d_freqhi, d_scl, d_bias;
+ //kernel::fir_filter_ccf* d_filter;
+
+ public:
+ fmdet_cf_impl(float samplerate, float freq_low,
+ float freq_high, float scl);
+ ~fmdet_cf_impl();
+
+ void set_scale(float scl);
+ void set_freq_range(float freq_low, float freq_high);
+
+ float freq() const { return d_freq; }
+ float freq_high() const { return d_freqhi; }
+ float freq_low() const { return d_freqlo; }
+ float scale() const { return d_scl; }
+ float bias() const { return d_bias; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_FMDET_CF_IMPL_H */
diff --git a/gr-analog/python/qa_fmdet.py b/gr-analog/python/qa_fmdet.py
new file mode 100644
index 000000000..b90ef2ffa
--- /dev/null
+++ b/gr-analog/python/qa_fmdet.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+#
+# Copyright 2012 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# 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.
+#
+
+from gnuradio import gr, gr_unittest
+import analog_swig as analog
+import math
+
+class test_fmdet_cf(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_fmdet_cf_001(self):
+ # Test set/gets
+
+ fh1 = 10
+ fh2 = 20
+ fl1 = 1
+ fl2 = 2
+ scale1 = 3
+ scale2 = 4
+ op = analog.fmdet_cf(1, fl1, fh1, scale1)
+
+ op.set_freq_range(fl2, fh2)
+ lo = op.freq_low()
+ hi = op.freq_high()
+ f = op.freq()
+ self.assertEqual(fl2, lo)
+ self.assertEqual(fh2, hi)
+ self.assertEqual(0, f)
+
+ op.set_scale(scale2)
+ s = op.scale()
+ b = op.bias()
+ eb = 0.5*scale2*(hi + lo) / (hi - lo);
+ self.assertEqual(scale2, s)
+ self.assertAlmostEqual(eb, b)
+
+ # FIXME: This passes QA, but the it's only based off what the
+ # block is saying, not what the values should actually be.
+ def est_fmdet_cf_002(self):
+ N = 100
+ src = gr.sig_source_c(1, gr.GR_SIN_WAVE, 0.2, 1)
+ head = gr.head(gr.sizeof_gr_complex, N)
+ op = analog.fmdet_cf(1, 0.1, 0.3, 0.1)
+ dst = gr.vector_sink_f()
+
+ self.tb.connect(src, head, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ result_data = dst.data()[4:N]
+ expected_result = (100-4)*[-0.21755,]
+ self.assertFloatTuplesAlmostEqual(expected_result, result_data, 4)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_fmdet_cf, "test_fmdet_cf.xml")
+
diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i
index 135bfb859..fec099a6c 100644
--- a/gr-analog/swig/analog_swig.i
+++ b/gr-analog/swig/analog_swig.i
@@ -36,6 +36,7 @@
#include "analog/ctcss_squelch_ff.h"
#include "analog/dpll_bb.h"
#include "analog/feedforward_agc_cc.h"
+#include "analog/fmdet_cf.h"
#include "analog/squelch_base_cc.h"
#include "analog/squelch_base_ff.h"
%}
@@ -49,6 +50,7 @@
%include "analog/ctcss_squelch_ff.h"
%include "analog/dpll_bb.h"
%include "analog/feedforward_agc_cc.h"
+%include "analog/fmdet_cf.h"
%include "analog/squelch_base_cc.h"
%include "analog/squelch_base_ff.h"
@@ -60,3 +62,4 @@ GR_SWIG_BLOCK_MAGIC2(analog, cpfsk_bc);
GR_SWIG_BLOCK_MAGIC2(analog, ctcss_squelch_ff);
GR_SWIG_BLOCK_MAGIC2(analog, dpll_bb);
GR_SWIG_BLOCK_MAGIC2(analog, feedforward_agc_cc);
+GR_SWIG_BLOCK_MAGIC2(analog, fmdet_cf);