From f53fef3d2bc39b2020b8bce3d88b43569dd16605 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 12 May 2011 16:29:33 +0100 Subject: core: adding get/set sensitivity accessors to frequency_modulator_fc block. --- gnuradio-core/src/lib/general/gr_frequency_modulator_fc.h | 4 +++- gnuradio-core/src/lib/general/gr_frequency_modulator_fc.i | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/general/gr_frequency_modulator_fc.h b/gnuradio-core/src/lib/general/gr_frequency_modulator_fc.h index 4ba05d709..55f8412ce 100644 --- a/gnuradio-core/src/lib/general/gr_frequency_modulator_fc.h +++ b/gnuradio-core/src/lib/general/gr_frequency_modulator_fc.h @@ -47,7 +47,9 @@ class gr_frequency_modulator_fc : public gr_sync_block gr_frequency_modulator_fc (double sensitivity); public: - + void set_sensitivity(float sens) { d_sensitivity = sens; } + float get_sensitivity() { return d_sensitivity; } + int work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); diff --git a/gnuradio-core/src/lib/general/gr_frequency_modulator_fc.i b/gnuradio-core/src/lib/general/gr_frequency_modulator_fc.i index 612b59026..04d9a41ba 100644 --- a/gnuradio-core/src/lib/general/gr_frequency_modulator_fc.i +++ b/gnuradio-core/src/lib/general/gr_frequency_modulator_fc.i @@ -28,4 +28,7 @@ class gr_frequency_modulator_fc : public gr_sync_block { private: gr_frequency_modulator_fc (double sensitivity); +public: + void set_sensitivity(float sens) { d_sensitivity = sens; } + float get_sensitivity() { return d_sensitivity; } }; -- cgit From 900e227bd6a78609d3f4017291af944edae9a3dd Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 18 May 2011 11:05:50 +0100 Subject: core: minor changes to clean up adaptive filter code. --- .../src/lib/filter/gr_adaptive_fir_ccc.cc | 26 +++++++++++++--------- gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.h | 2 ++ 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.cc b/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.cc index 179391839..884caf29c 100644 --- a/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.cc +++ b/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.cc @@ -33,9 +33,8 @@ gr_adaptive_fir_ccc::gr_adaptive_fir_ccc(const char *name, int decimation, gr_make_io_signature (1, 1, sizeof(gr_complex)), gr_make_io_signature (1, 1, sizeof(gr_complex)), decimation), - d_updated(false) + d_taps(taps), d_updated(false) { - d_taps = taps; set_history(d_taps.size()); } @@ -46,6 +45,17 @@ gr_adaptive_fir_ccc::set_taps(const std::vector &taps) d_updated = true; } +gr_complex +gr_adaptive_fir_ccc::filter(gr_complex *x) +{ + // Generic dot product of d_taps[] and in[] + gr_complex acc(0.0, 0.0); + int l = d_taps.size(); + for (int k = 0; k < l; k++) + acc += d_taps[l-k-1] * x[k]; + return acc; +} + int gr_adaptive_fir_ccc::work(int noutput_items, gr_vector_const_void_star &input_items, @@ -63,20 +73,14 @@ gr_adaptive_fir_ccc::work(int noutput_items, int j = 0, k, l = d_taps.size(); for (int i = 0; i < noutput_items; i++) { - // Generic dot product of d_taps[] and in[] - gr_complex sum(0.0, 0.0); - for (k = 0; k < l; k++) - sum += d_taps[l-k-1]*in[j+k]; - out[i] = sum; + out[i] = filter(&in[j]); // Adjust taps - d_error = error(sum); + d_error = error(out[i]); for (k = 0; k < l; k++) { - //printf("%f ", d_taps[k]); update_tap(d_taps[l-k-1], in[j+k]); } - //printf("\n"); - + j += decimation(); } diff --git a/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.h b/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.h index 88b5f9281..8678255b7 100644 --- a/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.h +++ b/gnuradio-core/src/lib/filter/gr_adaptive_fir_ccc.h @@ -45,6 +45,8 @@ protected: // Override to calculate new weight from old, corresponding input virtual void update_tap(gr_complex &tap, const gr_complex &in) = 0; + gr_complex filter(gr_complex *x); + gr_adaptive_fir_ccc(const char *name, int decimation, const std::vector &taps); -- cgit From 781de9ee2986e96f201e796b5371d6bcb6324982 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 18 May 2011 12:12:17 +0100 Subject: filter: Adding a concept of output samples per symbol to the PFB clock recovery alg, mostly so you can pass on 2+ samples per symbol to a follow-on equalizer. --- .../src/lib/filter/gr_pfb_clock_sync_ccf.cc | 40 ++++++++++++++-------- .../src/lib/filter/gr_pfb_clock_sync_ccf.h | 10 ++++-- .../src/lib/filter/gr_pfb_clock_sync_ccf.i | 6 ++-- 3 files changed, 36 insertions(+), 20 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc index 937899c0d..a52d1d901 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.cc @@ -37,12 +37,14 @@ gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain, const std::vector &taps, unsigned int filter_size, float init_phase, - float max_rate_deviation) + float max_rate_deviation, + int osps) { return gnuradio::get_initial_sptr(new gr_pfb_clock_sync_ccf (sps, gain, taps, - filter_size, - init_phase, - max_rate_deviation)); + filter_size, + init_phase, + max_rate_deviation, + osps)); } static int ios[] = {sizeof(gr_complex), sizeof(float), sizeof(float), sizeof(float)}; @@ -51,12 +53,14 @@ gr_pfb_clock_sync_ccf::gr_pfb_clock_sync_ccf (double sps, float gain, const std::vector &taps, unsigned int filter_size, float init_phase, - float max_rate_deviation) + float max_rate_deviation, + int osps) : gr_block ("pfb_clock_sync_ccf", gr_make_io_signature (1, 1, sizeof(gr_complex)), gr_make_io_signaturev (1, 4, iosig)), d_updated (false), d_nfilters(filter_size), - d_max_dev(max_rate_deviation) + d_max_dev(max_rate_deviation), + d_osps(osps) { d_nfilters = filter_size; d_sps = floor(sps); @@ -239,13 +243,13 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items, } // We need this many to process one output - int nrequired = ninput_items[0] - d_taps_per_filter; + int nrequired = ninput_items[0] - d_taps_per_filter - d_osps; int i = 0, count = 0; float error, error_r, error_i; // produce output as long as we can and there are enough input samples - while((i < noutput_items) && (count < nrequired)) { + while((i < noutput_items-d_osps) && (count < nrequired)) { d_filtnum = (int)floor(d_k); // Keep the current filter number in [0, d_nfilters] @@ -262,7 +266,10 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items, count -= 1; } - out[i] = d_filters[d_filtnum]->filter(&in[count]); + for(int k = 0; k < d_osps; k++) { + out[i+k] = d_filters[d_filtnum]->filter(&in[count+k]); + } + gr_complex diff = d_diff_filters[d_filtnum]->filter(&in[count]); error_r = out[i].real() * diff.real(); error_i = out[i].imag() * diff.imag(); @@ -275,14 +282,17 @@ gr_pfb_clock_sync_ccf::general_work (int noutput_items, // Keep our rate within a good range d_rate_f = gr_branchless_clip(d_rate_f, d_max_dev); - i++; - count += (int)floor(d_sps); - if(output_items.size() == 4) { - err[i] = error; - outrate[i] = d_rate_f; - outk[i] = d_k; + // FIXME: don't really know what to do about d_osps>1 + for(int k = 0; k < d_osps; k++) { + err[i] = error; + outrate[i] = d_rate_f; + outk[i] = d_k; + } } + + i+=d_osps; + count += (int)floor(d_sps); } consume_each(count); diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h index fc80d2961..d4357e3d8 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h @@ -32,7 +32,8 @@ gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain, const std::vector &taps, unsigned int filter_size=32, float init_phase=0, - float max_rate_deviation=1.5); + float max_rate_deviation=1.5, + int osps=1); class gr_fir_ccf; @@ -128,7 +129,8 @@ class gr_pfb_clock_sync_ccf : public gr_block const std::vector &taps, unsigned int filter_size, float init_phase, - float max_rate_deviation); + float max_rate_deviation, + int osps); bool d_updated; double d_sps; @@ -147,6 +149,7 @@ class gr_pfb_clock_sync_ccf : public gr_block float d_max_dev; int d_filtnum; int d_taps_per_filter; + int d_osps; /*! * Build the polyphase filterbank timing synchronizer. @@ -155,7 +158,8 @@ class gr_pfb_clock_sync_ccf : public gr_block const std::vector &taps, unsigned int filter_size, float init_phase, - float max_rate_deviation); + float max_rate_deviation, + int osps); void create_diff_taps(const std::vector &newtaps, std::vector &difftaps); diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i index 197984287..343ed0912 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.i @@ -26,7 +26,8 @@ gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain, const std::vector &taps, unsigned int filter_size=32, float init_phase=0, - float max_rate_deviation=1.5); + float max_rate_deviation=1.5, + int osps=1); class gr_pfb_clock_sync_ccf : public gr_block { @@ -35,7 +36,8 @@ class gr_pfb_clock_sync_ccf : public gr_block const std::vector &taps, unsigned int filter_size, float init_phase, - float max_rate_deviation); + float max_rate_deviation, + int osps); public: ~gr_pfb_clock_sync_ccf (); -- cgit From 09f5b9606b57631d27d3abd868dcf5fe7eca6d12 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 25 May 2011 16:29:22 +0100 Subject: filter: adding a DC blocker algorithm. --- gnuradio-core/src/lib/filter/Makefile.am | 7 +- gnuradio-core/src/lib/filter/filter.i | 2 + gnuradio-core/src/lib/filter/gr_dc_blocker_cc.cc | 138 +++++++++++++++++++++++ gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h | 110 ++++++++++++++++++ gnuradio-core/src/lib/filter/gr_dc_blocker_cc.i | 34 ++++++ 5 files changed, 289 insertions(+), 2 deletions(-) create mode 100644 gnuradio-core/src/lib/filter/gr_dc_blocker_cc.cc create mode 100644 gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h create mode 100644 gnuradio-core/src/lib/filter/gr_dc_blocker_cc.i (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/filter/Makefile.am b/gnuradio-core/src/lib/filter/Makefile.am index dee13e239..95489156f 100644 --- a/gnuradio-core/src/lib/filter/Makefile.am +++ b/gnuradio-core/src/lib/filter/Makefile.am @@ -216,7 +216,8 @@ libfilter_la_common_SOURCES = \ gr_pfb_interpolator_ccf.cc \ gr_pfb_arb_resampler_ccf.cc \ gr_pfb_clock_sync_ccf.cc \ - gr_pfb_clock_sync_fff.cc + gr_pfb_clock_sync_fff.cc \ + gr_dc_blocker_cc.cc libfilter_qa_la_common_SOURCES = \ qa_filter.cc \ @@ -306,7 +307,8 @@ grinclude_HEADERS = \ gr_pfb_interpolator_ccf.h \ gr_pfb_arb_resampler_ccf.h \ gr_pfb_clock_sync_ccf.h \ - gr_pfb_clock_sync_fff.h + gr_pfb_clock_sync_fff.h \ + gr_dc_blocker_cc.h noinst_HEADERS = \ assembly.h \ @@ -372,6 +374,7 @@ swiginclude_HEADERS = \ gr_pfb_arb_resampler_ccf.i \ gr_pfb_clock_sync_ccf.i \ gr_pfb_clock_sync_fff.i \ + gr_dc_blocker_cc.i \ $(GENERATED_I) diff --git a/gnuradio-core/src/lib/filter/filter.i b/gnuradio-core/src/lib/filter/filter.i index 645607cba..b8f4d06eb 100644 --- a/gnuradio-core/src/lib/filter/filter.i +++ b/gnuradio-core/src/lib/filter/filter.i @@ -39,6 +39,7 @@ #include #include #include +#include %} %include "gr_iir_filter_ffd.i" @@ -62,5 +63,6 @@ %include "gr_pfb_arb_resampler_ccf.i" %include "gr_pfb_clock_sync_ccf.i" %include "gr_pfb_clock_sync_fff.i" +%include "gr_dc_blocker_cc.i" %include "filter_generated.i" diff --git a/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.cc b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.cc new file mode 100644 index 000000000..66f59f240 --- /dev/null +++ b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.cc @@ -0,0 +1,138 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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 +#include +#include + +moving_averager::moving_averager(int D) + : d_length(D), d_out(0), d_out_d1(0), d_out_d2(0) +{ + d_delay_line = std::deque(d_length-1, gr_complex(0,0)); +} + +moving_averager::~moving_averager() +{ +} + +gr_complex +moving_averager::filter(gr_complex x) +{ + d_out_d1 = d_out; + d_delay_line.push_back(x); + d_out = d_delay_line[0]; + d_delay_line.pop_front(); + + gr_complex y = x - d_out_d1 + d_out_d2; + d_out_d2 = y; + + return (y / (float)(d_length)); +} + + + +gr_dc_blocker_cc_sptr gr_make_dc_blocker_cc (int D, bool long_form) +{ + return gnuradio::get_initial_sptr(new gr_dc_blocker_cc(D, long_form)); +} + + +gr_dc_blocker_cc::gr_dc_blocker_cc (int D, bool long_form) + : gr_sync_block ("dc_blocker_cc", + gr_make_io_signature (1, 1, sizeof(gr_complex)), + gr_make_io_signature (1, 1, sizeof(gr_complex))), + d_length(D), d_long_form(long_form) +{ + if(d_long_form) { + d_ma_0 = new moving_averager(D); + d_ma_1 = new moving_averager(D); + d_ma_2 = new moving_averager(D); + d_ma_3 = new moving_averager(D); + d_delay_line = std::deque(d_length-1, gr_complex(0,0)); + } + else { + d_ma_0 = new moving_averager(D); + d_ma_1 = new moving_averager(D); + } +} + +gr_dc_blocker_cc::~gr_dc_blocker_cc() +{ + if(d_long_form) { + delete d_ma_0; + delete d_ma_1; + delete d_ma_2; + delete d_ma_3; + } + else { + delete d_ma_0; + delete d_ma_1; + } +} + +int +gr_dc_blocker_cc::get_group_delay() +{ + if(d_long_form) + return (2*d_length-2); + else + return d_length - 1; +} + +int +gr_dc_blocker_cc::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]; + + if(d_long_form) { + gr_complex y1, y2, y3, y4, d; + for(int i = 0; i < noutput_items; i++) { + y1 = d_ma_0->filter(in[i]); + y2 = d_ma_1->filter(y1); + y3 = d_ma_2->filter(y2); + y4 = d_ma_3->filter(y3); + + d_delay_line.push_back(d_ma_0->delayed_sig()); + d = d_delay_line[0]; + d_delay_line.pop_front(); + + out[i] = d - y4; + } + } + else { + gr_complex y1, y2; + for(int i = 0; i < noutput_items; i++) { + y1 = d_ma_0->filter(in[i]); + y2 = d_ma_1->filter(y1); + out[i] = d_ma_0->delayed_sig() - y2; + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h new file mode 100644 index 000000000..26a2247ea --- /dev/null +++ b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h @@ -0,0 +1,110 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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_GR_DC_BLOCKER_CC_H +#define INCLUDED_GR_DC_BLOCKER_CC_H + +#include +#include + +class gr_dc_blocker_cc; +typedef boost::shared_ptr gr_dc_blocker_cc_sptr; +gr_dc_blocker_cc_sptr gr_make_dc_blocker_cc (int D=32, bool long_form=true); + +/*! + * \class gr_dc_blocker_cc + * \brief a computationally efficient controllabel DC blocker + * + * \ingroup filter_blk + * + * This block implements a computationally efficient DC blocker that produces + * a tigher notch filter around DC for a smaller group delay than an + * equivalent FIR filter or using a single pole IIR filter. + * + * The block defaults to using a delay line of length 32 and the long form + * of the filter. Optionally, the delay line length can be changed to alter + * the width of the DC notch (longer lines will decrease the width). + * + * The long form of the filter produces a nearly flat response outside of + * the notch but at the cost of a group delay of 2D-2. + * + * The short form of the filter does not have a flat a response in the + * passband but has a group delay of only D-1 and is cheaper to compute. + * + * The theory behind this block can be found in the paper: + * + * R. Yates, "DC Blocker Algorithms," IEEE Signal Processing Magazine, + * Mar. 2008, pp 132-134. + */ +class moving_averager +{ +public: + moving_averager(int D); + ~moving_averager(); + + gr_complex filter(gr_complex x); + gr_complex delayed_sig() { return d_out; } + +private: + int d_length; + gr_complex d_out, d_out_d1, d_out_d2; + std::deque d_delay_line; +}; + +class gr_dc_blocker_cc : public gr_sync_block +{ + private: + /*! + * Build the DC blocker. + * \param D (int) the length of the delay line + * \param long_form (bool) whether to use long (true, default) or short form + * \param channel (unsigned integer) Selects the channel to return [default=0]. + */ + friend gr_dc_blocker_cc_sptr gr_make_dc_blocker_cc (int D, bool long_form); + + int d_length; + bool d_long_form; + moving_averager *d_ma_0; + moving_averager *d_ma_1; + moving_averager *d_ma_2; + moving_averager *d_ma_3; + std::deque d_delay_line; + + gr_dc_blocker_cc (int D, bool long_form); + +public: + ~gr_dc_blocker_cc (); + + /*! + * Get the blocker's group delay that is based on length of delay lines + */ + int get_group_delay(); + + //int set_length(int D); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.i b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.i new file mode 100644 index 000000000..b88fecbde --- /dev/null +++ b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.i @@ -0,0 +1,34 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,dc_blocker_cc); + +gr_dc_blocker_cc_sptr gr_make_dc_blocker_cc (int D=32, bool long_form=true); + +class gr_dc_blocker_cc : public gr_sync_block +{ + private: + gr_dc_blocker_cc (int D, bool long_form); + + public: + ~gr_dc_blocker_cc (); +}; -- cgit From e45053b962d8a8c3d6615950397cb6429a34e336 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 25 May 2011 16:49:57 +0100 Subject: filter: changing name of moving average class to remove name conflicts. --- gnuradio-core/src/lib/filter/gr_dc_blocker_cc.cc | 18 +++++++++--------- gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.cc b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.cc index 66f59f240..e7d5ced25 100644 --- a/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.cc +++ b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.cc @@ -28,18 +28,18 @@ #include #include -moving_averager::moving_averager(int D) +moving_averager_c::moving_averager_c(int D) : d_length(D), d_out(0), d_out_d1(0), d_out_d2(0) { d_delay_line = std::deque(d_length-1, gr_complex(0,0)); } -moving_averager::~moving_averager() +moving_averager_c::~moving_averager_c() { } gr_complex -moving_averager::filter(gr_complex x) +moving_averager_c::filter(gr_complex x) { d_out_d1 = d_out; d_delay_line.push_back(x); @@ -67,15 +67,15 @@ gr_dc_blocker_cc::gr_dc_blocker_cc (int D, bool long_form) d_length(D), d_long_form(long_form) { if(d_long_form) { - d_ma_0 = new moving_averager(D); - d_ma_1 = new moving_averager(D); - d_ma_2 = new moving_averager(D); - d_ma_3 = new moving_averager(D); + d_ma_0 = new moving_averager_c(D); + d_ma_1 = new moving_averager_c(D); + d_ma_2 = new moving_averager_c(D); + d_ma_3 = new moving_averager_c(D); d_delay_line = std::deque(d_length-1, gr_complex(0,0)); } else { - d_ma_0 = new moving_averager(D); - d_ma_1 = new moving_averager(D); + d_ma_0 = new moving_averager_c(D); + d_ma_1 = new moving_averager_c(D); } } diff --git a/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h index 26a2247ea..8e6164cbd 100644 --- a/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h +++ b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h @@ -56,11 +56,11 @@ gr_dc_blocker_cc_sptr gr_make_dc_blocker_cc (int D=32, bool long_form=true); * R. Yates, "DC Blocker Algorithms," IEEE Signal Processing Magazine, * Mar. 2008, pp 132-134. */ -class moving_averager +class moving_averager_c { public: - moving_averager(int D); - ~moving_averager(); + moving_averager_c(int D); + ~moving_averager_c(); gr_complex filter(gr_complex x); gr_complex delayed_sig() { return d_out; } @@ -84,10 +84,10 @@ class gr_dc_blocker_cc : public gr_sync_block int d_length; bool d_long_form; - moving_averager *d_ma_0; - moving_averager *d_ma_1; - moving_averager *d_ma_2; - moving_averager *d_ma_3; + moving_averager_c *d_ma_0; + moving_averager_c *d_ma_1; + moving_averager_c *d_ma_2; + moving_averager_c *d_ma_3; std::deque d_delay_line; gr_dc_blocker_cc (int D, bool long_form); -- cgit From b0b248eadb35bfcca178f97d5ba0160c5d3717eb Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 25 May 2011 16:50:25 +0100 Subject: filter: adding floating point version of DC blocker alg. --- gnuradio-core/src/lib/filter/Makefile.am | 7 +- gnuradio-core/src/lib/filter/filter.i | 2 + gnuradio-core/src/lib/filter/gr_dc_blocker_ff.cc | 138 +++++++++++++++++++++++ gnuradio-core/src/lib/filter/gr_dc_blocker_ff.h | 110 ++++++++++++++++++ gnuradio-core/src/lib/filter/gr_dc_blocker_ff.i | 34 ++++++ 5 files changed, 289 insertions(+), 2 deletions(-) create mode 100644 gnuradio-core/src/lib/filter/gr_dc_blocker_ff.cc create mode 100644 gnuradio-core/src/lib/filter/gr_dc_blocker_ff.h create mode 100644 gnuradio-core/src/lib/filter/gr_dc_blocker_ff.i (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/filter/Makefile.am b/gnuradio-core/src/lib/filter/Makefile.am index 95489156f..0314079a2 100644 --- a/gnuradio-core/src/lib/filter/Makefile.am +++ b/gnuradio-core/src/lib/filter/Makefile.am @@ -217,7 +217,8 @@ libfilter_la_common_SOURCES = \ gr_pfb_arb_resampler_ccf.cc \ gr_pfb_clock_sync_ccf.cc \ gr_pfb_clock_sync_fff.cc \ - gr_dc_blocker_cc.cc + gr_dc_blocker_cc.cc \ + gr_dc_blocker_ff.cc libfilter_qa_la_common_SOURCES = \ qa_filter.cc \ @@ -308,7 +309,8 @@ grinclude_HEADERS = \ gr_pfb_arb_resampler_ccf.h \ gr_pfb_clock_sync_ccf.h \ gr_pfb_clock_sync_fff.h \ - gr_dc_blocker_cc.h + gr_dc_blocker_cc.h \ + gr_dc_blocker_ff.h noinst_HEADERS = \ assembly.h \ @@ -375,6 +377,7 @@ swiginclude_HEADERS = \ gr_pfb_clock_sync_ccf.i \ gr_pfb_clock_sync_fff.i \ gr_dc_blocker_cc.i \ + gr_dc_blocker_ff.i \ $(GENERATED_I) diff --git a/gnuradio-core/src/lib/filter/filter.i b/gnuradio-core/src/lib/filter/filter.i index b8f4d06eb..58bb4f0d5 100644 --- a/gnuradio-core/src/lib/filter/filter.i +++ b/gnuradio-core/src/lib/filter/filter.i @@ -40,6 +40,7 @@ #include #include #include +#include %} %include "gr_iir_filter_ffd.i" @@ -64,5 +65,6 @@ %include "gr_pfb_clock_sync_ccf.i" %include "gr_pfb_clock_sync_fff.i" %include "gr_dc_blocker_cc.i" +%include "gr_dc_blocker_ff.i" %include "filter_generated.i" diff --git a/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.cc b/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.cc new file mode 100644 index 000000000..d684bc7e8 --- /dev/null +++ b/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.cc @@ -0,0 +1,138 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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 +#include +#include + +moving_averager_f::moving_averager_f(int D) + : d_length(D), d_out(0), d_out_d1(0), d_out_d2(0) +{ + d_delay_line = std::deque(d_length-1, 0); +} + +moving_averager_f::~moving_averager_f() +{ +} + +float +moving_averager_f::filter(float x) +{ + d_out_d1 = d_out; + d_delay_line.push_back(x); + d_out = d_delay_line[0]; + d_delay_line.pop_front(); + + float y = x - d_out_d1 + d_out_d2; + d_out_d2 = y; + + return (y / (float)(d_length)); +} + + + +gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D, bool long_form) +{ + return gnuradio::get_initial_sptr(new gr_dc_blocker_ff(D, long_form)); +} + + +gr_dc_blocker_ff::gr_dc_blocker_ff (int D, bool long_form) + : gr_sync_block ("dc_blocker_ff", + gr_make_io_signature (1, 1, sizeof(float)), + gr_make_io_signature (1, 1, sizeof(float))), + d_length(D), d_long_form(long_form) +{ + if(d_long_form) { + d_ma_0 = new moving_averager_f(D); + d_ma_1 = new moving_averager_f(D); + d_ma_2 = new moving_averager_f(D); + d_ma_3 = new moving_averager_f(D); + d_delay_line = std::deque(d_length-1, 0); + } + else { + d_ma_0 = new moving_averager_f(D); + d_ma_1 = new moving_averager_f(D); + } +} + +gr_dc_blocker_ff::~gr_dc_blocker_ff() +{ + if(d_long_form) { + delete d_ma_0; + delete d_ma_1; + delete d_ma_2; + delete d_ma_3; + } + else { + delete d_ma_0; + delete d_ma_1; + } +} + +int +gr_dc_blocker_ff::get_group_delay() +{ + if(d_long_form) + return (2*d_length-2); + else + return d_length - 1; +} + +int +gr_dc_blocker_ff::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const float *in = (const float*)input_items[0]; + float *out = (float*)output_items[0]; + + if(d_long_form) { + float y1, y2, y3, y4, d; + for(int i = 0; i < noutput_items; i++) { + y1 = d_ma_0->filter(in[i]); + y2 = d_ma_1->filter(y1); + y3 = d_ma_2->filter(y2); + y4 = d_ma_3->filter(y3); + + d_delay_line.push_back(d_ma_0->delayed_sig()); + d = d_delay_line[0]; + d_delay_line.pop_front(); + + out[i] = d - y4; + } + } + else { + float y1, y2; + for(int i = 0; i < noutput_items; i++) { + y1 = d_ma_0->filter(in[i]); + y2 = d_ma_1->filter(y1); + out[i] = d_ma_0->delayed_sig() - y2; + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.h b/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.h new file mode 100644 index 000000000..adaaca1e2 --- /dev/null +++ b/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.h @@ -0,0 +1,110 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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_GR_DC_BLOCKER_FF_H +#define INCLUDED_GR_DC_BLOCKER_FF_H + +#include +#include + +class gr_dc_blocker_ff; +typedef boost::shared_ptr gr_dc_blocker_ff_sptr; +gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D=32, bool long_form=true); + +/*! + * \class gr_dc_blocker_ff + * \brief a computationally efficient controllabel DC blocker + * + * \ingroup filter_blk + * + * This block implements a computationally efficient DC blocker that produces + * a tigher notch filter around DC for a smaller group delay than an + * equivalent FIR filter or using a single pole IIR filter. + * + * The block defaults to using a delay line of length 32 and the long form + * of the filter. Optionally, the delay line length can be changed to alter + * the width of the DC notch (longer lines will decrease the width). + * + * The long form of the filter produces a nearly flat response outside of + * the notch but at the cost of a group delay of 2D-2. + * + * The short form of the filter does not have a flat a response in the + * passband but has a group delay of only D-1 and is cheaper to compute. + * + * The theory behind this block can be found in the paper: + * + * R. Yates, "DC Blocker Algorithms," IEEE Signal Processing Magazine, + * Mar. 2008, pp 132-134. + */ +class moving_averager_f +{ +public: + moving_averager_f(int D); + ~moving_averager_f(); + + float filter(float x); + float delayed_sig() { return d_out; } + +private: + int d_length; + float d_out, d_out_d1, d_out_d2; + std::deque d_delay_line; +}; + +class gr_dc_blocker_ff : public gr_sync_block +{ + private: + /*! + * Build the DC blocker. + * \param D (int) the length of the delay line + * \param long_form (bool) whether to use long (true, default) or short form + * \param channel (unsigned integer) Selects the channel to return [default=0]. + */ + friend gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D, bool long_form); + + int d_length; + bool d_long_form; + moving_averager_f *d_ma_0; + moving_averager_f *d_ma_1; + moving_averager_f *d_ma_2; + moving_averager_f *d_ma_3; + std::deque d_delay_line; + + gr_dc_blocker_ff (int D, bool long_form); + +public: + ~gr_dc_blocker_ff (); + + /*! + * Get the blocker's group delay that is based on length of delay lines + */ + int get_group_delay(); + + //int set_length(int D); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.i b/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.i new file mode 100644 index 000000000..032145c9e --- /dev/null +++ b/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.i @@ -0,0 +1,34 @@ +/* -*- c++ -*- */ +/* + * Copyright 2011 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,dc_blocker_ff); + +gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D=32, bool long_form=true); + +class gr_dc_blocker_ff : public gr_sync_block +{ + private: + gr_dc_blocker_ff (int D, bool long_form); + + public: + ~gr_dc_blocker_ff (); +}; -- cgit From 7829d145d3a00b64a9e203008a6ea4847e966388 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 2 Jun 2011 11:11:17 -0400 Subject: core: fixed documentation for dc blocker. --- gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h | 5 +++-- gnuradio-core/src/lib/filter/gr_dc_blocker_ff.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h index 8e6164cbd..de9ccc0ea 100644 --- a/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h +++ b/gnuradio-core/src/lib/filter/gr_dc_blocker_cc.h @@ -39,7 +39,8 @@ gr_dc_blocker_cc_sptr gr_make_dc_blocker_cc (int D=32, bool long_form=true); * * This block implements a computationally efficient DC blocker that produces * a tigher notch filter around DC for a smaller group delay than an - * equivalent FIR filter or using a single pole IIR filter. + * equivalent FIR filter or using a single pole IIR filter (though the IIR + * filter is computationally cheaper). * * The block defaults to using a delay line of length 32 and the long form * of the filter. Optionally, the delay line length can be changed to alter @@ -48,7 +49,7 @@ gr_dc_blocker_cc_sptr gr_make_dc_blocker_cc (int D=32, bool long_form=true); * The long form of the filter produces a nearly flat response outside of * the notch but at the cost of a group delay of 2D-2. * - * The short form of the filter does not have a flat a response in the + * The short form of the filter does not have as flat a response in the * passband but has a group delay of only D-1 and is cheaper to compute. * * The theory behind this block can be found in the paper: diff --git a/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.h b/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.h index adaaca1e2..b632d81da 100644 --- a/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.h +++ b/gnuradio-core/src/lib/filter/gr_dc_blocker_ff.h @@ -39,7 +39,8 @@ gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D=32, bool long_form=true); * * This block implements a computationally efficient DC blocker that produces * a tigher notch filter around DC for a smaller group delay than an - * equivalent FIR filter or using a single pole IIR filter. + * equivalent FIR filter or using a single pole IIR filter (though the IIR + * filter is computationally cheaper). * * The block defaults to using a delay line of length 32 and the long form * of the filter. Optionally, the delay line length can be changed to alter @@ -48,7 +49,7 @@ gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D=32, bool long_form=true); * The long form of the filter produces a nearly flat response outside of * the notch but at the cost of a group delay of 2D-2. * - * The short form of the filter does not have a flat a response in the + * The short form of the filter does not have as flat a response in the * passband but has a group delay of only D-1 and is cheaper to compute. * * The theory behind this block can be found in the paper: -- cgit From add65c9ceae949592a9719175575f88da217790a Mon Sep 17 00:00:00 2001 From: Don Ward Date: Sat, 11 Jun 2011 14:46:18 -0700 Subject: Allow disabling shm vmcircbuf tests at configure time --- gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gnuradio-core/src/lib') diff --git a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc index abcf5b2a6..3b8a6e617 100644 --- a/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc +++ b/gnuradio-core/src/lib/runtime/gr_vmcircbuf.cc @@ -100,8 +100,10 @@ gr_vmcircbuf_sysconfig::all_factories () std::vector result; result.push_back (gr_vmcircbuf_createfilemapping_factory::singleton ()); +#ifdef TRY_SHM_VMCIRCBUF result.push_back (gr_vmcircbuf_sysv_shm_factory::singleton ()); result.push_back (gr_vmcircbuf_mmap_shm_open_factory::singleton ()); +#endif result.push_back (gr_vmcircbuf_mmap_tmpfile_factory::singleton ()); return result; -- cgit