diff options
author | Tom Rondeau <trondeau@vt.edu> | 2013-02-06 10:52:29 -0500 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2013-02-06 10:52:29 -0500 |
commit | 43c5b002c181d3d270d0cf91591c086d896086aa (patch) | |
tree | a390e7fb3abde4386aee76fb033c43520031ff32 | |
parent | be45281798f35b7e2ec2380503b97590d6b754b4 (diff) | |
parent | ac631948603583392189722d0e9b8654a2324670 (diff) |
Merge branch 'master' into next
Merges fastnoise_source from master and reorganizes it to gr-analog.
Conflicts:
gnuradio-core/src/lib/general/CMakeLists.txt
gnuradio-core/src/lib/general/general.i
gnuradio-core/src/lib/gengen/CMakeLists.txt
gnuradio-core/src/lib/hier/gr_channel_model.cc
gnuradio-core/src/lib/hier/gr_channel_model.h
-rw-r--r-- | gnuradio-core/src/lib/general/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/general.i | 2 | ||||
-rw-r--r-- | gnuradio-core/src/lib/general/gr_random_pdu.cc | 4 | ||||
-rw-r--r-- | gnuradio-core/src/lib/gengen/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gr-analog/include/analog/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-analog/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-analog/lib/fastnoise_source_X_impl.cc.t | 126 | ||||
-rw-r--r-- | gr-analog/lib/fastnoise_source_X_impl.h.t | 61 | ||||
-rw-r--r-- | gr-analog/swig/analog_swig.i | 12 | ||||
-rw-r--r-- | gr-channels/include/channels/channel_model.h | 8 | ||||
-rw-r--r-- | gr-channels/lib/channel_model_impl.cc | 4 | ||||
-rw-r--r-- | gr-channels/lib/channel_model_impl.h | 4 |
12 files changed, 215 insertions, 11 deletions
diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 6d67b333b9..26dab910c9 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -169,6 +169,7 @@ set(gr_core_general_triple_threats gr_pa_2x2_phase_combiner gr_peak_detector2_fb gr_prefs + gr_random_pdu gr_regenerate_bb gr_remez gr_rms_cf diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 4e483500ee..e379c40867 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -40,6 +40,7 @@ #include <gr_endian_swap.h> #include <gr_firdes.h> #include <gr_delay.h> +#include <gr_random_pdu.h> #include <gr_rms_cf.h> #include <gr_rms_ff.h> #include <gr_fake_channel_coder_pp.h> @@ -89,6 +90,7 @@ %include "gr_endian_swap.i" %include "gr_firdes.i" %include "gr_delay.i" +%include "gr_random_pdu.i" %include "gr_rms_cf.i" %include "gr_rms_ff.i" %include "gr_fake_channel_coder_pp.i" diff --git a/gnuradio-core/src/lib/general/gr_random_pdu.cc b/gnuradio-core/src/lib/general/gr_random_pdu.cc index 9f692c72be..61332c0715 100644 --- a/gnuradio-core/src/lib/general/gr_random_pdu.cc +++ b/gnuradio-core/src/lib/general/gr_random_pdu.cc @@ -74,8 +74,8 @@ void gr_random_pdu::output_random(){ } // send the vector - pmt::pmt_t vecpmt( pmt::pmt_make_blob( vec, len ) ); - pmt::pmt_t pdu( pmt::pmt_cons( pmt::PMT_NIL, vecpmt ) ); + pmt::pmt_t vecpmt( pmt::make_blob( vec, len ) ); + pmt::pmt_t pdu( pmt::cons( pmt::PMT_NIL, vecpmt ) ); message_port_pub( pmt::mp("pdus"), pdu ); std::cout << "sending new random vector of length " << len << "\n"; diff --git a/gnuradio-core/src/lib/gengen/CMakeLists.txt b/gnuradio-core/src/lib/gengen/CMakeLists.txt index 404a258873..d018876183 100644 --- a/gnuradio-core/src/lib/gengen/CMakeLists.txt +++ b/gnuradio-core/src/lib/gengen/CMakeLists.txt @@ -145,7 +145,7 @@ install(FILES if(ENABLE_PYTHON) install(FILES - ${generated_gengen_swigs} + ${generated_gengen_swigs} ${CMAKE_CURRENT_SOURCE_DIR}/gr_endianness.i ${CMAKE_CURRENT_SOURCE_DIR}/gengen.i ${CMAKE_CURRENT_BINARY_DIR}/gengen_generated.i diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt index 2496e7f057..1ae24f8c28 100644 --- a/gr-analog/include/analog/CMakeLists.txt +++ b/gr-analog/include/analog/CMakeLists.txt @@ -65,6 +65,7 @@ endmacro(expand_h) # Invoke macro to generate various sources ####################################################################### expand_h(noise_source_X s i f c) +expand_h(fastnoise_source_X s i f c) expand_h(sig_source_X s i f c) add_custom_target(analog_generated_includes DEPENDS diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index a7b328607a..3e95beda15 100644 --- a/gr-analog/lib/CMakeLists.txt +++ b/gr-analog/lib/CMakeLists.txt @@ -100,6 +100,7 @@ endmacro(expand_cc) # Invoke macro to generate various sources ######################################################################## expand_cc(noise_source_X_impl s i f c) +expand_cc(fastnoise_source_X_impl s i f c) expand_cc(sig_source_X_impl s i f c) ######################################################################## diff --git a/gr-analog/lib/fastnoise_source_X_impl.cc.t b/gr-analog/lib/fastnoise_source_X_impl.cc.t new file mode 100644 index 0000000000..f33e7afa39 --- /dev/null +++ b/gr-analog/lib/fastnoise_source_X_impl.cc.t @@ -0,0 +1,126 @@ +/* -*- c++ -*- */ +/* + * Copyright 2013 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, long samples) + { + return gnuradio::get_initial_sptr + (new @IMPL_NAME@(type, ampl, seed, samples)); + } + + @IMPL_NAME@::@IMPL_NAME@(noise_type_t type, float ampl, long seed, long samples) + : 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) + { + d_samples.resize(samples); + generate(); + } + + @IMPL_NAME@::~@IMPL_NAME@() + { + } + + void + @IMPL_NAME@::generate() + { + int noutput_items = d_samples.size(); + switch(d_type){ +#if @IS_COMPLEX@ // complex? + + case GR_UNIFORM: + for(int i = 0; i < noutput_items; i++) + d_samples[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++) + d_samples[i] = d_ampl * d_rng.rayleigh_complex(); + break; + +#else // nope... + + case GR_UNIFORM: + for(int i = 0; i < noutput_items; i++) + d_samples[i] = (@TYPE@)(d_ampl * ((d_rng.ran1() * 2.0) - 1.0)); + break; + + case GR_GAUSSIAN: + for(int i = 0; i < noutput_items; i++) + d_samples[i] = (@TYPE@)(d_ampl * d_rng.gasdev()); + break; + + case GR_LAPLACIAN: + for(int i = 0; i < noutput_items; i++) + d_samples[i] = (@TYPE@)(d_ampl * d_rng.laplacian()); + break; + + case GR_IMPULSE: // FIXME changeable impulse settings + for(int i = 0; i < noutput_items; i++) + d_samples[i] = (@TYPE@)(d_ampl * d_rng.impulse(9)); + break; +#endif + + default: + throw std::runtime_error("invalid type"); + } + } + + 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]; + + for(int i=0; i<noutput_items; i++) { +#ifdef __USE_GNU + size_t idx = lrand48() % d_samples.size(); +#else + size_t idx = rand() % d_samples.size(); +#endif + out[i] = d_samples[idx]; + } + + return noutput_items; + } + + } /* namespace analog */ +} /* namespace gr */ + diff --git a/gr-analog/lib/fastnoise_source_X_impl.h.t b/gr-analog/lib/fastnoise_source_X_impl.h.t new file mode 100644 index 0000000000..7a0f792683 --- /dev/null +++ b/gr-analog/lib/fastnoise_source_X_impl.h.t @@ -0,0 +1,61 @@ +/* -*- c++ -*- */ +/* + * Copyright 2013 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@ + { + private: + noise_type_t d_type; + float d_ampl; + gr_random d_rng; + std::vector<@TYPE@> d_samples; + + public: + @IMPL_NAME@(noise_type_t type, float ampl, long seed, long samples); + ~@IMPL_NAME@(); + + void set_type(noise_type_t type) { d_type = type; generate(); } + void set_amplitude(float ampl) { d_ampl = ampl; generate(); } + void generate(); + + 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/swig/analog_swig.i b/gr-analog/swig/analog_swig.i index 5171af09bb..ab7beb3c0f 100644 --- a/gr-analog/swig/analog_swig.i +++ b/gr-analog/swig/analog_swig.i @@ -40,6 +40,10 @@ #include "analog/feedforward_agc_cc.h" #include "analog/fmdet_cf.h" #include "analog/frequency_modulator_fc.h" +#include "analog/fastnoise_source_s.h" +#include "analog/fastnoise_source_i.h" +#include "analog/fastnoise_source_f.h" +#include "analog/fastnoise_source_c.h" #include "analog/noise_source_s.h" #include "analog/noise_source_i.h" #include "analog/noise_source_f.h" @@ -78,6 +82,10 @@ %include "analog/feedforward_agc_cc.h" %include "analog/fmdet_cf.h" %include "analog/frequency_modulator_fc.h" +%include "analog/fastnoise_source_s.h" +%include "analog/fastnoise_source_i.h" +%include "analog/fastnoise_source_f.h" +%include "analog/fastnoise_source_c.h" %include "analog/noise_source_s.h" %include "analog/noise_source_i.h" %include "analog/noise_source_f.h" @@ -113,6 +121,10 @@ 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, fastnoise_source_s); +GR_SWIG_BLOCK_MAGIC2(analog, fastnoise_source_i); +GR_SWIG_BLOCK_MAGIC2(analog, fastnoise_source_f); +GR_SWIG_BLOCK_MAGIC2(analog, fastnoise_source_c); GR_SWIG_BLOCK_MAGIC2(analog, noise_source_s); GR_SWIG_BLOCK_MAGIC2(analog, noise_source_i); GR_SWIG_BLOCK_MAGIC2(analog, noise_source_f); diff --git a/gr-channels/include/channels/channel_model.h b/gr-channels/include/channels/channel_model.h index e509933af0..2fe73da90b 100644 --- a/gr-channels/include/channels/channel_model.h +++ b/gr-channels/include/channels/channel_model.h @@ -65,10 +65,10 @@ namespace gr { * \param noise_seed A random number generator seed for the noise source. */ static sptr make(double noise_voltage=0.0, - double frequency_offset=0.0, - double epsilon=1.0, - const std::vector<gr_complex> &taps=std::vector<gr_complex>(1,1), - double noise_seed=0); + double frequency_offset=0.0, + double epsilon=1.0, + const std::vector<gr_complex> &taps=std::vector<gr_complex>(1,1), + double noise_seed=0); virtual void set_noise_voltage(double noise_voltage) = 0; virtual void set_frequency_offset(double frequency_offset) = 0; diff --git a/gr-channels/lib/channel_model_impl.cc b/gr-channels/lib/channel_model_impl.cc index 36fbd7ed63..a7e866fbc1 100644 --- a/gr-channels/lib/channel_model_impl.cc +++ b/gr-channels/lib/channel_model_impl.cc @@ -62,8 +62,8 @@ namespace gr { d_multipath = filter::fir_filter_ccc::make(1, d_taps); d_noise_adder = blocks::add_cc::make(); - d_noise = analog::noise_source_c::make(analog::GR_GAUSSIAN, - noise_voltage, noise_seed); + d_noise = analog::fastnoise_source_c::make(analog::GR_GAUSSIAN, + noise_voltage, noise_seed); d_freq_offset = analog::sig_source_c::make(1, analog::GR_SIN_WAVE, frequency_offset, 1.0, 0.0); d_mixer_offset = blocks::multiply_cc::make(); diff --git a/gr-channels/lib/channel_model_impl.h b/gr-channels/lib/channel_model_impl.h index ce79e54aae..b94555f122 100644 --- a/gr-channels/lib/channel_model_impl.h +++ b/gr-channels/lib/channel_model_impl.h @@ -27,7 +27,7 @@ #include <blocks/add_cc.h> #include <blocks/multiply_cc.h> #include <analog/sig_source_c.h> -#include <analog/noise_source_c.h> +#include <analog/fastnoise_source_c.h> #include <channels/channel_model.h> #include <filter/fractional_interpolator_cc.h> #include <filter/fir_filter_ccc.h> @@ -42,7 +42,7 @@ namespace gr { blocks::multiply_cc::sptr d_mixer_offset; analog::sig_source_c::sptr d_freq_offset; - analog::noise_source_c::sptr d_noise; + analog::fastnoise_source_c::sptr d_noise; filter::fractional_interpolator_cc::sptr d_timing_offset; filter::fir_filter_ccc::sptr d_multipath; |