From d8d8e992e3f94792fefa74c61d32494903f77dfb Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 19 Jun 2012 22:22:06 -0400 Subject: filter: added channel_model block with GRC. Dummy QA test needs work. More documentation. --- gr-filter/grc/CMakeLists.txt | 1 + gr-filter/grc/channel_model.xml | 61 ++++++++++++++ gr-filter/grc/filter_block_tree.xml | 1 + gr-filter/include/filter/CMakeLists.txt | 1 + gr-filter/include/filter/channel_model.h | 63 +++++++++++++++ gr-filter/lib/CMakeLists.txt | 1 + gr-filter/lib/channel_model_impl.cc | 135 +++++++++++++++++++++++++++++++ gr-filter/lib/channel_model_impl.h | 74 +++++++++++++++++ gr-filter/python/qa_channel_model.py | 43 ++++++++++ gr-filter/swig/filter_swig.i | 3 + 10 files changed, 383 insertions(+) create mode 100644 gr-filter/grc/channel_model.xml create mode 100644 gr-filter/include/filter/channel_model.h create mode 100644 gr-filter/lib/channel_model_impl.cc create mode 100644 gr-filter/lib/channel_model_impl.h create mode 100755 gr-filter/python/qa_channel_model.py diff --git a/gr-filter/grc/CMakeLists.txt b/gr-filter/grc/CMakeLists.txt index 8bbb4c9e0..2e3fef4f0 100644 --- a/gr-filter/grc/CMakeLists.txt +++ b/gr-filter/grc/CMakeLists.txt @@ -35,6 +35,7 @@ install(FILES pfb_synthesizer.xml rational_resampler_base_xxx.xml single_pole_iir_filter_xx.xml + channel_model.xml DESTINATION ${GRC_BLOCKS_DIR} COMPONENT "filter_python" ) diff --git a/gr-filter/grc/channel_model.xml b/gr-filter/grc/channel_model.xml new file mode 100644 index 000000000..6d780974a --- /dev/null +++ b/gr-filter/grc/channel_model.xml @@ -0,0 +1,61 @@ + + + + Channel Model + channel_model + from gnuradio import filter + from gnuradio.filter import firdes + filter.channel_model( + noise_voltage=$noise_voltage, + frequency_offset=$freq_offset, + epsilon=$epsilon, + taps=$taps, + noise_seed=$seed, +) + set_noise_voltage($noise_voltage) + set_frequency_offset($freq_offset) + set_taps($taps) + set_timing_offset($epsilon) + + Noise Voltage + noise_voltage + 0.0 + real + + + Frequency Offset + freq_offset + 0.0 + real + + + Epsilon + epsilon + 1.0 + real + + + Taps + taps + 1.0 + 1.0j + complex_vector + + + Seed + seed + 0 + int + + + in + complex + + + out + complex + + diff --git a/gr-filter/grc/filter_block_tree.xml b/gr-filter/grc/filter_block_tree.xml index b16966eae..711ce4059 100644 --- a/gr-filter/grc/filter_block_tree.xml +++ b/gr-filter/grc/filter_block_tree.xml @@ -46,5 +46,6 @@ pfb_synthesizer_ccf rational_resampler_base_xxx single_pole_iir_filter_xx + channel_model diff --git a/gr-filter/include/filter/CMakeLists.txt b/gr-filter/include/filter/CMakeLists.txt index b30a1fc76..c6bf109cd 100644 --- a/gr-filter/include/filter/CMakeLists.txt +++ b/gr-filter/include/filter/CMakeLists.txt @@ -109,6 +109,7 @@ install(FILES pfb_synthesizer_ccf.h single_pole_iir_filter_cc.h single_pole_iir_filter_ff.h + channel_model.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio/filter COMPONENT "filter_devel" ) diff --git a/gr-filter/include/filter/channel_model.h b/gr-filter/include/filter/channel_model.h new file mode 100644 index 000000000..42b879515 --- /dev/null +++ b/gr-filter/include/filter/channel_model.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_FILTER_CHANNEL_MODEL_H +#define INCLUDED_FILTER_CHANNEL_MODEL_H + +#include +#include +#include + +namespace gr { + namespace filter { + + /*! + * \brief channel simulator + * \ingroup misc_blk + */ + class FILTER_API channel_model : virtual public gr_hier_block2 + { + public: + // gr::filter::channel_model::sptr + typedef boost::shared_ptr sptr; + + static FILTER_API sptr make(double noise_voltage, + double frequency_offset, + double epsilon, + const std::vector &taps, + double noise_seed=0); + + virtual void set_noise_voltage(double noise_voltage) = 0; + virtual void set_frequency_offset(double frequency_offset) = 0; + virtual void set_taps(const std::vector &taps) = 0; + virtual void set_timing_offset(double epsilon) = 0; + + virtual double noise_voltage() const = 0; + virtual double frequency_offset() const = 0; + virtual std::vector taps() const = 0; + virtual double timing_offset() const = 0; + }; + + } /* namespace filter */ +} /* namespace gr */ + +#endif /* INCLUDED_FILTER_CHANNEL_MODEL_H */ diff --git a/gr-filter/lib/CMakeLists.txt b/gr-filter/lib/CMakeLists.txt index e29d69db5..a54cd7b1d 100644 --- a/gr-filter/lib/CMakeLists.txt +++ b/gr-filter/lib/CMakeLists.txt @@ -136,6 +136,7 @@ list(APPEND filter_sources pfb_synthesizer_ccf_impl.cc single_pole_iir_filter_cc_impl.cc single_pole_iir_filter_ff_impl.cc + channel_model_impl.cc ) list(APPEND filter_libs diff --git a/gr-filter/lib/channel_model_impl.cc b/gr-filter/lib/channel_model_impl.cc new file mode 100644 index 000000000..f9e995479 --- /dev/null +++ b/gr-filter/lib/channel_model_impl.cc @@ -0,0 +1,135 @@ +/* -*- 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 "channel_model_impl.h" +#include +#include + +namespace gr { + namespace filter { + + channel_model::sptr + channel_model::make(double noise_voltage, + double frequency_offset, + double epsilon, + const std::vector &taps, + double noise_seed) + { + return gnuradio::get_initial_sptr + (new channel_model_impl(noise_voltage, + frequency_offset, + epsilon, + taps, + noise_seed)); + } + + // Hierarchical block constructor + channel_model_impl::channel_model_impl(double noise_voltage, + double frequency_offset, + double epsilon, + const std::vector &taps, + double noise_seed) + : gr_hier_block2("gr_channel_model", + gr_make_io_signature(1, 1, sizeof(gr_complex)), + gr_make_io_signature(1, 1, sizeof(gr_complex))) + { + d_taps = taps; + while(d_taps.size() < 2) { + d_taps.push_back(0); + } + + d_timing_offset = fractional_interpolator_cc::make(0, epsilon); + + d_multipath = fir_filter_ccc::make(1, d_taps); + + d_noise_adder = gr_make_add_cc(); + d_noise = gr_make_noise_source_c(GR_GAUSSIAN, noise_voltage, noise_seed); + d_freq_offset = gr_make_sig_source_c(1, GR_SIN_WAVE, frequency_offset, 1.0, 0.0); + d_mixer_offset = gr_make_multiply_cc(); + + connect(self(), 0, d_timing_offset, 0); + connect(d_timing_offset, 0, d_multipath, 0); + connect(d_multipath, 0, d_mixer_offset, 0); + connect(d_freq_offset, 0, d_mixer_offset, 1); + connect(d_mixer_offset, 0, d_noise_adder, 1); + connect(d_noise, 0, d_noise_adder, 0); + connect(d_noise_adder, 0, self(), 0); + } + + channel_model_impl::~channel_model_impl() + { + } + + void + channel_model_impl::set_noise_voltage(double noise_voltage) + { + d_noise->set_amplitude(noise_voltage); + } + + void + channel_model_impl::set_frequency_offset(double frequency_offset) + { + d_freq_offset->set_frequency(frequency_offset); + } + + void + channel_model_impl::set_taps(const std::vector &taps) + { + d_taps = taps; + while(d_taps.size() < 2) { + d_taps.push_back(0); + } + d_multipath->set_taps(d_taps); + } + + void + channel_model_impl::set_timing_offset(double epsilon) + { + d_timing_offset->set_interp_ratio(epsilon); + } + + double + channel_model_impl::noise_voltage() const + { + return d_noise->amplitude(); + } + + double + channel_model_impl::frequency_offset() const + { + return d_freq_offset->frequency(); + } + + std::vector + channel_model_impl::taps() const + { + return d_multipath->taps(); + } + + double + channel_model_impl::timing_offset() const + { + return d_timing_offset->interp_ratio(); + } + + } /* namespace filter */ +} /* namespace gr */ diff --git a/gr-filter/lib/channel_model_impl.h b/gr-filter/lib/channel_model_impl.h new file mode 100644 index 000000000..95a63d790 --- /dev/null +++ b/gr-filter/lib/channel_model_impl.h @@ -0,0 +1,74 @@ +/* -*- 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_FILTER_CHANNEL_MODEL_IMPL_H +#define INCLUDED_FILTER_CHANNEL_MODEL_IMPL_H + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace gr { + namespace filter { + + class FILTER_API channel_model_impl : public channel_model + { + private: + gr_sig_source_c_sptr d_freq_offset; + gr_add_cc_sptr d_noise_adder; + gr_noise_source_c_sptr d_noise; + gr_multiply_cc_sptr d_mixer_offset; + + fractional_interpolator_cc::sptr d_timing_offset; + fir_filter_ccc::sptr d_multipath; + + std::vector d_taps; + + public: + channel_model_impl(double noise_voltage, + double frequency_offset, + double epsilon, + const std::vector &taps, + double noise_seed); + + ~channel_model_impl(); + + void set_noise_voltage(double noise_voltage); + void set_frequency_offset(double frequency_offset); + void set_taps(const std::vector &taps); + void set_timing_offset(double epsilon); + + double noise_voltage() const; + double frequency_offset() const; + std::vector taps() const; + double timing_offset() const; + }; + + } /* namespace filter */ +} /* namespace gr */ + +#endif /* INCLUDED_FILTER_CHANNEL_MODEL_IMPL_H */ diff --git a/gr-filter/python/qa_channel_model.py b/gr-filter/python/qa_channel_model.py new file mode 100755 index 000000000..d908f83f7 --- /dev/null +++ b/gr-filter/python/qa_channel_model.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# +# Copyright 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. +# + +from gnuradio import gr, gr_unittest +import filter_swig as filter + +class test_channel_model(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_000_make(self): + op = filter.channel_model(0.0, 0.0, 1.0, [1,], 0) + op.set_noise_voltage(0.0) + op.set_frequency_offset(0.0) + op.set_taps([1,]) + op.set_timing_offset(1.0) + + +if __name__ == '__main__': + gr_unittest.run(test_channel_model, "test_channel_model.xml") diff --git a/gr-filter/swig/filter_swig.i b/gr-filter/swig/filter_swig.i index bb4eab381..05b84d4d6 100644 --- a/gr-filter/swig/filter_swig.i +++ b/gr-filter/swig/filter_swig.i @@ -73,6 +73,7 @@ #include "filter/rational_resampler_base_scc.h" #include "filter/single_pole_iir_filter_cc.h" #include "filter/single_pole_iir_filter_ff.h" +#include "filter/channel_model.h" %} %include "filter/firdes.h" @@ -120,6 +121,7 @@ %include "filter/rational_resampler_base_scc.h" %include "filter/single_pole_iir_filter_cc.h" %include "filter/single_pole_iir_filter_ff.h" +%include "filter/channel_model.h" GR_SWIG_BLOCK_MAGIC2(filter, adaptive_fir_ccc); GR_SWIG_BLOCK_MAGIC2(filter, adaptive_fir_ccf); @@ -164,3 +166,4 @@ GR_SWIG_BLOCK_MAGIC2(filter, rational_resampler_base_fsf); GR_SWIG_BLOCK_MAGIC2(filter, rational_resampler_base_scc); GR_SWIG_BLOCK_MAGIC2(filter, single_pole_iir_filter_cc); GR_SWIG_BLOCK_MAGIC2(filter, single_pole_iir_filter_ff); +GR_SWIG_BLOCK_MAGIC2(filter, channel_model); -- cgit