diff options
author | Ben Reynwar <ben@reynwar.net> | 2013-06-03 10:31:25 -0700 |
---|---|---|
committer | Ben Reynwar <ben@reynwar.net> | 2013-06-03 10:31:25 -0700 |
commit | 6ee7c1a6267e823d5525d3d5cf251ba52b12c823 (patch) | |
tree | 9a6b39ae056aab1f399c82b4108ac05ba2c6ea05 /gr-analog | |
parent | bb01988e75d50d82cbb44c1a49c86c1d08f05665 (diff) | |
parent | d1b65f4125aee94442c68d53f503bb29cdc10330 (diff) |
Merged in master.
Diffstat (limited to 'gr-analog')
26 files changed, 518 insertions, 64 deletions
diff --git a/gr-analog/grc/analog_agc2_xx.xml b/gr-analog/grc/analog_agc2_xx.xml index e57666873b..cafd6a09b5 100644 --- a/gr-analog/grc/analog_agc2_xx.xml +++ b/gr-analog/grc/analog_agc2_xx.xml @@ -8,7 +8,8 @@ <name>AGC2</name> <key>analog_agc2_xx</key> <import>from gnuradio import analog</import> - <make>analog.agc2_$(type.fcn)($attack_rate, $decay_rate, $reference, $gain, $max_gain)</make> + <make>analog.agc2_$(type.fcn)($attack_rate, $decay_rate, $reference, $gain) +self.$(id).set_max_gain($max_gain)</make> <callback>set_attack_rate($attack_rate)</callback> <callback>set_decay_rate($decay_rate)</callback> <callback>set_reference($reference)</callback> @@ -56,7 +57,7 @@ <param> <name>Max Gain</name> <key>max_gain</key> - <value>0.0</value> + <value>65536</value> <type>real</type> </param> <sink> diff --git a/gr-analog/grc/analog_agc3_xx.xml b/gr-analog/grc/analog_agc3_xx.xml new file mode 100644 index 0000000000..5ad4d7829a --- /dev/null +++ b/gr-analog/grc/analog_agc3_xx.xml @@ -0,0 +1,71 @@ +<?xml version="1.0"?> +<!-- +################################################### +##AGC3 +################################################### + --> +<block> + <name>AGC3</name> + <key>analog_agc3_xx</key> + <import>from gnuradio import analog</import> + <make>analog.agc3_$(type.fcn)($attack_rate, $decay_rate, $reference, $gain) +self.$(id).set_max_gain($max_gain)</make> + <callback>set_attack_rate($attack_rate)</callback> + <callback>set_decay_rate($decay_rate)</callback> + <callback>set_reference($reference)</callback> + <callback>set_gain($gain)</callback> + <callback>set_max_gain($max_gain)</callback> + <param> + <name>Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>fcn:cc</opt> + </option> +<!-- <option> + <name>Float</name> + <key>float</key> + <opt>fcn:ff</opt> + </option> --> + </param> + <param> + <name>Attack Rate</name> + <key>attack_rate</key> + <value>1e-3</value> + <type>real</type> + </param> + <param> + <name>Decay Rate</name> + <key>decay_rate</key> + <value>1e-4</value> + <type>real</type> + </param> + <param> + <name>Reference</name> + <key>reference</key> + <value>1.0</value> + <type>real</type> + </param> + <param> + <name>Gain</name> + <key>gain</key> + <value>1.0</value> + <type>real</type> + </param> + <param> + <name>Max Gain</name> + <key>max_gain</key> + <value>65536</value> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>$type</type> + </sink> + <source> + <name>out</name> + <type>$type</type> + </source> +</block> diff --git a/gr-analog/grc/analog_agc_xx.xml b/gr-analog/grc/analog_agc_xx.xml index 46797bff9a..085ded3d8c 100644 --- a/gr-analog/grc/analog_agc_xx.xml +++ b/gr-analog/grc/analog_agc_xx.xml @@ -8,7 +8,8 @@ <name>AGC</name> <key>analog_agc_xx</key> <import>from gnuradio import analog</import> - <make>analog.agc_$(type.fcn)($rate, $reference, $gain, $max_gain)</make> + <make>analog.agc_$(type.fcn)($rate, $reference, $gain) +self.$(id).set_max_gain($max_gain)</make> <callback>set_rate($rate)</callback> <callback>set_reference($reference)</callback> <callback>set_gain($gain)</callback> @@ -49,7 +50,7 @@ <param> <name>Max Gain</name> <key>max_gain</key> - <value>0.0</value> + <value>65536</value> <type>real</type> </param> <sink> diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml index 6fdd139a85..ff64f03b70 100644 --- a/gr-analog/grc/analog_block_tree.xml +++ b/gr-analog/grc/analog_block_tree.xml @@ -32,6 +32,7 @@ <name>Level Controllers</name> <block>analog_agc_xx</block> <block>analog_agc2_xx</block> + <block>analog_agc3_xx</block> <block>analog_feedforward_agc_cc</block> <block>analog_ctcss_squelch_ff</block> <block>analog_pwr_squelch_xx</block> @@ -60,6 +61,7 @@ <block>analog_sig_source_x</block> <block>analog_const_source_x</block> <block>analog_noise_source_x</block> + <block>analog_fastnoise_source_x</block> <block>analog_random_source_x</block> </cat> <cat> diff --git a/gr-analog/grc/analog_fastnoise_source_x.xml b/gr-analog/grc/analog_fastnoise_source_x.xml new file mode 100644 index 0000000000..f18c8c2f54 --- /dev/null +++ b/gr-analog/grc/analog_fastnoise_source_x.xml @@ -0,0 +1,86 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Fast Noise Source +################################################### + --> +<block> + <name>Fast Noise Source</name> + <key>analog_fastnoise_source_x</key> + <import>from gnuradio import analog</import> + <make>analog.fastnoise_source_$(type.fcn)($noise_type, $amp, $seed, $samples)</make> + <callback>set_type($noise_type)</callback> + <callback>set_amplitude($amp)</callback> + <param> + <name>Output Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>fcn:c</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>fcn:f</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>fcn:i</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>fcn:s</opt> + </option> + </param> + <param> + <name>Noise Type</name> + <key>noise_type</key> + <value>analog.GR_GAUSSIAN</value> + <type>int</type> + <option> + <name>Uniform</name> + <key>analog.GR_UNIFORM</key> + </option> + <option> + <name>Gaussian</name> + <key>analog.GR_GAUSSIAN</key> + </option> + <option> + <name>Laplacian</name> + <key>analog.GR_LAPLACIAN</key> + </option> + <option> + <name>Impulse</name> + <key>analog.GR_IMPULSE</key> + </option> + </param> + <param> + <name>Amplitude</name> + <key>amp</key> + <value>1</value> + <type>real</type> + </param> + <param> + <name>Seed</name> + <key>seed</key> + <value>0</value> + <type>int</type> + </param> + <param> + <name>Variate Pool Size</name> + <key>samples</key> + <value>8192</value> + <type>int</type> + </param> + <source> + <name>out</name> + <type>$type</type> + </source> + <doc> +The fast noise source works by pre-generating a pool of random variates taken from the specified distribution. At runtime, samples are then uniform randomly chosen from this pool which is a very fast operation. + </doc> +</block> diff --git a/gr-analog/include/gnuradio/analog/CMakeLists.txt b/gr-analog/include/gnuradio/analog/CMakeLists.txt index 0343abcd85..bc2631c89a 100644 --- a/gr-analog/include/gnuradio/analog/CMakeLists.txt +++ b/gr-analog/include/gnuradio/analog/CMakeLists.txt @@ -88,6 +88,7 @@ install(FILES agc_ff.h agc2_cc.h agc2_ff.h + agc3_cc.h cpfsk_bc.h ctcss_squelch_ff.h dpll_bb.h diff --git a/gr-analog/include/gnuradio/analog/agc2_cc.h b/gr-analog/include/gnuradio/analog/agc2_cc.h index 76a5263183..8a24c79288 100644 --- a/gr-analog/include/gnuradio/analog/agc2_cc.h +++ b/gr-analog/include/gnuradio/analog/agc2_cc.h @@ -51,11 +51,9 @@ namespace gr { * \param decay_rate the update rate of the loop when in decay mode. * \param reference reference value to adjust signal power to. * \param gain initial gain value. - * \param max_gain maximum gain value (0 for unlimited). */ static sptr make(float attack_rate = 1e-1, float decay_rate = 1e-2, - float reference = 1.0, - float gain = 1.0, float max_gain = 0.0); + float reference = 1.0, float gain = 1.0); virtual float attack_rate() const = 0; virtual float decay_rate() const = 0; diff --git a/gr-analog/include/gnuradio/analog/agc2_ff.h b/gr-analog/include/gnuradio/analog/agc2_ff.h index 740d795e1d..646882371e 100644 --- a/gr-analog/include/gnuradio/analog/agc2_ff.h +++ b/gr-analog/include/gnuradio/analog/agc2_ff.h @@ -51,11 +51,9 @@ namespace gr { * \param decay_rate the update rate of the loop when in decay mode. * \param reference reference value to adjust signal power to. * \param gain initial gain value. - * \param max_gain maximum gain value (0 for unlimited). */ static sptr make(float attack_rate = 1e-1, float decay_rate = 1e-2, - float reference = 1.0, - float gain = 1.0, float max_gain = 0.0); + float reference = 1.0, float gain = 1.0); virtual float attack_rate() const = 0; virtual float decay_rate() const = 0; diff --git a/gr-analog/include/gnuradio/analog/agc3_cc.h b/gr-analog/include/gnuradio/analog/agc3_cc.h new file mode 100644 index 0000000000..9cd6e60e1e --- /dev/null +++ b/gr-analog/include/gnuradio/analog/agc3_cc.h @@ -0,0 +1,77 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,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_AGC3_CC_H +#define INCLUDED_ANALOG_AGC3_CC_H + +#include <gnuradio/analog/api.h> +#include <gnuradio/sync_block.h> + +namespace gr { + namespace analog { + + /*! + * \brief high performance Automatic Gain Control class with + * attack and decay rates. + * \ingroup level_controllers_blk + * + * \details + * Unlike the AGC2 loop, this uses an initial linear calculation + * at the beginning for very fast initial acquisition. Moves to + * IIR model for tracking purposes. + * + * For Power the absolute value of the complex number is used. + */ + class ANALOG_API agc3_cc : virtual public sync_block + { + public: + // gr::analog::agc3_cc::sptr + typedef boost::shared_ptr<agc3_cc> sptr; + + /*! + * Build a complex value AGC loop block with attack and decay rates. + * + * \param attack_rate the update rate of the loop when in attack mode. + * \param decay_rate the update rate of the loop when in decay mode. + * \param reference reference value to adjust signal power to. + * \param gain initial gain value. + */ + static sptr make(float attack_rate = 1e-1, float decay_rate = 1e-2, + float reference = 1.0, float gain = 1.0); + + virtual float attack_rate() const = 0; + virtual float decay_rate() const = 0; + virtual float reference() const = 0; + virtual float gain() const = 0; + virtual float max_gain() const = 0; + + virtual void set_attack_rate(float rate) = 0; + virtual void set_decay_rate(float rate) = 0; + virtual void set_reference(float reference) = 0; + virtual void set_gain(float gain) = 0; + virtual void set_max_gain(float max_gain) = 0; + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_AGC3_CC_H */ diff --git a/gr-analog/include/gnuradio/analog/agc_cc.h b/gr-analog/include/gnuradio/analog/agc_cc.h index 8319995960..9a489f11da 100644 --- a/gr-analog/include/gnuradio/analog/agc_cc.h +++ b/gr-analog/include/gnuradio/analog/agc_cc.h @@ -49,10 +49,9 @@ namespace gr { * \param rate the update rate of the loop. * \param reference reference value to adjust signal power to. * \param gain initial gain value. - * \param max_gain maximum gain value (0 for unlimited). */ static sptr make(float rate = 1e-4, float reference = 1.0, - float gain = 1.0, float max_gain = 0.0); + float gain = 1.0); virtual float rate() const = 0; virtual float reference() const = 0; diff --git a/gr-analog/include/gnuradio/analog/agc_ff.h b/gr-analog/include/gnuradio/analog/agc_ff.h index d55072889b..19e2fcbee2 100644 --- a/gr-analog/include/gnuradio/analog/agc_ff.h +++ b/gr-analog/include/gnuradio/analog/agc_ff.h @@ -49,10 +49,9 @@ namespace gr { * \param rate the update rate of the loop. * \param reference reference value to adjust signal power to. * \param gain initial gain value. - * \param max_gain maximum gain value (0 for unlimited). */ static sptr make(float rate = 1e-4, float reference = 1.0, - float gain = 1.0, float max_gain = 0.0); + float gain = 1.0); virtual float rate() const = 0; virtual float reference() const = 0; diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index ce10422487..473003a3bf 100644 --- a/gr-analog/lib/CMakeLists.txt +++ b/gr-analog/lib/CMakeLists.txt @@ -120,6 +120,7 @@ list(APPEND analog_sources agc_ff_impl.cc agc2_cc_impl.cc agc2_ff_impl.cc + agc3_cc_impl.cc cpfsk_bc_impl.cc ctcss_squelch_ff_impl.cc dpll_bb_impl.cc diff --git a/gr-analog/lib/agc2_cc_impl.cc b/gr-analog/lib/agc2_cc_impl.cc index fbca18777b..e559c104b4 100644 --- a/gr-analog/lib/agc2_cc_impl.cc +++ b/gr-analog/lib/agc2_cc_impl.cc @@ -26,29 +26,31 @@ #include "agc2_cc_impl.h" #include <gnuradio/io_signature.h> +#include <volk/volk.h> namespace gr { namespace analog { agc2_cc::sptr agc2_cc::make(float attack_rate, float decay_rate, - float reference, - float gain, float max_gain) + float reference, float gain) { return gnuradio::get_initial_sptr (new agc2_cc_impl(attack_rate, decay_rate, - reference, gain, max_gain)); + reference, gain)); } agc2_cc_impl::agc2_cc_impl(float attack_rate, float decay_rate, - float reference, - float gain, float max_gain) + float reference, float gain) : sync_block("agc2_cc", - io_signature::make(1, 1, sizeof(gr_complex)), - io_signature::make(1, 1, sizeof(gr_complex))), + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(gr_complex))), kernel::agc2_cc(attack_rate, decay_rate, - reference, gain, max_gain) + reference, gain, 65536) { + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); } agc2_cc_impl::~agc2_cc_impl() diff --git a/gr-analog/lib/agc2_cc_impl.h b/gr-analog/lib/agc2_cc_impl.h index 9220501323..bfb420789f 100644 --- a/gr-analog/lib/agc2_cc_impl.h +++ b/gr-analog/lib/agc2_cc_impl.h @@ -32,8 +32,7 @@ namespace gr { { public: agc2_cc_impl(float attack_rate = 1e-1, float decay_rate = 1e-2, - float reference = 1.0, - float gain = 1.0, float max_gain = 0.0); + float reference = 1.0, float gain = 1.0); ~agc2_cc_impl(); float attack_rate() const { return kernel::agc2_cc::attack_rate(); } diff --git a/gr-analog/lib/agc2_ff_impl.cc b/gr-analog/lib/agc2_ff_impl.cc index 93a404c6df..a6dc1d4c6c 100644 --- a/gr-analog/lib/agc2_ff_impl.cc +++ b/gr-analog/lib/agc2_ff_impl.cc @@ -32,13 +32,11 @@ namespace gr { agc2_ff::sptr agc2_ff::make(float attack_rate, float decay_rate, - float reference, - float gain, float max_gain) + float reference, float gain) { return gnuradio::get_initial_sptr (new agc2_ff_impl(attack_rate, decay_rate, - reference, - gain, max_gain)); + reference, gain)); } agc2_ff_impl::~agc2_ff_impl() @@ -46,13 +44,12 @@ namespace gr { } agc2_ff_impl::agc2_ff_impl(float attack_rate, float decay_rate, - float reference, - float gain, float max_gain) - : sync_block("agc2_ff", - io_signature::make(1, 1, sizeof(float)), - io_signature::make(1, 1, sizeof(float))) - , kernel::agc2_ff(attack_rate, decay_rate, - reference, gain, max_gain) + float reference, float gain) + : sync_block("agc2_ff", + io_signature::make(1, 1, sizeof(float)), + io_signature::make(1, 1, sizeof(float))), + kernel::agc2_ff(attack_rate, decay_rate, + reference, gain, 65536) { } diff --git a/gr-analog/lib/agc2_ff_impl.h b/gr-analog/lib/agc2_ff_impl.h index 8c068c4e34..5c7a7b486a 100644 --- a/gr-analog/lib/agc2_ff_impl.h +++ b/gr-analog/lib/agc2_ff_impl.h @@ -32,8 +32,7 @@ namespace gr { { public: agc2_ff_impl(float attack_rate = 1e-1, float decay_rate = 1e-2, - float reference = 1.0, - float gain = 1.0, float max_gain = 0.0); + float reference = 1.0, float gain = 1.0); ~agc2_ff_impl(); float attack_rate() const { return kernel::agc2_ff::attack_rate(); } diff --git a/gr-analog/lib/agc3_cc_impl.cc b/gr-analog/lib/agc3_cc_impl.cc new file mode 100644 index 0000000000..a6a85caf10 --- /dev/null +++ b/gr-analog/lib/agc3_cc_impl.cc @@ -0,0 +1,109 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,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 "agc3_cc_impl.h" +#include <gnuradio/io_signature.h> +#include <volk/volk.h> + +namespace gr { + namespace analog { + + agc3_cc::sptr + agc3_cc::make(float attack_rate, float decay_rate, + float reference, float gain) + { + return gnuradio::get_initial_sptr + (new agc3_cc_impl(attack_rate, decay_rate, + reference, gain)); + } + + agc3_cc_impl::agc3_cc_impl(float attack_rate, float decay_rate, + float reference, float gain) + : sync_block("agc3_cc", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(gr_complex))), + d_attack(attack_rate), d_decay(decay_rate), + d_reference(reference), d_gain(gain), d_max_gain(65536), + d_reset(true) + { + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); + } + + agc3_cc_impl::~agc3_cc_impl() + { + } + + int + agc3_cc_impl::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]; + // Compute magnitude of each sample +#ifdef __GNUC__ + float mags[noutput_items] __attribute__ ((aligned (16))); +#else + float mags[noutput_items]; +#endif + volk_32fc_magnitude_32f(mags, &in[0], noutput_items); + // Compute a linear average on reset (no expected) + if(__builtin_expect(d_reset, false)) { + float mag; + for(int i=0; i<noutput_items; i++) { + mag += mags[i]; + } + d_gain = d_reference * (noutput_items/mag); + + if(d_gain < 0.0) + d_gain = 10e-5; + + if(d_max_gain > 0.0 && d_gain > d_max_gain) { + d_gain = d_max_gain; + } + + // scale output values + for(int i=0; i<noutput_items; i++){ + out[i] = in[i] * d_gain; + } + d_reset = false; + } + else { + // Otherwise perform a normal iir update + for(int i=0; i<noutput_items; i++) { + float newlevel = mags[i]; // abs(in[i]); + float rate = (newlevel > d_reference/d_gain)?d_attack:d_decay; + d_gain = (d_gain*(1-rate)) + (d_reference/newlevel)*rate; + out[i] = in[i] * d_gain; + } + } + return noutput_items; + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gr-analog/lib/agc3_cc_impl.h b/gr-analog/lib/agc3_cc_impl.h new file mode 100644 index 0000000000..77cc1978c5 --- /dev/null +++ b/gr-analog/lib/agc3_cc_impl.h @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,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_AGC3_IMPL_CC_H +#define INCLUDED_ANALOG_AGC3_IMPL_CC_H + +#include <gnuradio/analog/agc3_cc.h> + +namespace gr { + namespace analog { + + class agc3_cc_impl : public agc3_cc + { + public: + agc3_cc_impl(float attack_rate = 1e-1, float decay_rate = 1e-2, + float reference = 1.0, float gain = 1.0); + ~agc3_cc_impl(); + + float attack_rate() const { return d_attack; } + float decay_rate() const { return d_decay; } + float reference() const { return d_reference; } + float gain() const { return d_gain; } + float max_gain() const { return d_max_gain; } + + void set_attack_rate(float rate) { d_attack = rate; } + void set_decay_rate(float rate) { d_decay = rate; } + void set_reference(float reference) { d_reference = reference; } + void set_gain(float gain) { d_gain = gain; } + void set_max_gain(float max_gain) { d_max_gain = max_gain; } + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + private: + float d_attack; + float d_decay; + float d_reference; + float d_gain; + float d_max_gain; + bool d_reset; + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_AGC3_CC_IMPL_H */ diff --git a/gr-analog/lib/agc_cc_impl.cc b/gr-analog/lib/agc_cc_impl.cc index 04d70d5421..af19953b86 100644 --- a/gr-analog/lib/agc_cc_impl.cc +++ b/gr-analog/lib/agc_cc_impl.cc @@ -26,25 +26,27 @@ #include "agc_cc_impl.h" #include <gnuradio/io_signature.h> +#include <volk/volk.h> namespace gr { namespace analog { agc_cc::sptr - agc_cc::make(float rate, float reference, - float gain, float max_gain) + agc_cc::make(float rate, float reference, float gain) { return gnuradio::get_initial_sptr - (new agc_cc_impl(rate, reference, gain, max_gain)); + (new agc_cc_impl(rate, reference, gain)); } - agc_cc_impl::agc_cc_impl(float rate, float reference, - float gain, float max_gain) + agc_cc_impl::agc_cc_impl(float rate, float reference, float gain) : sync_block("agc_cc", - io_signature::make(1, 1, sizeof(gr_complex)), - io_signature::make(1, 1, sizeof(gr_complex))), - kernel::agc_cc(rate, reference, gain, max_gain) + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(gr_complex))), + kernel::agc_cc(rate, reference, gain, 65536) { + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); } agc_cc_impl::~agc_cc_impl() diff --git a/gr-analog/lib/agc_cc_impl.h b/gr-analog/lib/agc_cc_impl.h index fda154d021..7772cb4092 100644 --- a/gr-analog/lib/agc_cc_impl.h +++ b/gr-analog/lib/agc_cc_impl.h @@ -32,7 +32,7 @@ namespace gr { { public: agc_cc_impl(float rate = 1e-4, float reference = 1.0, - float gain = 1.0, float max_gain = 0.0); + float gain = 1.0); ~agc_cc_impl(); float rate() const { return kernel::agc_cc::rate(); } diff --git a/gr-analog/lib/agc_ff_impl.cc b/gr-analog/lib/agc_ff_impl.cc index 1c29934361..e1b925665c 100644 --- a/gr-analog/lib/agc_ff_impl.cc +++ b/gr-analog/lib/agc_ff_impl.cc @@ -31,17 +31,17 @@ namespace gr { namespace analog { agc_ff::sptr - agc_ff::make(float rate, float reference, float gain, float max_gain) + agc_ff::make(float rate, float reference, float gain) { return gnuradio::get_initial_sptr - (new agc_ff_impl(rate, reference, gain, max_gain)); + (new agc_ff_impl(rate, reference, gain)); } - agc_ff_impl::agc_ff_impl(float rate, float reference, float gain, float max_gain) + agc_ff_impl::agc_ff_impl(float rate, float reference, float gain) : sync_block("agc_ff", io_signature::make(1, 1, sizeof(float)), io_signature::make(1, 1, sizeof(float))), - kernel::agc_ff(rate, reference, gain, max_gain) + kernel::agc_ff(rate, reference, gain, 65536) { } diff --git a/gr-analog/lib/agc_ff_impl.h b/gr-analog/lib/agc_ff_impl.h index c67739b73e..319823c6aa 100644 --- a/gr-analog/lib/agc_ff_impl.h +++ b/gr-analog/lib/agc_ff_impl.h @@ -32,7 +32,7 @@ namespace gr { { public: agc_ff_impl(float rate = 1e-4, float reference = 1.0, - float gain = 1.0, float max_gain = 0.0); + float gain = 1.0); ~agc_ff_impl(); float rate() const { return kernel::agc_ff::rate(); } diff --git a/gr-analog/lib/quadrature_demod_cf_impl.cc b/gr-analog/lib/quadrature_demod_cf_impl.cc index 583de4dba4..059cc89627 100644 --- a/gr-analog/lib/quadrature_demod_cf_impl.cc +++ b/gr-analog/lib/quadrature_demod_cf_impl.cc @@ -27,6 +27,7 @@ #include "quadrature_demod_cf_impl.h" #include <gnuradio/io_signature.h> #include <gnuradio/math.h> +#include <volk/volk.h> namespace gr { namespace analog { @@ -44,6 +45,10 @@ namespace gr { io_signature::make(1, 1, sizeof(float))), d_gain(gain) { + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1, alignment_multiple)); + set_history(2); // we need to look at the previous value } @@ -58,11 +63,11 @@ namespace gr { { gr_complex *in = (gr_complex*)input_items[0]; float *out = (float*)output_items[0]; - in++; // ensure that in[-1] is valid + std::vector<gr_complex> tmp(noutput_items); + volk_32fc_x2_multiply_conjugate_32fc(&tmp[0], &in[1], &in[0], noutput_items); 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)); + out[i] = d_gain * gr::fast_atan2f(imag(tmp[i]), real(tmp[i])); } return noutput_items; diff --git a/gr-analog/python/analog/qa_agc.py b/gr-analog/python/analog/qa_agc.py index f274b04e7e..cb72668341 100755 --- a/gr-analog/python/analog/qa_agc.py +++ b/gr-analog/python/analog/qa_agc.py @@ -31,7 +31,7 @@ class test_agc(gr_unittest.TestCase): self.tb = None def test_001_sets(self): - agc = analog.agc_cc(1e-3, 1, 1, 1000) + agc = analog.agc_cc(1e-3, 1, 1) agc.set_rate(1) agc.set_reference(1.1) @@ -105,7 +105,7 @@ class test_agc(gr_unittest.TestCase): dst1 = blocks.vector_sink_c() head = blocks.head(gr.sizeof_gr_complex, int (5*sampling_freq * 0.10)) - agc = analog.agc_cc(1e-3, 1, 1, 1000) + agc = analog.agc_cc(1e-3, 1, 1) tb.connect(src1, head) tb.connect(head, agc) @@ -116,7 +116,7 @@ class test_agc(gr_unittest.TestCase): self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4) def test_002_sets(self): - agc = analog.agc_ff(1e-3, 1, 1, 1000) + agc = analog.agc_ff(1e-3, 1, 1) agc.set_rate(1) agc.set_reference(1.1) @@ -190,7 +190,7 @@ class test_agc(gr_unittest.TestCase): dst1 = blocks.vector_sink_f () head = blocks.head (gr.sizeof_float, int (5*sampling_freq * 0.10)) - agc = analog.agc_ff(1e-3, 1, 1, 1000) + agc = analog.agc_ff(1e-3, 1, 1) tb.connect (src1, head) tb.connect (head, agc) @@ -201,7 +201,7 @@ class test_agc(gr_unittest.TestCase): self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 4) def test_003_sets(self): - agc = analog.agc2_cc(1e-3, 1e-1, 1, 1, 1000) + agc = analog.agc2_cc(1e-3, 1e-1, 1, 1) agc.set_attack_rate(1) agc.set_decay_rate(2) @@ -277,7 +277,7 @@ class test_agc(gr_unittest.TestCase): dst1 = blocks.vector_sink_c() head = blocks.head(gr.sizeof_gr_complex, int(5*sampling_freq * 0.10)) - agc = analog.agc2_cc(1e-2, 1e-3, 1, 1, 1000) + agc = analog.agc2_cc(1e-2, 1e-3, 1, 1) tb.connect(src1, head) tb.connect(head, agc) @@ -288,7 +288,7 @@ class test_agc(gr_unittest.TestCase): self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4) def test_004_sets(self): - agc = analog.agc2_ff(1e-3, 1e-1, 1, 1, 1000) + agc = analog.agc2_ff(1e-3, 1e-1, 1, 1) agc.set_attack_rate(1) agc.set_decay_rate(2) @@ -364,7 +364,7 @@ class test_agc(gr_unittest.TestCase): dst1 = blocks.vector_sink_f() head = blocks.head(gr.sizeof_float, int(5*sampling_freq * 0.10)) - agc = analog.agc2_ff(1e-2, 1e-3, 1, 1, 1000) + agc = analog.agc2_ff(1e-2, 1e-3, 1, 1) tb.connect(src1, head) tb.connect(head, agc) @@ -437,7 +437,7 @@ class test_agc(gr_unittest.TestCase): dst1 = blocks.vector_sink_c() head = blocks.head(gr.sizeof_gr_complex, int(5*sampling_freq * 0.10)) - agc = analog.agc2_cc(1e-2, 1e-3, 1, 1, 1000) + agc = analog.agc2_cc(1e-2, 1e-3, 1, 1) tb.connect(src1, head) tb.connect(head, agc) @@ -447,6 +447,43 @@ class test_agc(gr_unittest.TestCase): dst_data = dst1.data() self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4) + def test_006_sets(self): + agc = analog.agc3_cc(1e-3, 1e-1, 1) + + agc.set_attack_rate(1) + agc.set_decay_rate(2) + agc.set_reference(1.1) + agc.set_gain(1.1) + + self.assertAlmostEqual(agc.attack_rate(), 1) + self.assertAlmostEqual(agc.decay_rate(), 2) + self.assertAlmostEqual(agc.reference(), 1.1) + self.assertAlmostEqual(agc.gain(), 1.1) + + def test_006(self): + ''' Test the complex AGC loop (attack and decay rate inputs) ''' + tb = self.tb + + sampling_freq = 100 + N = int(5*sampling_freq) + src1 = analog.sig_source_c(sampling_freq, analog.GR_SIN_WAVE, + sampling_freq * 0.10, 100) + dst1 = blocks.vector_sink_c() + head = blocks.head(gr.sizeof_gr_complex, N) + + ref = 1 + agc = analog.agc3_cc(1e-2, 1e-3, ref) + + tb.connect(src1, head) + tb.connect(head, agc) + tb.connect(agc, dst1) + + tb.run() + dst_data = dst1.data() + M = 100 + result = map(lambda x: abs(x), dst_data[N-M:]) + self.assertFloatTuplesAlmostEqual(result, M*[ref,], 4) + def test_100(self): ''' Test complex feedforward agc with constant input ''' diff --git a/gr-analog/swig/CMakeLists.txt b/gr-analog/swig/CMakeLists.txt index 68b2c4a662..06f1cdf985 100644 --- a/gr-analog/swig/CMakeLists.txt +++ b/gr-analog/swig/CMakeLists.txt @@ -28,6 +28,7 @@ set(GR_SWIG_INCLUDE_DIRS ${GR_ANALOG_INCLUDE_DIRS} ${GR_FILTER_INCLUDE_DIRS} ${GNURADIO_RUNTIME_SWIG_INCLUDE_DIRS} + ${VOLK_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ) diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i index a2da8dd10e..d9561b32d5 100644 --- a/gr-analog/swig/analog_swig.i +++ b/gr-analog/swig/analog_swig.i @@ -22,7 +22,7 @@ #define ANALOG_API #define BLOCKS_API -%include "runtime_swig.i" +%include "gnuradio.i" %include "stdint.i" //load generated python docstrings @@ -40,6 +40,7 @@ #include "gnuradio/analog/agc_ff.h" #include "gnuradio/analog/agc2_cc.h" #include "gnuradio/analog/agc2_ff.h" +#include "gnuradio/analog/agc3_cc.h" #include "gnuradio/analog/cpfsk_bc.h" #include "gnuradio/analog/ctcss_squelch_ff.h" #include "gnuradio/analog/dpll_bb.h" @@ -81,6 +82,7 @@ %include "gnuradio/analog/agc_ff.h" %include "gnuradio/analog/agc2_cc.h" %include "gnuradio/analog/agc2_ff.h" +%include "gnuradio/analog/agc3_cc.h" %include "gnuradio/analog/cpfsk_bc.h" %include "gnuradio/analog/ctcss_squelch_ff.h" %include "gnuradio/analog/dpll_bb.h" @@ -119,6 +121,7 @@ GR_SWIG_BLOCK_MAGIC2(analog, agc_cc); GR_SWIG_BLOCK_MAGIC2(analog, agc_ff); GR_SWIG_BLOCK_MAGIC2(analog, agc2_cc); GR_SWIG_BLOCK_MAGIC2(analog, agc2_ff); +GR_SWIG_BLOCK_MAGIC2(analog, agc3_cc); GR_SWIG_BLOCK_MAGIC2(analog, cpfsk_bc); GR_SWIG_BLOCK_MAGIC2(analog, ctcss_squelch_ff); GR_SWIG_BLOCK_MAGIC2(analog, dpll_bb); |