diff options
author | Tim O'Shea <tim.oshea753@gmail.com> | 2013-05-23 08:43:14 -0400 |
---|---|---|
committer | Tim O'Shea <tim.oshea753@gmail.com> | 2013-05-23 08:43:14 -0400 |
commit | 131bf62d8f06b8c9918be7c50a9f62601d107a27 (patch) | |
tree | aba99492b7716be9db46ec80766e9e44b199c4bd | |
parent | 419b761a1a6b3da3de1d9f15d5022aeab3ddf8b1 (diff) |
analog: adding grc def for fastnoise source, adding agc3_cc
-rw-r--r-- | gr-analog/grc/analog_agc3_xx.xml | 56 | ||||
-rw-r--r-- | gr-analog/grc/analog_block_tree.xml | 2 | ||||
-rw-r--r-- | gr-analog/grc/analog_fastnoise_source_x.xml | 86 | ||||
-rw-r--r-- | gr-analog/include/analog/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-analog/include/analog/agc3_cc.h | 71 | ||||
-rw-r--r-- | gr-analog/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-analog/lib/agc3_cc_impl.cc | 85 | ||||
-rw-r--r-- | gr-analog/lib/agc3_cc_impl.h | 63 | ||||
-rw-r--r-- | gr-analog/swig/analog_swig.i | 3 |
9 files changed, 368 insertions, 0 deletions
diff --git a/gr-analog/grc/analog_agc3_xx.xml b/gr-analog/grc/analog_agc3_xx.xml new file mode 100644 index 0000000000..d39e81e660 --- /dev/null +++ b/gr-analog/grc/analog_agc3_xx.xml @@ -0,0 +1,56 @@ +<?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)</make> + <callback>set_attack_rate($attack_rate)</callback> + <callback>set_decay_rate($decay_rate)</callback> + <callback>set_reference($reference)</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> + <sink> + <name>in</name> + <type>$type</type> + </sink> + <source> + <name>out</name> + <type>$type</type> + </source> +</block> 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/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt index 0343abcd85..bc2631c89a 100644 --- a/gr-analog/include/analog/CMakeLists.txt +++ b/gr-analog/include/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/analog/agc3_cc.h b/gr-analog/include/analog/agc3_cc.h new file mode 100644 index 0000000000..9ce2c0c18f --- /dev/null +++ b/gr-analog/include/analog/agc3_cc.h @@ -0,0 +1,71 @@ +/* -*- 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 <analog/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace analog { + + /*! + * \brief high performance Automatic Gain Control class with + * attack and decay rates. + * \ingroup level_controllers_blk + * + * \details + * For Power the absolute value of the complex number is used. + */ + class ANALOG_API agc3_cc : virtual public gr_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. + * \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); + + virtual float attack_rate() const = 0; + virtual float decay_rate() const = 0; + virtual float reference() const = 0; + virtual float 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; + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_AGC3_CC_H */ diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index 5719eac7a5..506cf7efb1 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/agc3_cc_impl.cc b/gr-analog/lib/agc3_cc_impl.cc new file mode 100644 index 0000000000..c99434d8a8 --- /dev/null +++ b/gr-analog/lib/agc3_cc_impl.cc @@ -0,0 +1,85 @@ +/* -*- 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 <gr_io_signature.h> + +namespace gr { + namespace analog { + + agc3_cc::sptr + agc3_cc::make(float attack_rate, float decay_rate, float reference) + { + return gnuradio::get_initial_sptr (new agc3_cc_impl(attack_rate, decay_rate, reference)); + } + + agc3_cc_impl::agc3_cc_impl(float attack_rate, float decay_rate, float reference) + : gr_sync_block("agc3_cc", + gr_make_io_signature(1, 1, sizeof(gr_complex)), + gr_make_io_signature(1, 1, sizeof(gr_complex))), + d_attack(attack_rate), d_decay(decay_rate), + d_reference(reference), d_gain(1.0), + d_reset(true) + { + } + + 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 a linear average on reset (no expected) + if(__builtin_expect (d_reset, false)){ + float mag; + for(int i=0; i<noutput_items; i++){ + mag += abs(in[i]); + } + d_gain = d_reference * (noutput_items/mag); + for(int i=0; i<noutput_items; i++){ + out[i] = in[i] * d_gain; + } + d_reset = false; + printf("computed initial mean on %d values = %f\n", noutput_items, d_gain); + } else { + // Otherwise perform a normal iir update + for(int i=0; i<noutput_items; i++){ + float newlevel = 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..0913243fd6 --- /dev/null +++ b/gr-analog/lib/agc3_cc_impl.h @@ -0,0 +1,63 @@ +/* -*- 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 <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); + ~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; } + + 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; } + + 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; + bool d_reset; + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_AGC3_CC_IMPL_H */ diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i index 9ae019ad8e..bc00ce1e2b 100644 --- a/gr-analog/swig/analog_swig.i +++ b/gr-analog/swig/analog_swig.i @@ -40,6 +40,7 @@ #include "analog/agc_ff.h" #include "analog/agc2_cc.h" #include "analog/agc2_ff.h" +#include "analog/agc3_cc.h" #include "analog/cpfsk_bc.h" #include "analog/ctcss_squelch_ff.h" #include "analog/dpll_bb.h" @@ -81,6 +82,7 @@ %include "analog/agc_ff.h" %include "analog/agc2_cc.h" %include "analog/agc2_ff.h" +%include "analog/agc3_cc.h" %include "analog/cpfsk_bc.h" %include "analog/ctcss_squelch_ff.h" %include "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); |