GNU Radio 3.5.1 C++ API
gr_dc_blocker_ff.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2011 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 
00024 #ifndef INCLUDED_GR_DC_BLOCKER_FF_H
00025 #define INCLUDED_GR_DC_BLOCKER_FF_H
00026 
00027 #include <gr_core_api.h>
00028 #include <gr_sync_block.h>
00029 #include <deque>
00030 
00031 class GR_CORE_API moving_averager_f
00032 {
00033 public:
00034   moving_averager_f(int D);
00035   ~moving_averager_f();
00036 
00037   float filter(float x);
00038   float delayed_sig() { return d_out; }
00039 
00040 private:
00041   int d_length;
00042   float d_out, d_out_d1, d_out_d2;
00043   std::deque<float> d_delay_line;
00044 };
00045 
00046 
00047 class gr_dc_blocker_ff;
00048 typedef boost::shared_ptr<gr_dc_blocker_ff> gr_dc_blocker_ff_sptr;
00049 GR_CORE_API gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D=32, bool long_form=true);
00050 
00051 /*!
00052  * \class gr_dc_blocker_ff
00053  * \brief a computationally efficient controllable DC blocker
00054  *
00055  * \ingroup filter_blk
00056  * 
00057  * This block implements a computationally efficient DC blocker that produces
00058  * a tighter notch filter around DC for a smaller group delay than an
00059  * equivalent FIR filter or using a single pole IIR filter (though the IIR
00060  * filter is computationally cheaper).
00061  *
00062  * The block defaults to using a delay line of length 32 and the long form
00063  * of the filter. Optionally, the delay line length can be changed to alter
00064  * the width of the DC notch (longer lines will decrease the width).
00065  *
00066  * The long form of the filter produces a nearly flat response outside of
00067  * the notch but at the cost of a group delay of 2D-2.
00068  *
00069  * The short form of the filter does not have as flat a response in the
00070  * passband but has a group delay of only D-1 and is cheaper to compute.
00071  *
00072  * The theory behind this block can be found in the paper:
00073  *
00074  *    <B><EM>R. Yates, "DC Blocker Algorithms," IEEE Signal Processing Magazine,
00075  *        Mar. 2008, pp 132-134.</EM></B>
00076  */
00077 class GR_CORE_API gr_dc_blocker_ff : public gr_sync_block
00078 {
00079  private:
00080   /*!
00081    * Build the DC blocker.
00082    * \param D          (int) the length of the delay line
00083    * \param long_form  (bool) whether to use long (true, default) or short form
00084    */
00085   friend GR_CORE_API gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D, bool long_form);
00086 
00087   int d_length;
00088   bool d_long_form;
00089   moving_averager_f *d_ma_0;
00090   moving_averager_f *d_ma_1;
00091   moving_averager_f *d_ma_2;
00092   moving_averager_f *d_ma_3;
00093   std::deque<float> d_delay_line;
00094 
00095   gr_dc_blocker_ff (int D, bool long_form);
00096 
00097 public:
00098   ~gr_dc_blocker_ff ();
00099 
00100   /*!
00101    * Get the blocker's group delay that is based on length of delay lines
00102    */
00103   int get_group_delay();
00104 
00105   //int set_length(int D);
00106   
00107   int work (int noutput_items,
00108             gr_vector_const_void_star &input_items,
00109             gr_vector_void_star &output_items);
00110 };
00111 
00112 #endif