summaryrefslogtreecommitdiff
path: root/gr-analog
diff options
context:
space:
mode:
Diffstat (limited to 'gr-analog')
-rw-r--r--gr-analog/grc/analog_block_tree.xml1
-rw-r--r--gr-analog/grc/analog_quadrature_demod_cf.xml26
-rw-r--r--gr-analog/include/analog/CMakeLists.txt1
-rw-r--r--gr-analog/include/analog/quadrature_demod_cf.h54
-rw-r--r--gr-analog/lib/CMakeLists.txt1
-rw-r--r--gr-analog/lib/quadrature_demod_cf_impl.cc72
-rw-r--r--gr-analog/lib/quadrature_demod_cf_impl.h51
-rwxr-xr-xgr-analog/python/qa_quadrature_demod.py63
-rw-r--r--gr-analog/swig/analog_swig.i3
9 files changed, 272 insertions, 0 deletions
diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml
index a25123f4a..99255d759 100644
--- a/gr-analog/grc/analog_block_tree.xml
+++ b/gr-analog/grc/analog_block_tree.xml
@@ -44,6 +44,7 @@
<block>analog_cpfsk_bc</block>
<block>analog_frequency_modulator_fc</block>
<block>analog_phase_modulator_fc</block>
+ <block>analog_quadrature_demod_cf</block>
</cat>
<cat>
<name>Sources</name>
diff --git a/gr-analog/grc/analog_quadrature_demod_cf.xml b/gr-analog/grc/analog_quadrature_demod_cf.xml
new file mode 100644
index 000000000..a60653135
--- /dev/null
+++ b/gr-analog/grc/analog_quadrature_demod_cf.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Quadrature Demodulator
+###################################################
+ -->
+<block>
+ <name>Quadrature Demod</name>
+ <key>analog_quadrature_demod_cf</key>
+ <import>from gnuradio import analog</import>
+ <make>analog.quadrature_demod_cf($gain)</make>
+ <callback>set_gain($gain)</callback>
+ <param>
+ <name>Gain</name>
+ <key>gain</key>
+ <type>real</type>
+ </param>
+ <sink>
+ <name>in</name>
+ <type>complex</type>
+ </sink>
+ <source>
+ <name>out</name>
+ <type>float</type>
+ </source>
+</block>
diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt
index 4623fb2dd..4de94a88b 100644
--- a/gr-analog/include/analog/CMakeLists.txt
+++ b/gr-analog/include/analog/CMakeLists.txt
@@ -100,6 +100,7 @@ install(FILES
probe_avg_mag_sqrd_f.h
pwr_squelch_cc.h
pwr_squelch_ff.h
+ quadrature_demod_cf.h
rail_ff.h
rotator.h
sig_source_waveform.h
diff --git a/gr-analog/include/analog/quadrature_demod_cf.h b/gr-analog/include/analog/quadrature_demod_cf.h
new file mode 100644
index 000000000..916d8b2ec
--- /dev/null
+++ b/gr-analog/include/analog/quadrature_demod_cf.h
@@ -0,0 +1,54 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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_QUADRATURE_DEMOD_CF_H
+#define INCLUDED_ANALOG_QUADRATURE_DEMOD_CF_H
+
+#include <analog/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace analog {
+
+ /*!
+ * \brief quadrature demodulator: complex in, float out
+ * \ingroup demodulation_blk
+ *
+ * This can be used to demod FM, FSK, GMSK, etc.
+ * The input is complex baseband.
+ */
+ class ANALOG_API quadrature_demod_cf : virtual public gr_sync_block
+ {
+ public:
+ // gr::analog::quadrature_demod_cf::sptr
+ typedef boost::shared_ptr<quadrature_demod_cf> sptr;
+
+ static sptr make(float gain);
+
+ virtual void set_gain(float gain) = 0;
+ virtual float gain() const = 0;
+ };
+
+ } /* namespace analog */
+} /* namespace gr */
+
+#endif /* INCLUDED_ANALOG_QUADRATURE_DEMOD_CF_H */
diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt
index f912649d9..5e7d131b0 100644
--- a/gr-analog/lib/CMakeLists.txt
+++ b/gr-analog/lib/CMakeLists.txt
@@ -128,6 +128,7 @@ list(APPEND analog_sources
probe_avg_mag_sqrd_f_impl.cc
pwr_squelch_cc_impl.cc
pwr_squelch_ff_impl.cc
+ quadrature_demod_cf_impl.cc
rail_ff_impl.cc
simple_squelch_cc_impl.cc
)
diff --git a/gr-analog/lib/quadrature_demod_cf_impl.cc b/gr-analog/lib/quadrature_demod_cf_impl.cc
new file mode 100644
index 000000000..9490ba6be
--- /dev/null
+++ b/gr-analog/lib/quadrature_demod_cf_impl.cc
@@ -0,0 +1,72 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2005,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 "quadrature_demod_cf_impl.h"
+#include <gr_io_signature.h>
+#include <gr_math.h>
+
+namespace gr {
+ namespace analog {
+
+ quadrature_demod_cf::sptr
+ quadrature_demod_cf::make(float gain)
+ {
+ return gnuradio::get_initial_sptr
+ (new quadrature_demod_cf_impl(gain));
+ }
+
+ quadrature_demod_cf_impl::quadrature_demod_cf_impl(float gain)
+ : gr_sync_block("quadrature_demod_cf",
+ gr_make_io_signature(1, 1, sizeof(gr_complex)),
+ gr_make_io_signature(1, 1, sizeof(float))),
+ d_gain(gain)
+ {
+ set_history(2); // we need to look at the previous value
+ }
+
+ quadrature_demod_cf_impl::~quadrature_demod_cf_impl()
+ {
+ }
+
+ int
+ quadrature_demod_cf_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ gr_complex *in = (gr_complex*)input_items[0];
+ float *out = (float*)output_items[0];
+ in++; // ensure that in[-1] is valid
+
+ for(int i = 0; i < noutput_items; i++) {
+ gr_complex product = in[i] * conj(in[i-1]);
+ out[i] = d_gain * gr_fast_atan2f(imag(product), real(product));
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace analog */
+} /* namespace gr */
diff --git a/gr-analog/lib/quadrature_demod_cf_impl.h b/gr-analog/lib/quadrature_demod_cf_impl.h
new file mode 100644
index 000000000..72beb2331
--- /dev/null
+++ b/gr-analog/lib/quadrature_demod_cf_impl.h
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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_QUADRATURE_DEMOD_CF_IMPL_H
+#define INCLUDED_ANALOG_QUADRATURE_DEMOD_CF_IMPL_H
+
+#include <analog/quadrature_demod_cf.h>
+
+namespace gr {
+ namespace analog {
+
+ class quadrature_demod_cf_impl : public quadrature_demod_cf
+ {
+ private:
+ float d_gain;
+
+ public:
+ quadrature_demod_cf_impl(float gain);
+ ~quadrature_demod_cf_impl();
+
+ void set_gain(float gain) { d_gain = gain; }
+ float gain() const { return d_gain; }
+
+ 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_QUADRATURE_DEMOD_CF_IMPL_H */
diff --git a/gr-analog/python/qa_quadrature_demod.py b/gr-analog/python/qa_quadrature_demod.py
new file mode 100755
index 000000000..e38ea72a7
--- /dev/null
+++ b/gr-analog/python/qa_quadrature_demod.py
@@ -0,0 +1,63 @@
+#!/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 cmath
+
+class test_quadrature_demod(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_quad_demod_001(self):
+ f = 1000.0
+ fs = 8000.0
+
+ src_data = []
+ for i in xrange(200):
+ ti = i/fs
+ src_data.append(cmath.exp(2j*cmath.pi*f*ti))
+
+ # f/fs is a quarter turn per sample.
+ # Set the gain based on this to get 1 out.
+ gain = 1.0/(cmath.pi/4)
+
+ expected_result = [0,] + 199*[1.0]
+
+ src = gr.vector_source_c(src_data)
+ op = analog.quadrature_demod_cf(gain)
+ dst = gr.vector_sink_f()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+
+ result_data = dst.data()
+ self.assertComplexTuplesAlmostEqual(expected_result, result_data, 5)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_quadrature_demod, "test_quadrature_demod.xml")
+
diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i
index 9632b363c..016537c94 100644
--- a/gr-analog/swig/analog_swig.i
+++ b/gr-analog/swig/analog_swig.i
@@ -54,6 +54,7 @@
#include "analog/probe_avg_mag_sqrd_f.h"
#include "analog/pwr_squelch_cc.h"
#include "analog/pwr_squelch_ff.h"
+#include "analog/quadrature_demod_cf.h"
#include "analog/rail_ff.h"
#include "analog/sincos.h"
#include "analog/sig_source_s.h"
@@ -92,6 +93,7 @@
%include "analog/probe_avg_mag_sqrd_f.h"
%include "analog/pwr_squelch_cc.h"
%include "analog/pwr_squelch_ff.h"
+%include "analog/quadrature_demod_cf.h"
%include "analog/rail_ff.h"
%include "analog/sincos.h"
%include "analog/sig_source_s.h"
@@ -126,6 +128,7 @@ GR_SWIG_BLOCK_MAGIC2(analog, probe_avg_mag_sqrd_cf);
GR_SWIG_BLOCK_MAGIC2(analog, probe_avg_mag_sqrd_f);
GR_SWIG_BLOCK_MAGIC2(analog, pwr_squelch_cc);
GR_SWIG_BLOCK_MAGIC2(analog, pwr_squelch_ff);
+GR_SWIG_BLOCK_MAGIC2(analog, quadrature_demod_cf);
GR_SWIG_BLOCK_MAGIC2(analog, rail_ff);
GR_SWIG_BLOCK_MAGIC2(analog, sig_source_s);
GR_SWIG_BLOCK_MAGIC2(analog, sig_source_i);