diff options
author | Tim O'Shea <tim.oshea753@gmail.com> | 2013-09-19 11:59:47 -0400 |
---|---|---|
committer | Tim O'Shea <tim.oshea753@gmail.com> | 2013-11-07 01:10:46 -0500 |
commit | d9168b34dbc1aeeda7077ede8c9534fabb1e7518 (patch) | |
tree | fa3812f3184aad6a684989e463f4d06dadd1e54c | |
parent | 5f724cfd76ad52288db91b535b4366c176717d29 (diff) |
Adding models for sample rate and center frequency drift
Adding hier block "dynamic channel" model which combines these with AWGN and frequency selective fading
-rw-r--r-- | gr-analog/include/gnuradio/analog/fastnoise_source_X.h.t | 2 | ||||
-rw-r--r-- | gr-analog/lib/fastnoise_source_X_impl.cc.t | 30 | ||||
-rw-r--r-- | gr-analog/lib/fastnoise_source_X_impl.h.t | 3 | ||||
-rw-r--r-- | gr-channels/grc/channels_cfo_model.xml | 49 | ||||
-rw-r--r-- | gr-channels/grc/channels_dynamic_channel_model.xml | 149 | ||||
-rw-r--r-- | gr-channels/grc/channels_sro_model.xml | 49 | ||||
-rw-r--r-- | gr-channels/include/gnuradio/channels/cfo_model.h | 65 | ||||
-rw-r--r-- | gr-channels/include/gnuradio/channels/dynamic_channel_model.h | 89 | ||||
-rw-r--r-- | gr-channels/include/gnuradio/channels/sro_model.h | 59 | ||||
-rw-r--r-- | gr-channels/lib/CMakeLists.txt | 3 | ||||
-rw-r--r-- | gr-channels/lib/cfo_model_impl.cc | 108 | ||||
-rw-r--r-- | gr-channels/lib/cfo_model_impl.h | 63 | ||||
-rw-r--r-- | gr-channels/lib/dynamic_channel_model_impl.cc | 101 | ||||
-rw-r--r-- | gr-channels/lib/dynamic_channel_model_impl.h | 76 | ||||
-rw-r--r-- | gr-channels/lib/sro_model_impl.cc | 156 | ||||
-rw-r--r-- | gr-channels/lib/sro_model_impl.h | 72 | ||||
-rw-r--r-- | gr-channels/swig/channels_swig.i | 9 |
17 files changed, 1078 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_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..b87b40da11 --- /dev/null +++ b/gr-channels/grc/channels_dynamic_channel_model.xml @@ -0,0 +1,149 @@ +<?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> + int d_N=8; // number of sinusoids used to simulate gain on each ray + float d_fDTs=0.01 // normalized maximum doppler frequency (f_doppler / f_samprate) + float d_K=4; // Rician factor (ratio of the specular power to the scattered power) + bool d_LOS=true; // LOS path exists? chooses Rician (LOS) vs Rayleigh (NLOS) model. + int seed=0; // noise seed + int ntaps; // Number of FIR taps to use in selective fading model + + These two vectors comprise the Power Delay Profile of the signal + float_vector delays // Time delay in the fir filter (in samples) for each arriving WSSUS Ray + float_vector mags // Magnitude corresponding to each WSSUS Ray + + If using a LOS model, the first delay and mag should correspond with the LOS component + + References: + + The flat-fading portion of the algorithm implements the following + Compact Rayleigh and Rician fading simulator based on random walk processes + A. Alimohammad S.F. Fard B.F. Cockburn C. Schlegel + 26th November 2008 + + The frequency selective extension of the block roughly implements + A Low-Complexity Hardware Implementation of Discrete-Time + Frequency-Selective Rayleigh Fading Channels + F. Ren and Y. Zheng + 24-27 May 2009 + + Implementation by Tim O'Shea + </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..8ebf54ab3f --- /dev/null +++ b/gr-channels/include/gnuradio/channels/cfo_model.h @@ -0,0 +1,65 @@ +/* -*- 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 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, a (normalized) frequency + * offset, a sample 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.. + */ + class CHANNELS_API cfo_model : virtual public sync_block + { + public: + // gr::channels::cfo_model::sptr + typedef boost::shared_ptr<cfo_model> sptr; + + 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..0223b14962 --- /dev/null +++ b/gr-channels/include/gnuradio/channels/dynamic_channel_model.h @@ -0,0 +1,89 @@ +/* -*- 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 channel simulator + * \ingroup dynamic_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, a (normalized) frequency + * offset, a sample 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.. + */ + 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 channel simulator. + * + * \param noise_voltage The AWGN noise level as a voltage (to be + * calculated externally to meet, say, a + * desired SNR). + * \param frequency_offset The normalized frequency offset. 0 is + * no offset; 0.25 would be, for a digital + * modem, one quarter of the symbol rate. + * \param epsilon The 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 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..68eaabee83 --- /dev/null +++ b/gr-channels/include/gnuradio/channels/sro_model.h @@ -0,0 +1,59 @@ +/* -*- 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 varries 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; + + 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..d07a0f9454 --- /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, + 1.0, 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); |