diff options
author | Tom Rondeau | 2012-10-25 21:44:36 -0400 |
---|---|---|
committer | Tom Rondeau | 2012-10-25 21:44:36 -0400 |
commit | 8c9a5fdb19046c3cb8d25d6b77dbac87d49d8391 (patch) | |
tree | 2116f117efc4bd074d05faac306263f1a75574c8 /gr-analog | |
parent | 7b3ca29290f97388c3006959a91c24eea1116483 (diff) | |
download | gnuradio-8c9a5fdb19046c3cb8d25d6b77dbac87d49d8391.tar.gz gnuradio-8c9a5fdb19046c3cb8d25d6b77dbac87d49d8391.tar.bz2 gnuradio-8c9a5fdb19046c3cb8d25d6b77dbac87d49d8391.zip |
analog: adding frequency_modulator_fc to gr-analog, with QA and GRC.
Diffstat (limited to 'gr-analog')
-rw-r--r-- | gr-analog/grc/analog_block_tree.xml | 1 | ||||
-rw-r--r-- | gr-analog/grc/analog_frequency_modulator_fc.xml | 26 | ||||
-rw-r--r-- | gr-analog/include/analog/CMakeLists.txt | 3 | ||||
-rw-r--r-- | gr-analog/include/analog/frequency_modulator_fc.h | 53 | ||||
-rw-r--r-- | gr-analog/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-analog/lib/frequency_modulator_fc_impl.cc | 82 | ||||
-rw-r--r-- | gr-analog/lib/frequency_modulator_fc_impl.h | 52 | ||||
-rwxr-xr-x | gr-analog/python/qa_frequency_modulator.py | 56 | ||||
-rw-r--r-- | gr-analog/swig/analog_swig.i | 3 |
9 files changed, 276 insertions, 1 deletions
diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml index 53aba58c9..bb7a9b067 100644 --- a/gr-analog/grc/analog_block_tree.xml +++ b/gr-analog/grc/analog_block_tree.xml @@ -35,6 +35,7 @@ <block>analog_feedforward_agc_cc</block> <block>analog_ctcss_squelch_ff</block> <block>analog_dpll_bb</block> + <block>analog_frequency_modulator_fc</block> </cat> <cat> <name>Modulators</name> diff --git a/gr-analog/grc/analog_frequency_modulator_fc.xml b/gr-analog/grc/analog_frequency_modulator_fc.xml new file mode 100644 index 000000000..3b6cd159a --- /dev/null +++ b/gr-analog/grc/analog_frequency_modulator_fc.xml @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Frequency Modulator +################################################### + --> +<block> + <name>Frequency Mod</name> + <key>analog_frequency_modulator_fc</key> + <import>from gnuradio import analog</import> + <make>analog.frequency_modulator_fc($sensitivity)</make> + <callback>set_sensitivity($sensitivity)</callback> + <param> + <name>Sensitivity</name> + <key>sensitivity</key> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>float</type> + </sink> + <source> + <name>out</name> + <type>complex</type> + </source> +</block> diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt index 3c049bfd3..6e4c40b46 100644 --- a/gr-analog/include/analog/CMakeLists.txt +++ b/gr-analog/include/analog/CMakeLists.txt @@ -88,7 +88,8 @@ install(FILES ctcss_squelch_ff.h dpll_bb.h feedforward_agc_cc.h - fmdet_cf.j + fmdet_cf.h + frequency_modulator_fc.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio/analog COMPONENT "analog_devel" ) diff --git a/gr-analog/include/analog/frequency_modulator_fc.h b/gr-analog/include/analog/frequency_modulator_fc.h new file mode 100644 index 000000000..b163bac94 --- /dev/null +++ b/gr-analog/include/analog/frequency_modulator_fc.h @@ -0,0 +1,53 @@ +/* -*- 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_ANALOOG_FREQUENCY_MODULATOR_FC_H +#define INCLUDED_ANALOOG_FREQUENCY_MODULATOR_FC_H + +#include <analog/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace analog { + + /*! + * \brief Frequency modulator block + * \ingroup modulation_blk + * + * float input; complex baseband output + */ + class ANALOG_API frequency_modulator_fc : virtual public gr_sync_block + { + public: + // gr::analog::frequency_modulator_fc::sptr + typedef boost::shared_ptr<frequency_modulator_fc> sptr; + + static sptr make(double sensitivity); + + virtual void set_sensitivity(float sens) = 0; + virtual float sensitivity() const = 0; + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_FREQUENCY_MODULATOR_FC_H */ diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index abceed3e1..9faeaba80 100644 --- a/gr-analog/lib/CMakeLists.txt +++ b/gr-analog/lib/CMakeLists.txt @@ -115,6 +115,7 @@ list(APPEND analog_sources dpll_bb_impl.cc feedforward_agc_cc_impl.cc fmdet_cf_impl.cc + frequency_modulator_fc_impl.cc ) list(APPEND analog_libs diff --git a/gr-analog/lib/frequency_modulator_fc_impl.cc b/gr-analog/lib/frequency_modulator_fc_impl.cc new file mode 100644 index 000000000..2da7ee15f --- /dev/null +++ b/gr-analog/lib/frequency_modulator_fc_impl.cc @@ -0,0 +1,82 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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 "frequency_modulator_fc_impl.h" +#include <gr_io_signature.h> +#include <gr_fxpt.h> +#include <math.h> +#include <boost/math/special_functions/trunc.hpp> + +namespace gr { + namespace analog { + + frequency_modulator_fc::sptr + frequency_modulator_fc::make(double sensitivity) + { + return gnuradio::get_initial_sptr + (new frequency_modulator_fc_impl(sensitivity)); + } + + frequency_modulator_fc_impl::frequency_modulator_fc_impl(double sensitivity) + : gr_sync_block("frequency_modulator_fc", + gr_make_io_signature(1, 1, sizeof(float)), + gr_make_io_signature(1, 1, sizeof(gr_complex))), + d_sensitivity(sensitivity), d_phase(0) + { + } + + frequency_modulator_fc_impl::~frequency_modulator_fc_impl() + { + } + + int + frequency_modulator_fc_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const float *in = (const float*)input_items[0]; + gr_complex *out = (gr_complex*)output_items[0]; + + for(int i = 0; i < noutput_items; i++) { + d_phase = d_phase + d_sensitivity * in[i]; + + while(d_phase > (float)(M_PI)) + d_phase -= (float)(2.0 * M_PI); + while(d_phase < (float)(-M_PI)) + d_phase += (float)(2.0 * M_PI); + + float oi, oq; + + gr_int32 angle = gr_fxpt::float_to_fixed (d_phase); + gr_fxpt::sincos(angle, &oq, &oi); + out[i] = gr_complex(oi, oq); + } + + return noutput_items; + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gr-analog/lib/frequency_modulator_fc_impl.h b/gr-analog/lib/frequency_modulator_fc_impl.h new file mode 100644 index 000000000..36512f516 --- /dev/null +++ b/gr-analog/lib/frequency_modulator_fc_impl.h @@ -0,0 +1,52 @@ +/* -*- 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_FREQUENCY_MODULATOR_FC_IMPL_H +#define INCLUDED_ANALOG_FREQUENCY_MODULATOR_FC_IMPL_H + +#include <analog/frequency_modulator_fc.h> + +namespace gr { + namespace analog { + + class frequency_modulator_fc_impl : public frequency_modulator_fc + { + private: + float d_sensitivity; + float d_phase; + + public: + frequency_modulator_fc_impl(double sensitivity); + ~frequency_modulator_fc_impl(); + + void set_sensitivity(float sens) { d_sensitivity = sens; } + float sensitivity() const { return d_sensitivity; } + + 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_FREQUENCY_MODULATOR_FC_IMPL_H */ diff --git a/gr-analog/python/qa_frequency_modulator.py b/gr-analog/python/qa_frequency_modulator.py new file mode 100755 index 000000000..b673b3275 --- /dev/null +++ b/gr-analog/python/qa_frequency_modulator.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,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. +# + +from gnuradio import gr, gr_unittest +import analog_swig as analog +import math + +def sincos(x): + return math.cos(x) + math.sin(x) * 1j + + +class test_frequency_modulator(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_fm_001(self): + pi = math.pi + sensitivity = pi/4 + src_data = (1.0/4, 1.0/2, 1.0/4, -1.0/4, -1.0/2, -1/4.0) + running_sum = (pi/16, 3*pi/16, pi/4, 3*pi/16, pi/16, 0) + expected_result = tuple([sincos(x) for x in running_sum]) + src = gr.vector_source_f(src_data) + op = analog.frequency_modulator_fc(sensitivity) + dst = gr.vector_sink_c() + 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_frequency_modulator, "test_frequency_modulator.xml") + diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i index fec099a6c..8e1bb8058 100644 --- a/gr-analog/swig/analog_swig.i +++ b/gr-analog/swig/analog_swig.i @@ -37,6 +37,7 @@ #include "analog/dpll_bb.h" #include "analog/feedforward_agc_cc.h" #include "analog/fmdet_cf.h" +#include "analog/frequency_modulator_fc.h" #include "analog/squelch_base_cc.h" #include "analog/squelch_base_ff.h" %} @@ -51,6 +52,7 @@ %include "analog/dpll_bb.h" %include "analog/feedforward_agc_cc.h" %include "analog/fmdet_cf.h" +%include "analog/frequency_modulator_fc.h" %include "analog/squelch_base_cc.h" %include "analog/squelch_base_ff.h" @@ -63,3 +65,4 @@ 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); +GR_SWIG_BLOCK_MAGIC2(analog, frequency_modulator_fc); |