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