diff options
author | Tom Rondeau <tom@trondeau.com> | 2013-08-23 16:41:48 -0400 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2013-08-27 13:36:58 -0400 |
commit | 797b3b061a2ae79b51853e1b86fd9f511a8f36f4 (patch) | |
tree | ce8c16737a6db987639cf2e638e3a0b3a9212a92 | |
parent | 9c03a0d2aab4705c37645c87af1ec591e9a515cd (diff) |
channels: added second channel model that takes in a function to change freq/timing offsets.
-rw-r--r-- | gr-channels/grc/channels_channel_model2.xml | 61 | ||||
-rw-r--r-- | gr-channels/include/gnuradio/channels/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-channels/include/gnuradio/channels/channel_model2.h | 102 | ||||
-rw-r--r-- | gr-channels/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-channels/lib/channel_model2_impl.cc | 174 | ||||
-rw-r--r-- | gr-channels/lib/channel_model2_impl.h | 76 | ||||
-rw-r--r-- | gr-channels/swig/channels_swig.i | 3 |
7 files changed, 418 insertions, 0 deletions
diff --git a/gr-channels/grc/channels_channel_model2.xml b/gr-channels/grc/channels_channel_model2.xml new file mode 100644 index 0000000000..e8162f53d4 --- /dev/null +++ b/gr-channels/grc/channels_channel_model2.xml @@ -0,0 +1,61 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Channel Model +################################################### + --> +<block> + <name>Channel Model 2</name> + <key>channels_channel_model2</key> + <import>from gnuradio import channels</import> + <import>from gnuradio.filter import firdes</import> + <make>channels.channel_model2( + noise_voltage=$noise_voltage, + epsilon=$epsilon, + taps=$taps, + noise_seed=$seed, +)</make> + <callback>set_noise_voltage($noise_voltage)</callback> + <callback>set_taps($taps)</callback> + <callback>set_timing_offset($epsilon)</callback> + <param> + <name>Noise Voltage</name> + <key>noise_voltage</key> + <value>0.0</value> + <type>real</type> + </param> + <param> + <name>Time Offset</name> + <key>epsilon</key> + <value>1.0</value> + <type>real</type> + </param> + <param> + <name>Taps</name> + <key>taps</key> + <value>1.0 + 1.0j</value> + <type>complex_vector</type> + </param> + <param> + <name>Seed</name> + <key>seed</key> + <value>0</value> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>complex</type> + </sink> + <sink> + <name>freq</name> + <type>float</type> + </sink> + <sink> + <name>time</name> + <type>float</type> + </sink> + <source> + <name>out</name> + <type>complex</type> + </source> +</block> diff --git a/gr-channels/include/gnuradio/channels/CMakeLists.txt b/gr-channels/include/gnuradio/channels/CMakeLists.txt index f9a535b9c0..cb618a7e8d 100644 --- a/gr-channels/include/gnuradio/channels/CMakeLists.txt +++ b/gr-channels/include/gnuradio/channels/CMakeLists.txt @@ -23,6 +23,7 @@ install(FILES api.h channel_model.h + channel_model2.h fading_model.h selective_fading_model.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio/channels diff --git a/gr-channels/include/gnuradio/channels/channel_model2.h b/gr-channels/include/gnuradio/channels/channel_model2.h new file mode 100644 index 0000000000..05084931ee --- /dev/null +++ b/gr-channels/include/gnuradio/channels/channel_model2.h @@ -0,0 +1,102 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009,2012,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. + */ + +#ifndef INCLUDED_CHANNELS_CHANNEL_MODEL2_H +#define INCLUDED_CHANNELS_CHANNEL_MODEL2_H + +#include <gnuradio/channels/api.h> +#include <gnuradio/hier_block2.h> +#include <gnuradio/types.h> + +namespace gr { + namespace channels { + + /*! + * \brief channel model2 + * \ingroup channel_models_blk + * + * \details + * This block implements a basic channel model simulator that can + * be used to help evaluate, design, and test various signals, + * waveforms, and algorithms. + * + * This model allows the user to set the voltage of an AWGN noise + * source, an initial timing offset, and a noise seed to randomize + * the AWGN noise source. + * + * Multipath can be approximated in this model by using a FIR + * filter representation of a multipath delay profile. + * + * Unlike gr::channels::channel_model, this block is designed to + * enable time-varying frequency and timing offsets. + * * Port 0: input signal to be run through the channel. + * * Port 1: frequency function. A constant value between -0.5 and + * 0.5 here will turn into a constant frequency offset + * from -fs/2 to fs/2 (where fs is the sample rate). + * * Port 2: timing offset function. Sets the resampling rate of + * the channel model. A constant value here produces + * that value as the timing offset, so a constant 1.0 + * input stream is the same as not having a timing + * offset. + * + * Since the models for frequency and timing offset may vary and + * what we are trying to model may be different for different + * simulations, we provide the time-varying nature as an input + * function that is user-defined. If only constant frequency and + * timing offsets are required, it is easier and less expensive to + * use gr::channels::channel_model. + */ + class CHANNELS_API channel_model2 : virtual public hier_block2 + { + public: + // gr::channels::channel_model2::sptr + typedef boost::shared_ptr<channel_model2> sptr; + + /*! \brief Build the channel simulator. + * + * \param noise_voltage The AWGN noise level as a voltage (to be + * calculated externally to meet, say, a + * desired SNR). + * \param epsilon The initial sample timing offset to emulate the + * different rates between the sample clocks of + * the transmitter and receiver. 1.0 is no difference. + * \param taps Taps of a FIR filter to emulate a multipath delay profile. + * \param noise_seed A random number generator seed for the noise source. + */ + static sptr make(double noise_voltage=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_taps(const std::vector<gr_complex> &taps) = 0; + virtual void set_timing_offset(double epsilon) = 0; + + virtual double noise_voltage() const = 0; + virtual std::vector<gr_complex> taps() const = 0; + virtual double timing_offset() const = 0; + }; + + } /* namespace channels */ +} /* namespace gr */ + +#endif /* INCLUDED_CHANNELS_CHANNEL_MODEL2_H */ diff --git a/gr-channels/lib/CMakeLists.txt b/gr-channels/lib/CMakeLists.txt index 46c90671c2..f429fae0fc 100644 --- a/gr-channels/lib/CMakeLists.txt +++ b/gr-channels/lib/CMakeLists.txt @@ -43,6 +43,7 @@ endif(ENABLE_GR_CTRLPORT) ######################################################################## list(APPEND channels_sources channel_model_impl.cc + channel_model2_impl.cc fading_model_impl.cc selective_fading_model_impl.cc flat_fader_impl.cc diff --git a/gr-channels/lib/channel_model2_impl.cc b/gr-channels/lib/channel_model2_impl.cc new file mode 100644 index 0000000000..cd742305cb --- /dev/null +++ b/gr-channels/lib/channel_model2_impl.cc @@ -0,0 +1,174 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009,2012,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. + */ + +#include "channel_model2_impl.h" +#include <gnuradio/io_signature.h> +#include <iostream> + +namespace gr { + namespace channels { + + channel_model2::sptr + channel_model2::make(double noise_voltage, + double epsilon, + const std::vector<gr_complex> &taps, + double noise_seed) + { + return gnuradio::get_initial_sptr + (new channel_model2_impl(noise_voltage, + epsilon, + taps, + noise_seed)); + } + + // Hierarchical block constructor + channel_model2_impl::channel_model2_impl(double noise_voltage, + double epsilon, + const std::vector<gr_complex> &taps, + double noise_seed) + : hier_block2("channel_model2", + io_signature::make2(3, 3, sizeof(gr_complex), sizeof(float)), + io_signature::make(1, 1, sizeof(gr_complex))) + { + d_taps = taps; + while(d_taps.size() < 2) { + d_taps.push_back(0); + } + + d_timing_offset = filter::fractional_resampler_cc::make(0, epsilon); + + d_multipath = filter::fir_filter_ccc::make(1, d_taps); + + d_noise_adder = blocks::add_cc::make(); + d_noise = analog::fastnoise_source_c::make(analog::GR_GAUSSIAN, + noise_voltage, noise_seed); + d_freq_gen = blocks::vco_c::make(1.0, 2*M_PI, 1.0); + + d_mixer_offset = blocks::multiply_cc::make(); + + connect(self(), 0, d_timing_offset, 0); + connect(self(), 2, d_timing_offset, 1); + connect(d_timing_offset, 0, d_multipath, 0); + connect(d_multipath, 0, d_mixer_offset, 0); + + connect(self(), 1, d_freq_gen, 0); + connect(d_freq_gen, 0, d_mixer_offset, 1); + + connect(d_mixer_offset, 0, d_noise_adder, 1); + connect(d_noise, 0, d_noise_adder, 0); + connect(d_noise_adder, 0, self(), 0); + } + + channel_model2_impl::~channel_model2_impl() + { + } + + void + channel_model2_impl::set_noise_voltage(double noise_voltage) + { + d_noise->set_amplitude(noise_voltage); + } + + void + channel_model2_impl::set_taps(const std::vector<gr_complex> &taps) + { + d_taps = taps; + while(d_taps.size() < 2) { + d_taps.push_back(0); + } + d_multipath->set_taps(d_taps); + } + + void + channel_model2_impl::set_timing_offset(double epsilon) + { + d_timing_offset->set_resamp_ratio(epsilon); + } + + double + channel_model2_impl::noise_voltage() const + { + return d_noise->amplitude(); + } + + std::vector<gr_complex> + channel_model2_impl::taps() const + { + return d_multipath->taps(); + } + + double + channel_model2_impl::timing_offset() const + { + return d_timing_offset->resamp_ratio(); + } + + void + channel_model2_impl::setup_rpc() + { +#ifdef GR_CTRLPORT + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_get<channel_model2, double>( + alias(), "noise", + &channel_model2::noise_voltage, + pmt::mp(-10.0f), pmt::mp(10.0f), pmt::mp(0.0f), + "", "Noise Voltage", RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); + + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_get<channel_model2, double>( + alias(), "timing", + &channel_model2::timing_offset, + pmt::mp(0.0), pmt::mp(2.0), pmt::mp(0.0), + "", "Timing Offset", RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); + + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_get<channel_model2, std::vector<gr_complex> >( + alias(), "taps", + &channel_model2::taps, + pmt::make_c32vector(0,-10), + pmt::make_c32vector(0,10), + pmt::make_c32vector(0,0), + "", "Multipath taps", RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTCPLX | DISPOPTSTRIP))); + + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_set<channel_model2, double>( + alias(), "noise", + &channel_model2::set_noise_voltage, + pmt::mp(-10.0), pmt::mp(10.0), pmt::mp(0.0), + "V", "Noise Voltage", + RPC_PRIVLVL_MIN, DISPNULL))); + + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_set<channel_model2, double>( + alias(), "timing", + &channel_model2::set_timing_offset, + pmt::mp(0.0f), pmt::mp(2.0f), pmt::mp(0.0f), + "", "Timing Offset", + RPC_PRIVLVL_MIN, DISPNULL))); +#endif /* GR_CTRLPORT */ + } + + } /* namespace channels */ +} /* namespace gr */ diff --git a/gr-channels/lib/channel_model2_impl.h b/gr-channels/lib/channel_model2_impl.h new file mode 100644 index 0000000000..db2a667f9c --- /dev/null +++ b/gr-channels/lib/channel_model2_impl.h @@ -0,0 +1,76 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009,2012,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. + */ + +#ifndef INCLUDED_CHANNELS_CHANNEL_MODEL2_IMPL_H +#define INCLUDED_CHANNELS_CHANNEL_MODEL2_IMPL_H + +#include <gnuradio/channels/channel_model2.h> +#include <gnuradio/top_block.h> +#include <gnuradio/blocks/add_cc.h> +#include <gnuradio/blocks/multiply_cc.h> +#include <gnuradio/analog/sig_source_c.h> +#include <gnuradio/analog/fastnoise_source_c.h> +#include <gnuradio/filter/fractional_resampler_cc.h> +#include <gnuradio/filter/fir_filter_ccc.h> +#include <gnuradio/blocks/vco_c.h> + +namespace gr { + namespace channels { + + class CHANNELS_API channel_model2_impl : public channel_model2 + { + private: + blocks::add_cc::sptr d_noise_adder; + blocks::multiply_cc::sptr d_mixer_offset; + + blocks::vco_c::sptr d_freq_gen; + + analog::fastnoise_source_c::sptr d_noise; + + filter::fractional_resampler_cc::sptr d_timing_offset; + filter::fir_filter_ccc::sptr d_multipath; + + std::vector<gr_complex> d_taps; + + public: + channel_model2_impl(double noise_voltage, + double epsilon, + const std::vector<gr_complex> &taps, + double noise_seed); + + ~channel_model2_impl(); + + void setup_rpc(); + + void set_noise_voltage(double noise_voltage); + void set_taps(const std::vector<gr_complex> &taps); + void set_timing_offset(double epsilon); + + double noise_voltage() const; + std::vector<gr_complex> taps() const; + double timing_offset() const; + }; + + } /* namespace channels */ +} /* namespace gr */ + +#endif /* INCLUDED_CHANNELS_CHANNEL_MODEL2_IMPL_H */ diff --git a/gr-channels/swig/channels_swig.i b/gr-channels/swig/channels_swig.i index fb7ada7dae..784a10a085 100644 --- a/gr-channels/swig/channels_swig.i +++ b/gr-channels/swig/channels_swig.i @@ -29,14 +29,17 @@ %{ #include "gnuradio/channels/channel_model.h" +#include "gnuradio/channels/channel_model2.h" #include "gnuradio/channels/fading_model.h" #include "gnuradio/channels/selective_fading_model.h" %} %include "gnuradio/channels/channel_model.h" +%include "gnuradio/channels/channel_model2.h" %include "gnuradio/channels/fading_model.h" %include "gnuradio/channels/selective_fading_model.h" GR_SWIG_BLOCK_MAGIC2(channels, channel_model); +GR_SWIG_BLOCK_MAGIC2(channels, channel_model2); GR_SWIG_BLOCK_MAGIC2(channels, fading_model); GR_SWIG_BLOCK_MAGIC2(channels, selective_fading_model); |