diff options
20 files changed, 1097 insertions, 5 deletions
diff --git a/gr-analog/include/gnuradio/analog/fastnoise_source_X.h.t b/gr-analog/include/gnuradio/analog/fastnoise_source_X.h.t index c5331fc084..5f94a7eb56 100644 --- a/gr-analog/include/gnuradio/analog/fastnoise_source_X.h.t +++ b/gr-analog/include/gnuradio/analog/fastnoise_source_X.h.t @@ -55,6 +55,8 @@ namespace gr { */ static sptr make(noise_type_t type, float ampl, long seed = 0, long samples=1024*16); + virtual @TYPE@ sample() = 0; + virtual @TYPE@ sample_unbiased() = 0; virtual void set_type(noise_type_t type) = 0; virtual void set_amplitude(float ampl) = 0; diff --git a/gr-analog/lib/fastnoise_source_X_impl.cc.t b/gr-analog/lib/fastnoise_source_X_impl.cc.t index e6c7f13f34..c7831bb735 100644 --- a/gr-analog/lib/fastnoise_source_X_impl.cc.t +++ b/gr-analog/lib/fastnoise_source_X_impl.cc.t @@ -128,15 +128,35 @@ namespace gr { @TYPE@ *out = (@TYPE@*)output_items[0]; for(int i=0; i<noutput_items; i++) { + out[i] = sample(); + } + + return noutput_items; + } + + @TYPE@ @IMPL_NAME@::sample() + { #ifdef __USE_GNU - size_t idx = lrand48() % d_samples.size(); + size_t idx = lrand48() % d_samples.size(); #else - size_t idx = rand() % d_samples.size(); + size_t idx = rand() % d_samples.size(); #endif - out[i] = d_samples[idx]; - } + return d_samples[idx]; + } - return noutput_items; +#ifndef FASTNOISE_RANDOM_SIGN +#define FASTNOISE_RANDOM_SIGN ((lrand48()%2==0)?1:-1) +#endif + + @TYPE@ @IMPL_NAME@::sample_unbiased() + { +#if @IS_COMPLEX@ + gr_complex s(sample()); + return gr_complex(FASTNOISE_RANDOM_SIGN * s.real(), + FASTNOISE_RANDOM_SIGN * s.imag()); +#else + return FASTNOISE_RANDOM_SIGN * sample(); +#endif } } /* namespace analog */ diff --git a/gr-analog/lib/fastnoise_source_X_impl.h.t b/gr-analog/lib/fastnoise_source_X_impl.h.t index ed342ec176..8ad1e4f8fe 100644 --- a/gr-analog/lib/fastnoise_source_X_impl.h.t +++ b/gr-analog/lib/fastnoise_source_X_impl.h.t @@ -43,6 +43,9 @@ namespace gr { @IMPL_NAME@(noise_type_t type, float ampl, long seed, long samples); ~@IMPL_NAME@(); + @TYPE@ sample(); + @TYPE@ sample_unbiased(); + void set_type(noise_type_t type); void set_amplitude(float ampl); void generate(); diff --git a/gr-channels/grc/channels_block_tree.xml b/gr-channels/grc/channels_block_tree.xml index 154e9204d1..22c1fc8732 100644 --- a/gr-channels/grc/channels_block_tree.xml +++ b/gr-channels/grc/channels_block_tree.xml @@ -31,7 +31,11 @@ <cat> <name>Channel Models</name> <block>channels_channel_model</block> + <block>channels_channel_model2</block> + <block>channels_conj_fs_iqcorr</block> <block>channels_fading_model</block> + <block>channels_dynamic_channel_model</block> + <block>channels_selective_fading_model</block> </cat> <cat> <name>Impairment Models</name> @@ -43,5 +47,8 @@ <block>channels_distortion_3_gen</block> <block>channels_amp_bal</block> <block>channels_phase_bal</block> + <block>channels_cfo_model</block> + <block>channels_sro_model</block> </cat> </cat> + diff --git a/gr-channels/grc/channels_cfo_model.xml b/gr-channels/grc/channels_cfo_model.xml new file mode 100644 index 0000000000..188d89c52d --- /dev/null +++ b/gr-channels/grc/channels_cfo_model.xml @@ -0,0 +1,49 @@ +<?xml version="1.0"?> +<!-- +################################################### +##CFO Model +################################################### + --> +<block> + <name>CFO Model</name> + <key>channels_cfo_model</key> + <import>from gnuradio import channels</import> + <make>channels.cfo_model( + $srate, + $stdev, + $maxdev, + $seed +)</make> + <param> + <name>Sample Rate Hz</name> + <key>srate</key> + <value>samp_rate</value> + <type>real</type> + </param> + <param> + <name>CFO Standard Deviation Hz per sample</name> + <key>stdev</key> + <value>0.01</value> + <type>real</type> + </param> + <param> + <name>Max CFO Bound Hz</name> + <key>maxdev</key> + <value>1e3</value> + <type>real</type> + </param> + <param> + <name>Seed</name> + <key>seed</key> + <value>0</value> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>complex</type> + </sink> + <source> + <name>out</name> + <type>complex</type> + </source> +</block> diff --git a/gr-channels/grc/channels_dynamic_channel_model.xml b/gr-channels/grc/channels_dynamic_channel_model.xml new file mode 100644 index 0000000000..b54256c864 --- /dev/null +++ b/gr-channels/grc/channels_dynamic_channel_model.xml @@ -0,0 +1,129 @@ +<?xml version="1.0"?> +<!-- +################################################### +# Dynamic Channel Model +################################################### + --> +<block> + <name>Dynamic Channel Model</name> + <key>channels_dynamic_channel_model</key> + <import>from gnuradio import channels</import> + <make>channels.dynamic_channel_model( $samp_rate, $sro_stdev, $sro_maxdev, $cfo_stdev, $cfo_maxdev, $N, $fD, $LOS, $K, $delays, $mags, $ntaps, $noise_amp, $seed )</make> + <callback>set_fDTs($fDTs)</callback> + <callback>set_K($K)</callback> + + <param> + <name>Sample Rate Hz</name> + <key>samp_rate</key> + <value>samp_rate</value> + <type>real</type> + </param> + <param> + <name>CFO Standard Deviation Hz per sample</name> + <key>cfo_stdev</key> + <value>0.01</value> + <type>real</type> + </param> + <param> + <name>Max CFO Bound Hz</name> + <key>cfo_maxdev</key> + <value>1e3</value> + <type>real</type> + </param> + + <param> + <name>SRO Standard Deviation Hz per sample</name> + <key>sro_stdev</key> + <value>0.01</value> + <type>real</type> + </param> + <param> + <name>Max SRO Bound Hz</name> + <key>sro_maxdev</key> + <value>1e3</value> + <type>real</type> + </param> + + <param> + <name>White Noise Amplitude</name> + <key>noise_amp</key> + <value>1.0</value> + <type>real</type> + </param> + + <param> + <name>Num Sinusoids (SoS model)</name> + <key>N</key> + <value>8</value> + <type>int</type> + </param> + <param> + <name>Max Doppler Freq (Hz)</name> + <key>fD</key> + <value>2.0</value> + <type>real</type> + </param> + <param> + <name>LOS Model</name> + <key>LOS</key> + <type>enum</type> + <option> + <name>Rayleigh/NLOS</name> + <key>False</key> + <opt>hide_K:all</opt> + </option> + <option> + <name>Rician/LOS</name> + <key>True</key> + <opt>hide_K:</opt> + </option> + </param> + <param> + <name>Rician factor (K)</name> + <key>K</key> + <value>4.0</value> + <type>real</type> + <hide>$LOS.hide_K</hide> + </param> + <param> + <name>Seed</name> + <key>seed</key> + <value>0</value> + <type>int</type> + </param> + <param> + <name>PDP Delays (samp)</name> + <key>delays</key> + <value>0.0,0.1,1.3</value> + <type>real_vector</type> + </param> + <param> + <name>PDP Magnitudes</name> + <key>mags</key> + <value>1,0.99,0.97</value> + <type>real_vector</type> + </param> + <param> + <name>Num Taps</name> + <key>ntaps</key> + <value>8</value> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>complex</type> + </sink> + <source> + <name>out</name> + <type>complex</type> + </source> + <doc> + The dynamic channel model is a hier block consisting of the following effects: + - Dynamic Frequency Selective Fading Channel + - Dynamic Center Frequency Offset Model + - Dynamic Sample Rate Offset Model + - Additive White Gaussian Noise + + The desired power delay profile and max doppler frequency may be provided to achieve the desired Ricean or Rayleigh fading scenario. For center frequency and sample rate offset models, a gaussian random walk process is conducted for each. The single sample step variance and maximum deviation for these two processes is specified and may be modified to simulate various desired stability effects. Lastly AWGN is added to simulate a typical receiver/thermal noise floor after propagation, and the variance may be modified here as desired. + </doc> +</block> diff --git a/gr-channels/grc/channels_sro_model.xml b/gr-channels/grc/channels_sro_model.xml new file mode 100644 index 0000000000..64d06899e6 --- /dev/null +++ b/gr-channels/grc/channels_sro_model.xml @@ -0,0 +1,49 @@ +<?xml version="1.0"?> +<!-- +################################################### +##SRO Model +################################################### + --> +<block> + <name>SRO Model</name> + <key>channels_sro_model</key> + <import>from gnuradio import channels</import> + <make>channels.sro_model( + $srate, + $stdev, + $maxdev, + $seed +)</make> + <param> + <name>Sample Rate Hz</name> + <key>srate</key> + <value>samp_rate</value> + <type>real</type> + </param> + <param> + <name>SRO Standard Deviation Hz per sample</name> + <key>stdev</key> + <value>0.01</value> + <type>real</type> + </param> + <param> + <name>Max SRO Bound Hz</name> + <key>maxdev</key> + <value>1e3</value> + <type>real</type> + </param> + <param> + <name>Seed</name> + <key>seed</key> + <value>0</value> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>complex</type> + </sink> + <source> + <name>out</name> + <type>complex</type> + </source> +</block> diff --git a/gr-channels/include/gnuradio/channels/cfo_model.h b/gr-channels/include/gnuradio/channels/cfo_model.h new file mode 100644 index 0000000000..bb23a8e9f2 --- /dev/null +++ b/gr-channels/include/gnuradio/channels/cfo_model.h @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009,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_CHANNELS_CFO_MODEL_H +#define INCLUDED_CHANNELS_CFO_MODEL_H + +#include <gnuradio/channels/api.h> +#include <gnuradio/sync_block.h> +#include <gnuradio/types.h> + +namespace gr { + namespace channels { + + /*! + * \brief channel simulator + * \ingroup channel_models_blk + * + * \details + * This block implements a carrier frequency offset model that + * can be used to simulate carrier frequency drift typically from + * mixer LO drift on either transmit or receive hardware. + * + * A clipped gaussian random walk process is used. + */ + class CHANNELS_API cfo_model : virtual public sync_block + { + public: + // gr::channels::cfo_model::sptr + typedef boost::shared_ptr<cfo_model> sptr; + + /*! \brief Build the carrier frequency offset model + * + * \param sample_rate_hz Sample rate of the input signal in Hz + * \param std_dev_hz Desired standard deviation of the random walk + process every sample in Hz + * \param max_dev_hz Maximum carrier frequency deviation in Hz. + * \param noise_seed A random number generator seed for the noise source. + */ + static sptr make( + double sample_rate_hz, + double std_dev_hz, + double max_dev_hz, + double noise_seed=0); + + }; + + } /* namespace channels */ +} /* namespace gr */ + +#endif /* INCLUDED_CHANNELS_CFO_MODEL_H */ diff --git a/gr-channels/include/gnuradio/channels/dynamic_channel_model.h b/gr-channels/include/gnuradio/channels/dynamic_channel_model.h new file mode 100644 index 0000000000..7b23a4144d --- /dev/null +++ b/gr-channels/include/gnuradio/channels/dynamic_channel_model.h @@ -0,0 +1,96 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009,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_CHANNELS_DYNAMIC_CHANNEL_MODEL_H +#define INCLUDED_CHANNELS_DYNAMIC_CHANNEL_MODEL_H + +#include <gnuradio/channels/api.h> +#include <gnuradio/hier_block2.h> +#include <gnuradio/types.h> + +namespace gr { + namespace channels { + + /*! + * \brief dynamic channel simulator + * \ingroup dynamic_channel_models_blk + * + * \details + * This block implements a dynamic 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 up an AWGN noise cource, a + * random walk process to simulate carrier frequency drift, a random + * walk process to simulate sample rate offset drive, and a frequency + * selective fading channel response that is either Rayleigh or Ricean + * for a user specified power delay profile. + */ + class CHANNELS_API dynamic_channel_model : virtual public hier_block2 + { + public: + // gr::channels::dynamic_channel_model::sptr + typedef boost::shared_ptr<dynamic_channel_model> sptr; + + /*! \brief Build the dynamic channel simulator. + * + * \param samp_rate Input sample rate in Hz + * \param sro_std_dev sample rate drift process standard deviation per sample in Hz + * \param sro_max_dev maximum sample rate offset in Hz + * \param cfo_std_dev carrier frequnecy drift process standard deviation per sample in Hz + * \param cfo_max_dev maximum carrier frequency offset in Hz + + * \param N number of sinusoids used in frequency selective fading simulation + * \param doppler_freq maximum doppler frequency used in fading simulation in Hz + * \param LOS_model defines whether the fading model should include a line of site + component. LOS->Rician, NLOS->Rayleigh + * \param K Rician K-factor, the ratio of specular to diffuse power in the model + * \param delays A list of fractional sample delays making up the power delay profile + * \param mags A list of magnitudes corresponding to each delay time in the power delay profile + * \param ntaps_mpath The length of the filter to interpolate the power delay profile over. + Delays in the PDP must lie between 0 and ntaps_mpath, fractional delays + will be sinc-interpolated only to the width of this filter. + * \param noise_amp Specifies the standard deviation of the AWGN process + * \param noise_seed A random number generator seed for the noise source. + */ + static sptr make( + double samp_rate, + double sro_std_dev, + double sro_max_dev, + double cfo_std_dev, + double cfo_max_dev, + unsigned int N, + double doppler_freq, + bool LOS_model, + float K, + std::vector<float> delays, + std::vector<float> mags, + int ntaps_mpath, + double noise_amp, + double noise_seed ); + + }; + + } /* namespace channels */ +} /* namespace gr */ + +#endif /* INCLUDED_CHANNELS_CHANNEL_MODEL_H */ diff --git a/gr-channels/include/gnuradio/channels/sro_model.h b/gr-channels/include/gnuradio/channels/sro_model.h new file mode 100644 index 0000000000..7eadc5a796 --- /dev/null +++ b/gr-channels/include/gnuradio/channels/sro_model.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009,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_CHANNELS_SRO_MODEL_H +#define INCLUDED_CHANNELS_SRO_MODEL_H + +#include <gnuradio/channels/api.h> +#include <gnuradio/block.h> +#include <gnuradio/types.h> + +namespace gr { + namespace channels { + + /*! + * \brief Sample Rate Offset Model + * \ingroup channel_models_blk + * + * \details + * This block implements a model that varies sample rate offset + * with respect to time by performing a random walk on the + * interpolation rate. + */ + class CHANNELS_API sro_model : virtual public block + { + public: + // gr::channels::sro_model::sptr + typedef boost::shared_ptr<sro_model> sptr; + + /*! \brief Build the sample rate offset model + * + * \param sample_rate_hz Sample rate of the input signal in Hz + * \param std_dev_hz Desired standard deviation of the random walk + process every sample in Hz + * \param max_dev_hz Maximum sample rate deviation from zero in Hz. + * \param noise_seed A random number generator seed for the noise source. + */ + static sptr make( + double sample_rate_hz, + double std_dev_hz, + double max_dev_hz, + double noise_seed=0); + + }; + + } /* namespace channels */ +} /* namespace gr */ + +#endif /* INCLUDED_CHANNELS_SRO_MODEL_H */ diff --git a/gr-channels/lib/CMakeLists.txt b/gr-channels/lib/CMakeLists.txt index f429fae0fc..46bb38b270 100644 --- a/gr-channels/lib/CMakeLists.txt +++ b/gr-channels/lib/CMakeLists.txt @@ -44,9 +44,12 @@ endif(ENABLE_GR_CTRLPORT) list(APPEND channels_sources channel_model_impl.cc channel_model2_impl.cc + dynamic_channel_model_impl.cc fading_model_impl.cc selective_fading_model_impl.cc flat_fader_impl.cc + cfo_model_impl.cc + sro_model_impl.cc ) #Add Windows DLL resource file if using MSVC diff --git a/gr-channels/lib/cfo_model_impl.cc b/gr-channels/lib/cfo_model_impl.cc new file mode 100644 index 0000000000..dc4f829dc0 --- /dev/null +++ b/gr-channels/lib/cfo_model_impl.cc @@ -0,0 +1,108 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009,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. + */ + +#include "cfo_model_impl.h" +#include <gnuradio/io_signature.h> +#include <iostream> + +namespace gr { + namespace channels { + + cfo_model::sptr + cfo_model::make( + double sample_rate_hz, + double std_dev_hz, + double max_dev_hz, + double noise_seed ) + { + return gnuradio::get_initial_sptr + (new cfo_model_impl(sample_rate_hz, + std_dev_hz, + max_dev_hz, + noise_seed)); + } + + cfo_model_impl::cfo_model_impl( + double sample_rate_hz, + double std_dev_hz, + double max_dev_hz, + double noise_seed) + : sync_block("cfo_model", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(gr_complex))), + d_samp_rate(sample_rate_hz), + d_max_dev_hz(max_dev_hz), + d_table(8*1024), + d_noise(gr::analog::fastnoise_source_f::make(analog::GR_GAUSSIAN, std_dev_hz, noise_seed)), + d_cfo(0), + d_angle(0) + { + } + + cfo_model_impl::~cfo_model_impl() + { + } + + int cfo_model_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]; + for(size_t i=0; i<noutput_items; i++){ + // update and bound cfo + // we multiply by a random {1,-1} to remove any sign + // bias that may exist in our random sample pool + d_cfo += d_noise->sample_unbiased(); + d_cfo = std::min( d_cfo, d_max_dev_hz ); + d_cfo = std::max( d_cfo, -d_max_dev_hz ); + // update and wrap angle + d_angle += 2*M_PI*d_cfo/d_samp_rate; + d_angle = d_angle > 2*M_PI ? d_angle - 2*M_PI : d_angle; + d_angle = d_angle < -2*M_PI ? d_angle + 2*M_PI : d_angle; + out[i] = in[i] * gr_complex(d_table.cos(d_angle), d_table.sin(d_angle)); + } + return noutput_items; + + } + + void + cfo_model_impl::setup_rpc() + { +#ifdef GR_CTRLPORT + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_variable<double>( + alias(), "cfo", &d_cfo, + pmt::mp(-10.0f), pmt::mp(10.0f), pmt::mp(0.0f), + "", "Current CFO in Hz", RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_variable<double>( + alias(), "cfo_max", &d_max_dev_hz, + pmt::mp(-10.0f), pmt::mp(10.0f), pmt::mp(0.0f), + "", "Max CFO in Hz", RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); +#endif /* GR_CTRLPORT */ + } + + } /* namespace channels */ +} /* namespace gr */ diff --git a/gr-channels/lib/cfo_model_impl.h b/gr-channels/lib/cfo_model_impl.h new file mode 100644 index 0000000000..672de6308f --- /dev/null +++ b/gr-channels/lib/cfo_model_impl.h @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009,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_CHANNELS_CFO_MODEL_IMPL_H +#define INCLUDED_CHANNELS_CFO_MODEL_IMPL_H + +#include <gnuradio/top_block.h> +#include <gnuradio/blocks/integrate_ff.h> +#include <gnuradio/blocks/vco_c.h> +#include <gnuradio/blocks/multiply_cc.h> +#include <gnuradio/analog/fastnoise_source_f.h> +#include <gnuradio/channels/cfo_model.h> +#include <sincostable.h> + +namespace gr { + namespace channels { + + class CHANNELS_API cfo_model_impl : public cfo_model + { + private: + double d_samp_rate; + double d_std_dev_hz; + double d_max_dev_hz; + sincostable d_table; + gr::analog::fastnoise_source_f::sptr d_noise; + double d_cfo; + float d_angle; + + public: + cfo_model_impl( + double sample_rate_hz, + double std_dev_hz, + double max_dev_hz, + double noise_seed=0 ); + + ~cfo_model_impl(); + void setup_rpc(); + int work(int, gr_vector_const_void_star&, gr_vector_void_star&); + }; + + } /* namespace channels */ +} /* namespace gr */ + +#endif /* INCLUDED_CHANNELS_CFO_MODEL_IMPL_H */ diff --git a/gr-channels/lib/dynamic_channel_model_impl.cc b/gr-channels/lib/dynamic_channel_model_impl.cc new file mode 100644 index 0000000000..7c2044570a --- /dev/null +++ b/gr-channels/lib/dynamic_channel_model_impl.cc @@ -0,0 +1,101 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009,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. + */ + +#include "dynamic_channel_model_impl.h" +#include <gnuradio/io_signature.h> +#include <iostream> + +namespace gr { + namespace channels { + + dynamic_channel_model::sptr + dynamic_channel_model::make( + double samp_rate, + double sro_std_dev, + double sro_max_dev, + double cfo_std_dev, + double cfo_max_dev, + unsigned int N, + double doppler_freq, + bool LOS_model, + float K, + std::vector<float> delays, + std::vector<float> mags, + int ntaps_mpath, + double noise_amp, + double noise_seed +) + { + return gnuradio::get_initial_sptr + (new dynamic_channel_model_impl( + samp_rate, sro_std_dev, sro_max_dev, cfo_std_dev, cfo_max_dev, + N, doppler_freq, LOS_model, K, delays, mags, ntaps_mpath, noise_amp, noise_seed)); + } + + // Hierarchical block constructor + dynamic_channel_model_impl::dynamic_channel_model_impl( + double samp_rate, + double sro_std_dev, + double sro_max_dev, + double cfo_std_dev, + double cfo_max_dev, + unsigned int N, + double doppler_freq, + bool LOS_model, + float K, + std::vector<float> delays, + std::vector<float> mags, + int ntaps_mpath, + double noise_amp, + double noise_seed) + : hier_block2("dynamic_channel_model", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(gr_complex))) + { + d_noise_adder = blocks::add_cc::make(); + d_noise = analog::fastnoise_source_c::make(analog::GR_GAUSSIAN, + noise_amp, noise_seed, 1024*8); + d_sro_model = channels::sro_model::make(samp_rate, sro_std_dev, sro_max_dev, noise_seed); + d_cfo_model = channels::cfo_model::make(samp_rate, cfo_std_dev, cfo_max_dev, noise_seed); + d_fader = channels::selective_fading_model::make(N, doppler_freq / samp_rate, LOS_model, K, noise_seed, delays, mags, ntaps_mpath); + + connect(self(), 0, d_sro_model, 0); + connect(d_sro_model, 0, d_cfo_model, 0); + connect(d_cfo_model, 0, d_fader, 0); + connect(d_fader, 0, d_noise_adder, 1); + connect(d_noise, 0, d_noise_adder, 0); + connect(d_noise_adder, 0, self(), 0); + } + + dynamic_channel_model_impl::~dynamic_channel_model_impl() + { + } + + void + dynamic_channel_model_impl::setup_rpc() + { +#ifdef GR_CTRLPORT +#endif /* GR_CTRLPORT */ + } + + } /* namespace channels */ +} /* namespace gr */ diff --git a/gr-channels/lib/dynamic_channel_model_impl.h b/gr-channels/lib/dynamic_channel_model_impl.h new file mode 100644 index 0000000000..b2651d28eb --- /dev/null +++ b/gr-channels/lib/dynamic_channel_model_impl.h @@ -0,0 +1,76 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009,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_CHANNELS_CHANNEL_MODEL_IMPL_H +#define INCLUDED_CHANNELS_CHANNEL_MODEL_IMPL_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/channels/dynamic_channel_model.h> +#include <gnuradio/channels/selective_fading_model.h> +#include <gnuradio/channels/sro_model.h> +#include <gnuradio/channels/cfo_model.h> +#include <gnuradio/filter/fractional_resampler_cc.h> +#include <gnuradio/filter/fir_filter_ccc.h> + +namespace gr { + namespace channels { + + class CHANNELS_API dynamic_channel_model_impl : public dynamic_channel_model + { + private: + + channels::sro_model::sptr d_sro_model; + channels::cfo_model::sptr d_cfo_model; + channels::selective_fading_model::sptr d_fader; + blocks::add_cc::sptr d_noise_adder; + analog::fastnoise_source_c::sptr d_noise; + + public: + dynamic_channel_model_impl( double samp_rate, + double sro_std_dev, + double sro_max_dev, + double cfo_std_dev, + double cfo_max_dev, + unsigned int N, + double doppler_freq, + bool LOS_model, + float K, + std::vector<float> delays, + std::vector<float> mags, + int ntaps_mpath, + double noise_amp, + double noise_seed); + + ~dynamic_channel_model_impl(); + + void setup_rpc(); + + }; + + } /* namespace channels */ +} /* namespace gr */ + +#endif /* INCLUDED_CHANNELS_CHANNEL_MODEL_IMPL_H */ diff --git a/gr-channels/lib/sro_model_impl.cc b/gr-channels/lib/sro_model_impl.cc new file mode 100644 index 0000000000..508fa4e2a8 --- /dev/null +++ b/gr-channels/lib/sro_model_impl.cc @@ -0,0 +1,156 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gnuradio/io_signature.h> +#include "sro_model_impl.h" +#include <stdexcept> + +namespace gr { + namespace channels { + + sro_model::sptr + sro_model::make( + double sample_rate_hz, + double std_dev_hz, + double max_dev_hz, + double noise_seed) + { + return gnuradio::get_initial_sptr( + new sro_model_impl(sample_rate_hz, std_dev_hz, max_dev_hz, noise_seed)); + } + + sro_model_impl::sro_model_impl( + double sample_rate_hz, + double std_dev_hz, + double max_dev_hz, + double noise_seed) + : block("sro_model", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(gr_complex))), + d_mu (0.0), d_mu_inc (1.0), d_sro(0.0), d_samp_rate(sample_rate_hz), + d_max_dev_hz(max_dev_hz), + d_interp(new gr::filter::mmse_fir_interpolator_cc()), + d_noise(gr::analog::fastnoise_source_f::make(analog::GR_GAUSSIAN, std_dev_hz, noise_seed)) + { + //set_relative_rate(1.0 / interp_ratio); + set_relative_rate(1.0); + } + + sro_model_impl::~sro_model_impl() + { + delete d_interp; + } + + void + sro_model_impl::forecast(int noutput_items, + gr_vector_int &ninput_items_required) + { + unsigned ninputs = ninput_items_required.size(); + for(unsigned i=0; i < ninputs; i++) { + ninput_items_required[i] = + (int)ceil((noutput_items * (d_mu_inc + d_max_dev_hz/d_samp_rate)) + d_interp->ntaps()); + } + } + + int + sro_model_impl::general_work(int noutput_items, + gr_vector_int &ninput_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]; + + int ii = 0; // input index + int oo = 0; // output index + + while(oo < noutput_items) { + + // perform sample rate offset update + d_sro += d_noise->sample_unbiased(); + d_sro = std::min(d_sro, d_max_dev_hz); + d_sro = std::max(d_sro, -d_max_dev_hz); + d_mu_inc = 1.0 + d_sro/d_samp_rate; + + out[oo++] = d_interp->interpolate(&in[ii], d_mu); + + double s = d_mu + d_mu_inc; + double f = floor(s); + int incr = (int)f; + d_mu = s - f; + ii += incr; + } + + consume_each(ii); + + return noutput_items; + } + + float + sro_model_impl::mu() const + { + return d_mu; + } + + float + sro_model_impl::interp_ratio() const + { + return d_mu_inc; + } + + void + sro_model_impl::set_mu(float mu) + { + d_mu = mu; + } + + void + sro_model_impl::set_interp_ratio(float interp_ratio) + { + d_mu_inc = interp_ratio; + } + + void + sro_model_impl::setup_rpc() + { +#ifdef GR_CTRLPORT + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_variable<float>( + alias(), "sro", &d_sro, + pmt::mp(-10.0f), pmt::mp(10.0f), pmt::mp(0.0f), + "", "Current SRO in Hz", RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_variable<float>( + alias(), "sro_max", &d_max_dev_hz, + pmt::mp(-10.0f), pmt::mp(10.0f), pmt::mp(0.0f), + "", "Max SRO in Hz", RPC_PRIVLVL_MIN, + DISPTIME | DISPOPTSTRIP))); +#endif /* GR_CTRLPORT */ + } + + } /* namespace filter */ +} /* namespace gr */ diff --git a/gr-channels/lib/sro_model_impl.h b/gr-channels/lib/sro_model_impl.h new file mode 100644 index 0000000000..7c72dac6a6 --- /dev/null +++ b/gr-channels/lib/sro_model_impl.h @@ -0,0 +1,72 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2007,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_CHANNELS_SRO_MODEL_CC_IMPL_H +#define INCLUDED_CHANNELS_SRO_MODEL_CC_IMPL_H + +#include <gnuradio/filter/fractional_interpolator_cc.h> +#include <gnuradio/filter/mmse_fir_interpolator_cc.h> +#include <gnuradio/analog/fastnoise_source_f.h> +#include <gnuradio/channels/sro_model.h> + +namespace gr { + namespace channels { + + class CHANNELS_API sro_model_impl + : public sro_model + { + private: + float d_mu; + float d_mu_inc; + float d_sro; + float d_samp_rate; + float d_max_dev_hz; + gr::filter::mmse_fir_interpolator_cc *d_interp; + gr::analog::fastnoise_source_f::sptr d_noise; + + public: + sro_model_impl( + double sample_rate_hz, + double std_dev_hz, + double max_dev_hz, + double noise_seed=0); + ~sro_model_impl(); + + void forecast(int noutput_items, + gr_vector_int &ninput_items_required); + int general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + float mu() const; + float interp_ratio() const; + void set_mu(float mu); + void set_interp_ratio(float interp_ratio); + void setup_rpc(); + + }; + + } /* namespace filter */ +} /* namespace gr */ + +#endif diff --git a/gr-channels/swig/channels_swig.i b/gr-channels/swig/channels_swig.i index 784a10a085..0a13d9cde0 100644 --- a/gr-channels/swig/channels_swig.i +++ b/gr-channels/swig/channels_swig.i @@ -30,16 +30,25 @@ %{ #include "gnuradio/channels/channel_model.h" #include "gnuradio/channels/channel_model2.h" +#include "gnuradio/channels/cfo_model.h" +#include "gnuradio/channels/dynamic_channel_model.h" #include "gnuradio/channels/fading_model.h" #include "gnuradio/channels/selective_fading_model.h" +#include "gnuradio/channels/sro_model.h" %} %include "gnuradio/channels/channel_model.h" %include "gnuradio/channels/channel_model2.h" +%include "gnuradio/channels/cfo_model.h" +%include "gnuradio/channels/dynamic_channel_model.h" %include "gnuradio/channels/fading_model.h" %include "gnuradio/channels/selective_fading_model.h" +%include "gnuradio/channels/sro_model.h" GR_SWIG_BLOCK_MAGIC2(channels, channel_model); GR_SWIG_BLOCK_MAGIC2(channels, channel_model2); +GR_SWIG_BLOCK_MAGIC2(channels, cfo_model); +GR_SWIG_BLOCK_MAGIC2(channels, dynamic_channel_model); GR_SWIG_BLOCK_MAGIC2(channels, fading_model); GR_SWIG_BLOCK_MAGIC2(channels, selective_fading_model); +GR_SWIG_BLOCK_MAGIC2(channels, sro_model); diff --git a/grc/base/Block.py b/grc/base/Block.py index 970cf516fe..668675c685 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -154,6 +154,16 @@ class Block(Element): 'value': '0' }) )) + self.get_params().append(self.get_parent().get_parent().Param( + block=self, + n=odict({'name': 'Max Output Buffer', + 'key': 'maxoutbuf', + 'type': 'int', + 'hide': 'part', + 'value': '0' + }) + )) + def back_ofthe_bus(self, portlist): portlist.sort(key=lambda a: a.get_type() == 'bus'); diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl index 5daf80f685..cf13317d1d 100644 --- a/grc/python/flow_graph.tmpl +++ b/grc/python/flow_graph.tmpl @@ -167,6 +167,9 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))]) #if (len($blk.get_sources())>0) and $blk.has_param('minoutbuf') and (int($blk.get_param('minoutbuf').get_evaluated()) > 0) (self.$blk.get_id()).set_min_output_buffer($blk.get_param('minoutbuf').get_evaluated()) #end if + #if (len($blk.get_sources())>0) and $blk.has_param('maxoutbuf') and (int($blk.get_param('maxoutbuf').get_evaluated()) > 0) + (self.$blk.get_id()).set_max_output_buffer($blk.get_param('maxoutbuf').get_evaluated()) + #end if #end if #end for ######################################################## |