diff options
Diffstat (limited to 'gr-analog')
-rw-r--r-- | gr-analog/grc/analog_noise_source_x.xml | 77 | ||||
-rw-r--r-- | gr-analog/include/analog/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-analog/include/analog/noise_source_X.h.t | 68 | ||||
-rw-r--r-- | gr-analog/include/analog/noise_type.h | 36 | ||||
-rw-r--r-- | gr-analog/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-analog/lib/noise_source_X_impl.cc.t | 116 | ||||
-rw-r--r-- | gr-analog/lib/noise_source_X_impl.h.t | 58 | ||||
-rwxr-xr-x | gr-analog/python/qa_noise.py | 52 | ||||
-rw-r--r-- | gr-analog/swig/analog_swig.i | 14 |
9 files changed, 423 insertions, 2 deletions
diff --git a/gr-analog/grc/analog_noise_source_x.xml b/gr-analog/grc/analog_noise_source_x.xml new file mode 100644 index 000000000..72daaaa20 --- /dev/null +++ b/gr-analog/grc/analog_noise_source_x.xml @@ -0,0 +1,77 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Noise Source +################################################### + --> +<block> + <name>Noise Source</name> + <key>gr_noise_source_x</key> + <import>from gnuradio import gr</import> + <make>gr.noise_source_$(type.fcn)($noise_type, $amp, $seed)</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>gr.GR_GAUSSIAN</value> + <type>int</type> + <option> + <name>Uniform</name> + <key>gr.GR_UNIFORM</key> + </option> + <option> + <name>Gaussian</name> + <key>gr.GR_GAUSSIAN</key> + </option> + <option> + <name>Laplacian</name> + <key>gr.GR_LAPLACIAN</key> + </option> + <option> + <name>Impulse</name> + <key>gr.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> + <source> + <name>out</name> + <type>$type</type> + </source> +</block> diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt index 6e4c40b46..76a11a3ac 100644 --- a/gr-analog/include/analog/CMakeLists.txt +++ b/gr-analog/include/analog/CMakeLists.txt @@ -64,7 +64,7 @@ endmacro(expand_h) ######################################################################## # Invoke macro to generate various sources ####################################################################### -#expand_h(block bf bc sf sc if ic) +expand_h(noise_source_X s i f c) add_custom_target(analog_generated_includes DEPENDS ${generated_includes} diff --git a/gr-analog/include/analog/noise_source_X.h.t b/gr-analog/include/analog/noise_source_X.h.t new file mode 100644 index 000000000..9d1be6fed --- /dev/null +++ b/gr-analog/include/analog/noise_source_X.h.t @@ -0,0 +1,68 @@ +/* -*- 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. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include <analog/api.h> +#include <analog/noise_type.h> +#include <gr_sync_block.h> +#include <gr_random.h> + +namespace gr { + namespace analog { + + /*! + * \brief Random number source + * \ingroup source_blk + * + * \details + * Generate random values from different distributions. + * Currently, only Gaussian and uniform are enabled. + */ + class ANALOG_API @BASE_NAME@ : virtual public gr_sync_block + { + public: + // gr::analog::@BASE_NAME@::sptr + typedef boost::shared_ptr<@BASE_NAME@> sptr; + + /*! \brief Make a noise source + * \param type the random distribution to use (see analog/noise_type.h) + * \param ampl a scaling factor for the output + * \param seed seed for random generators. Note that for uniform and + * Gaussian distributions, this should be a negative number. + */ + static sptr make(noise_type_t type, float ampl, long seed); + + virtual void set_type(noise_type_t type) = 0; + virtual void set_amplitude(float ampl) = 0; + + virtual noise_type_t type() const = 0; + virtual float amplitude() const = 0; + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-analog/include/analog/noise_type.h b/gr-analog/include/analog/noise_type.h new file mode 100644 index 000000000..c3a2146b7 --- /dev/null +++ b/gr-analog/include/analog/noise_type.h @@ -0,0 +1,36 @@ +/* -*- 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_NOISE_TYPE_H +#define INCLUDED_ANALOG_NOISE_TYPE_H + +namespace gr { + namespace analog { + + typedef enum { + GR_UNIFORM = 200, GR_GAUSSIAN, GR_LAPLACIAN, GR_IMPULSE + } noise_type_t; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_NOISE_TYPE_H */ diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index 9faeaba80..cad0d7b91 100644 --- a/gr-analog/lib/CMakeLists.txt +++ b/gr-analog/lib/CMakeLists.txt @@ -96,7 +96,7 @@ endmacro(expand_cc) ######################################################################## # Invoke macro to generate various sources ######################################################################## -#expand_cc(block bf bc sf sc if ic) +expand_cc(noise_source_X_impl s i f c) ######################################################################## # Setup library diff --git a/gr-analog/lib/noise_source_X_impl.cc.t b/gr-analog/lib/noise_source_X_impl.cc.t new file mode 100644 index 000000000..35dda9c5d --- /dev/null +++ b/gr-analog/lib/noise_source_X_impl.cc.t @@ -0,0 +1,116 @@ +/* -*- 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. + */ + +/* @WARNING@ */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "@IMPL_NAME@.h" +#include <gr_io_signature.h> +#include <stdexcept> + +namespace gr { + namespace analog { + + @BASE_NAME@::sptr + @BASE_NAME@::make(noise_type_t type, float ampl, long seed) + { + return gnuradio::get_initial_sptr + (new @IMPL_NAME@(type, ampl, seed)); + } + + @IMPL_NAME@::@IMPL_NAME@(noise_type_t type, float ampl, long seed) + : gr_sync_block("@BASE_NAME@", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, sizeof(@TYPE@))), + d_type(type), + d_ampl(ampl), + d_rng(seed) + { + } + + @IMPL_NAME@::~@IMPL_NAME@() + { + } + + int + @IMPL_NAME@::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + @TYPE@ *out = (@TYPE@*)output_items[0]; + + switch(d_type) { +#if @IS_COMPLEX@ // complex? + + case GR_UNIFORM: + for(int i = 0; i < noutput_items; i++) { + out[i] = gr_complex(d_ampl * ((d_rng.ran1() * 2.0) - 1.0), + d_ampl * ((d_rng.ran1() * 2.0) - 1.0)); + } + break; + + case GR_GAUSSIAN: + for(int i = 0; i < noutput_items; i++) { + out[i] = d_ampl * d_rng.rayleigh_complex(); + } + break; + +#else // nope... + + case GR_UNIFORM: + for(int i = 0; i < noutput_items; i++) { + out[i] = (@TYPE@)(d_ampl * ((d_rng.ran1() * 2.0) - 1.0)); + } + break; + + case GR_GAUSSIAN: + for(int i = 0; i < noutput_items; i++) { + out[i] = (@TYPE@)(d_ampl * d_rng.gasdev()); + } + break; + + case GR_LAPLACIAN: + for(int i = 0; i < noutput_items; i++) { + out[i] = (@TYPE@)(d_ampl * d_rng.laplacian()); + } + break; + + case GR_IMPULSE: // FIXME changeable impulse settings + for(int i = 0; i < noutput_items; i++) { + out[i] = (@TYPE@)(d_ampl * d_rng.impulse(9)); + } + break; +#endif + + default: + throw std::runtime_error("invalid type"); + } + + return noutput_items; + } + + } /* namespace analog */ +} /* namespace gr */ + diff --git a/gr-analog/lib/noise_source_X_impl.h.t b/gr-analog/lib/noise_source_X_impl.h.t new file mode 100644 index 000000000..8bcc1dfde --- /dev/null +++ b/gr-analog/lib/noise_source_X_impl.h.t @@ -0,0 +1,58 @@ +/* -*- 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. + */ + +/* @WARNING@ */ + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include <analog/@BASE_NAME@.h> +#include <gr_random.h> + +namespace gr { + namespace analog { + + class @IMPL_NAME@ : public @BASE_NAME@ + { + noise_type_t d_type; + float d_ampl; + gr_random d_rng; + + public: + @IMPL_NAME@(noise_type_t type, float ampl, long seed = 0); + ~@IMPL_NAME@(); + + void set_type(noise_type_t type) { d_type = type; } + void set_amplitude(float ampl) { d_ampl = ampl; } + + noise_type_t type() const { return d_type; } + float amplitude() const { return d_ampl; } + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace filter */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-analog/python/qa_noise.py b/gr-analog/python/qa_noise.py new file mode 100755 index 000000000..dd94fc231 --- /dev/null +++ b/gr-analog/python/qa_noise.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# +# Copyright 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 + +class test_noise_source(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001(self): + # Just confirm that we can instantiate a noise source + op = analog.noise_source_f(analog.GR_GAUSSIAN, 10, 10) + + def test_002(self): + # Test get methods + set_type = analog.GR_GAUSSIAN + set_ampl = 10 + op = analog.noise_source_f(set_type, set_ampl, 10) + get_type = op.type() + get_ampl = op.amplitude() + + self.assertEqual(get_type, set_type) + self.assertEqual(get_ampl, set_ampl) + + +if __name__ == '__main__': + gr_unittest.run(test_noise_source, "test_noise_source.xml") + diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i index 8e1bb8058..4c35f9b07 100644 --- a/gr-analog/swig/analog_swig.i +++ b/gr-analog/swig/analog_swig.i @@ -28,6 +28,7 @@ %{ #include "analog/cpm.h" +#include "analog/noise_type.h" #include "analog/agc_cc.h" #include "analog/agc_ff.h" #include "analog/agc2_cc.h" @@ -38,11 +39,16 @@ #include "analog/feedforward_agc_cc.h" #include "analog/fmdet_cf.h" #include "analog/frequency_modulator_fc.h" +#include "analog/noise_source_s.h" +#include "analog/noise_source_i.h" +#include "analog/noise_source_f.h" +#include "analog/noise_source_c.h" #include "analog/squelch_base_cc.h" #include "analog/squelch_base_ff.h" %} %include "analog/cpm.h" +%include "analog/noise_type.h" %include "analog/agc_cc.h" %include "analog/agc_ff.h" %include "analog/agc2_cc.h" @@ -53,6 +59,10 @@ %include "analog/feedforward_agc_cc.h" %include "analog/fmdet_cf.h" %include "analog/frequency_modulator_fc.h" +%include "analog/noise_source_s.h" +%include "analog/noise_source_i.h" +%include "analog/noise_source_f.h" +%include "analog/noise_source_c.h" %include "analog/squelch_base_cc.h" %include "analog/squelch_base_ff.h" @@ -66,3 +76,7 @@ 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); +GR_SWIG_BLOCK_MAGIC2(analog, noise_source_s); +GR_SWIG_BLOCK_MAGIC2(analog, noise_source_i); +GR_SWIG_BLOCK_MAGIC2(analog, noise_source_f); +GR_SWIG_BLOCK_MAGIC2(analog, noise_source_c); |