diff options
author | Tim O'Shea <tim.oshea753@gmail.com> | 2016-03-27 15:30:00 -0400 |
---|---|---|
committer | Tim O'Shea <tim.oshea753@gmail.com> | 2016-06-04 10:05:55 -0400 |
commit | 782d4bde300556eff59378eae3d587f6ce476267 (patch) | |
tree | 3f0a6539b3061591928b93b34bb013d81b27ceab | |
parent | 5fb584806c62b4c4a441068ae8b8d5fad3703deb (diff) |
channels: adding selective fading model 2 (PDP slowly changes without bounds as well so fades move ...)
-rw-r--r-- | gr-channels/grc/channels_block_tree.xml | 1 | ||||
-rw-r--r-- | gr-channels/grc/channels_selective_fading_model2.xml | 123 | ||||
-rw-r--r-- | gr-channels/include/gnuradio/channels/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-channels/include/gnuradio/channels/selective_fading_model2.h | 90 | ||||
-rw-r--r-- | gr-channels/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-channels/lib/flat_fader_impl.h | 2 | ||||
-rw-r--r-- | gr-channels/lib/selective_fading_model2_impl.cc | 195 | ||||
-rw-r--r-- | gr-channels/lib/selective_fading_model2_impl.h | 87 | ||||
-rw-r--r-- | gr-channels/swig/channels_swig.i | 3 |
9 files changed, 502 insertions, 1 deletions
diff --git a/gr-channels/grc/channels_block_tree.xml b/gr-channels/grc/channels_block_tree.xml index 00886e8eed..80aabaf478 100644 --- a/gr-channels/grc/channels_block_tree.xml +++ b/gr-channels/grc/channels_block_tree.xml @@ -36,6 +36,7 @@ <block>channels_fading_model</block> <block>channels_dynamic_channel_model</block> <block>channels_selective_fading_model</block> + <block>channels_selective_fading_model2</block> </cat> <cat> <name>Impairment Models</name> diff --git a/gr-channels/grc/channels_selective_fading_model2.xml b/gr-channels/grc/channels_selective_fading_model2.xml new file mode 100644 index 0000000000..7df09a7aab --- /dev/null +++ b/gr-channels/grc/channels_selective_fading_model2.xml @@ -0,0 +1,123 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Frequency Selective Fading Model +################################################### + --> +<block> + <name>Frequency Selective Fading Model2</name> + <key>channels_selective_fading_model2</key> + <import>from gnuradio import channels</import> + <make>channels.selective_fading_model2( $N, $fDTs, $LOS, $K, $seed, $delays, $delay_std, $delay_maxdev, $mags, $ntaps )</make> + <callback>set_fDTs($fDTs)</callback> + <callback>set_K($K)</callback> + <param> + <name>Num Sinusoids (Stochastic SoS model + delay drift)</name> + <key>N</key> + <value>8</value> + <type>int</type> + </param> + <param> + <name>Normalized Max Doppler (fD*Ts)</name> + <key>fDTs</key> + <value>0.2/samp_rate</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 (in samps)</name> + <key>delays</key> + <value>1.0,1.9,2.7</value> + <type>real_vector</type> + </param> + <param> + <name>PDP Delay StdDev (per samp)</name> + <key>delay_std</key> + <value>1e-4,1e-4,1e-4</value> + <type>real_vector</type> + </param> + <param> + <name>PDP Delay Max-Dev (per samp)</name> + <key>delay_maxdev</key> + <value>0.5,0.7,0.9</value> + <type>real_vector</type> + </param> + <param> + <name>PDP Magnitudes</name> + <key>mags</key> + <value>1,0.95,0.8</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 + (Alogrithm III) + ( with a novel addition of time delay tap random walk ) + + 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/include/gnuradio/channels/CMakeLists.txt b/gr-channels/include/gnuradio/channels/CMakeLists.txt index cb618a7e8d..6fac10e306 100644 --- a/gr-channels/include/gnuradio/channels/CMakeLists.txt +++ b/gr-channels/include/gnuradio/channels/CMakeLists.txt @@ -26,6 +26,7 @@ install(FILES channel_model2.h fading_model.h selective_fading_model.h + selective_fading_model2.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio/channels COMPONENT "channels_devel" ) diff --git a/gr-channels/include/gnuradio/channels/selective_fading_model2.h b/gr-channels/include/gnuradio/channels/selective_fading_model2.h new file mode 100644 index 0000000000..cc838b672c --- /dev/null +++ b/gr-channels/include/gnuradio/channels/selective_fading_model2.h @@ -0,0 +1,90 @@ +/* -*- 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. + */ + +#ifndef INCLUDED_CHANNELS_SELECTIVE_FADING_MODEL2_H +#define INCLUDED_CHANNELS_SELECTIVE_FADING_MODEL2_H + +#include <gnuradio/channels/api.h> +#include <gnuradio/sync_block.h> +#include <gnuradio/types.h> + +namespace gr { + namespace channels { + + const float default_delays2[] = {1.0,1.9,2.7}; + const float default_mags2[] = {1.0,0.95,0.8}; + + /*! + * \brief fading simulator + * \ingroup channel_models_blk + * + * \details + * This block implements a basic fading model simulator that can + * be used to help evaluate, design, and test various signals, + * waveforms, and algorithms. + */ + class CHANNELS_API selective_fading_model2 : virtual public sync_block + { + public: + // gr::channels::channel_model2::sptr + typedef boost::shared_ptr<selective_fading_model2> sptr; + + /*! \brief Build the channel simulator. + * + * \param N the number of sinusoids to use in simulating the channel; 8 is a good value + * \param fDTs normalized maximum Doppler frequency, fD * Ts + * \param LOS include Line-of-Site path? selects between Rayleigh (NLOS) and Rician (LOS) models + * \param K Rician factor (ratio of the specular power to the scattered power) + * \param seed a random number to seed the noise generators + * \param delays a vector of values that specify the time delay of each impulse + * \param delay_std a vector of values that specify the gaussian step size std of delays + * \param delay_maxdev a vector of values that specify the max deviation of each delay component + * \param mags a vector of values that specify the magnitude of each impulse + * \param mags a vector of values that specify the magnitude of each impulse + * \param ntaps the number of filter taps + */ + static sptr make(unsigned int N, + float fDTs, + bool LOS, + float K, + int seed, + std::vector<float> delays, + std::vector<float> delay_std, + std::vector<float> delay_maxdev, + std::vector<float> mags, + int ntaps + ); + + virtual float fDTs() = 0; + virtual float K() = 0; + virtual float step() = 0; + + virtual void set_fDTs(float fDTs) = 0; + virtual void set_K(float K) = 0; + virtual void set_step(float step) = 0; + + }; + + } /* namespace channels */ +} /* namespace gr */ + +#endif /* INCLUDED_CHANNELS_SELECTIVE_FADING_MODEL2_H */ diff --git a/gr-channels/lib/CMakeLists.txt b/gr-channels/lib/CMakeLists.txt index 52b6222b62..34726c1715 100644 --- a/gr-channels/lib/CMakeLists.txt +++ b/gr-channels/lib/CMakeLists.txt @@ -46,6 +46,7 @@ list(APPEND channels_sources dynamic_channel_model_impl.cc fading_model_impl.cc selective_fading_model_impl.cc + selective_fading_model2_impl.cc flat_fader_impl.cc cfo_model_impl.cc sro_model_impl.cc diff --git a/gr-channels/lib/flat_fader_impl.h b/gr-channels/lib/flat_fader_impl.h index 3a086f32d4..fae237278c 100644 --- a/gr-channels/lib/flat_fader_impl.h +++ b/gr-channels/lib/flat_fader_impl.h @@ -48,7 +48,7 @@ namespace gr { // random walk variate boost::mt19937 seed_2; - boost::uniform_real<> dist_2; // U(-pi,pi) + boost::uniform_real<> dist_2; // U(0,1) boost::variate_generator<boost::mt19937&, boost::uniform_real<> > rv_2; public: diff --git a/gr-channels/lib/selective_fading_model2_impl.cc b/gr-channels/lib/selective_fading_model2_impl.cc new file mode 100644 index 0000000000..7ae50418ac --- /dev/null +++ b/gr-channels/lib/selective_fading_model2_impl.cc @@ -0,0 +1,195 @@ +/* -*- 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. + */ + +#include "selective_fading_model2_impl.h" +#include <gnuradio/io_signature.h> +#include <iostream> + +#include <boost/format.hpp> +#include <boost/random.hpp> + +#include <gnuradio/fxpt.h> +#include <sincostable.h> + + +// FASTSINCOS: 0 = slow native, 1 = gr::fxpt impl, 2 = sincostable.h +#define FASTSINCOS 2 + + +namespace gr { + namespace channels { + + selective_fading_model2::sptr + selective_fading_model2::make( unsigned int N, float fDTs, bool LOS, float K, int seed, std::vector<float> delays, + std::vector<float> delays_std, std::vector<float> delays_maxdev, std::vector<float> mags, int ntaps) + { + return gnuradio::get_initial_sptr + (new selective_fading_model2_impl( N, fDTs, LOS, K, seed, delays, delays_std, delays_maxdev, mags, ntaps)); + } + + // Block constructor + selective_fading_model2_impl::selective_fading_model2_impl( unsigned int N, float fDTs, bool LOS, float K, int seed, std::vector<float> delays, + std::vector<float> delays_std, std::vector<float> delays_maxdev, std::vector<float> mags, int ntaps ) + : sync_block("selective_fading_model2", + io_signature::make(1, 1, sizeof(gr_complex)), + io_signature::make(1, 1, sizeof(gr_complex))), + d_delays(delays), + d_delays_orig(delays), + d_delays_std(delays_std), + d_delays_maxdev(delays_maxdev), + d_mags(mags), + d_sintable(1024), + seed_1(0), + dist_1(0,1), + rv_1(seed_1, dist_1) + { + if(mags.size() != delays.size()) + throw std::runtime_error("magnitude and delay vectors must be the same length!"); + if(mags.size() != delays_std.size()) + throw std::runtime_error("delay std dev vector length must be the same length!"); + if(mags.size() != delays_maxdev.size()) + throw std::runtime_error("delay maxdev vector length must be the same length!"); + + for(size_t i=0; i<mags.size(); i++){ + d_faders.push_back(new gr::channels::flat_fader_impl(N, fDTs, (i==0)&&(LOS), K, seed+i)); + } + + // set up tap history + if(ntaps < 1){ throw std::runtime_error("ntaps must be >= 1"); } + set_history(1+ntaps); + d_taps.resize(ntaps, gr_complex(0,0)); + } + + selective_fading_model2_impl::~selective_fading_model2_impl() + { + for(size_t i=0; i<d_faders.size(); i++){ + delete d_faders[i]; + } + } + + int + selective_fading_model2_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]; + + // pregenerate fading components + std::vector<std::vector<gr_complex> > fading_taps; + for(size_t j=0; j<d_faders.size(); j++){ + fading_taps.push_back( std::vector<gr_complex>() ); + d_faders[j]->next_samples(fading_taps[j], noutput_items); + } + + // loop over each output sample + for(int i=0; i<noutput_items; i++){ + + // move the tap delays around (random walk + clipping) + for(size_t j=0; j<d_faders.size(); j++){ + float tmp = d_delays[j] + rv_1()*d_delays_std[j]; + d_delays[j] = std::max(std::min(tmp,d_delays_orig[j]+d_delays_maxdev[j]), d_delays_orig[j]-d_delays_maxdev[j]); + } + + // clear the current values in each tap + for(size_t j=0; j<d_taps.size(); j++){ + d_taps[j] = gr_complex(0,0); + } + + // add each flat fading component to the taps + for(size_t j=0; j<d_faders.size(); j++){ + gr_complex ff_H(fading_taps[j][i]); + //gr_complex ff_H(d_faders[j]->next_sample()); + for(size_t k=0; k<d_taps.size(); k++){ + float dist = k-d_delays[j]; + float interpmag = d_sintable.sinc(2*M_PI*dist); + d_taps[k] += ff_H * interpmag * d_mags[j]; + } + } + + // apply the taps and generate output + gr_complex sum(0,0); + for(size_t j=0; j<d_taps.size(); j++){ + sum += in[i+j] * d_taps[d_taps.size()-j-1]; + } + + // assign output + out[i] = sum; + } + + // return all outputs + return noutput_items; + } + + void + selective_fading_model2_impl::setup_rpc() + { +#ifdef GR_CTRLPORT + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_get<selective_fading_model2, float >( + alias(), "fDTs", + &selective_fading_model2::fDTs, + pmt::mp(0), pmt::mp(1), pmt::mp(0.01), + "Hz*Sec", "normalized maximum doppler frequency (fD*Ts)", + RPC_PRIVLVL_MIN, DISPTIME | DISPOPTSTRIP))); + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_set<selective_fading_model2, float >( + alias(), "fDTs", + &selective_fading_model2::set_fDTs, + pmt::mp(0), pmt::mp(1), pmt::mp(0.01), + "Hz*Sec", "normalized maximum doppler frequency (fD*Ts)", + RPC_PRIVLVL_MIN, DISPTIME | DISPOPTSTRIP))); + + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_get<selective_fading_model2, float >( + alias(), "K", + &selective_fading_model2::K, + pmt::mp(0), pmt::mp(8), pmt::mp(4), + "Ratio", "Rician factor (ratio of the specular power to the scattered power)", + RPC_PRIVLVL_MIN, DISPTIME | DISPOPTSTRIP))); + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_set<selective_fading_model2, float >( + alias(), "K", + &selective_fading_model2::set_K, + pmt::mp(0), pmt::mp(8), pmt::mp(4), + "Ratio", "Rician factor (ratio of the specular power to the scattered power)", + RPC_PRIVLVL_MIN, DISPTIME | DISPOPTSTRIP))); + + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_get<selective_fading_model2, float >( + alias(), "step", + &selective_fading_model2::step, + pmt::mp(0), pmt::mp(8), pmt::mp(4), + "radians", "Maximum step size for random walk angle per sample", + RPC_PRIVLVL_MIN, DISPTIME | DISPOPTSTRIP))); + add_rpc_variable( + rpcbasic_sptr(new rpcbasic_register_set<selective_fading_model2, float >( + alias(), "step", + &selective_fading_model2::set_step, + pmt::mp(0), pmt::mp(1), pmt::mp(0.00001), + "radians", "Maximum step size for random walk angle per sample", + RPC_PRIVLVL_MIN, DISPTIME | DISPOPTSTRIP))); +#endif /* GR_CTRLPORT */ + } + + } /* namespace channels */ +} /* namespace gr */ diff --git a/gr-channels/lib/selective_fading_model2_impl.h b/gr-channels/lib/selective_fading_model2_impl.h new file mode 100644 index 0000000000..eac6adb842 --- /dev/null +++ b/gr-channels/lib/selective_fading_model2_impl.h @@ -0,0 +1,87 @@ +/* -*- 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. + */ + +#ifndef INCLUDED_CHANNELS_SELECTIVE_FADING_MODEL2_IMPL_H +#define INCLUDED_CHANNELS_SELECTIVE_FADING_MODEL2_IMPL_H + +#include <gnuradio/sync_block.h> +#include <gnuradio/channels/selective_fading_model2.h> +#include "flat_fader_impl.h" + +//#include <iostream> +#include <boost/format.hpp> +#include <boost/random.hpp> + +#include <gnuradio/fxpt.h> +#include <sincostable.h> + +namespace gr { + namespace channels { + + class CHANNELS_API selective_fading_model2_impl : public selective_fading_model2 + { + private: + std::vector<gr::channels::flat_fader_impl*> d_faders; + std::vector<float> d_delays; + std::vector<float> d_delays_orig; + std::vector<float> d_delays_std; + std::vector<float> d_delays_maxdev; + std::vector<float> d_mags; + sincostable d_sintable; + + boost::mt19937 seed_1; + boost::normal_distribution<> dist_1; // U(-pi,pi) + boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > rv_1; + + public: + selective_fading_model2_impl(unsigned int N, float fDTs, bool LOS, float K, int seed, std::vector<float> delays, std::vector<float> delay_std, + std::vector<float> delay_maxdev, std::vector<float> mags, int ntaps); + ~selective_fading_model2_impl(); + void setup_rpc(); + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + std::vector<gr_complex> d_taps; + + virtual float fDTs(){ return d_faders[0]->d_fDTs; } + virtual float K(){ return d_faders[0]->d_K; } + virtual float step(){ return d_faders[0]->d_step; } + + virtual void set_fDTs(float fDTs){ + BOOST_FOREACH( gr::channels::flat_fader_impl* fader, d_faders ) + { fader->d_fDTs = fDTs; fader->d_step = powf(0.00125*fDTs, 1.1); } + } + virtual void set_K(float K){ + BOOST_FOREACH( gr::channels::flat_fader_impl* fader, d_faders ) + { fader->d_K = K; fader->scale_los = sqrtf(fader->d_K)/sqrtf(fader->d_K+1); fader->scale_nlos = (1/sqrtf(fader->d_K+1)); } + } + virtual void set_step(float step){ + BOOST_FOREACH( gr::channels::flat_fader_impl* fader, d_faders ) + { fader->d_step = step; } + } + + }; + + } /* namespace channels */ +} /* namespace gr */ + +#endif /* INCLUDED_CHANNELS_SELECTIVE_FADING_MODEL2_IMPL_H */ diff --git a/gr-channels/swig/channels_swig.i b/gr-channels/swig/channels_swig.i index 0a13d9cde0..c80011c345 100644 --- a/gr-channels/swig/channels_swig.i +++ b/gr-channels/swig/channels_swig.i @@ -34,6 +34,7 @@ #include "gnuradio/channels/dynamic_channel_model.h" #include "gnuradio/channels/fading_model.h" #include "gnuradio/channels/selective_fading_model.h" +#include "gnuradio/channels/selective_fading_model2.h" #include "gnuradio/channels/sro_model.h" %} @@ -43,6 +44,7 @@ %include "gnuradio/channels/dynamic_channel_model.h" %include "gnuradio/channels/fading_model.h" %include "gnuradio/channels/selective_fading_model.h" +%include "gnuradio/channels/selective_fading_model2.h" %include "gnuradio/channels/sro_model.h" GR_SWIG_BLOCK_MAGIC2(channels, channel_model); @@ -51,4 +53,5 @@ 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, selective_fading_model2); GR_SWIG_BLOCK_MAGIC2(channels, sro_model); |