GNU Radio 3.4.2 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_sync_block.h>
00028 #include <deque>
00029 
00030 class gr_dc_blocker_ff;
00031 typedef boost::shared_ptr<gr_dc_blocker_ff> gr_dc_blocker_ff_sptr;
00032 gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D=32, bool long_form=true);
00033 
00034 /*!
00035  * \class gr_dc_blocker_ff
00036  * \brief a computationally efficient controllabel DC blocker
00037  *
00038  * \ingroup filter_blk
00039  * 
00040  * This block implements a computationally efficient DC blocker that produces
00041  * a tigher notch filter around DC for a smaller group delay than an
00042  * equivalent FIR filter or using a single pole IIR filter (though the IIR
00043  * filter is computationally cheaper).
00044  *
00045  * The block defaults to using a delay line of length 32 and the long form
00046  * of the filter. Optionally, the delay line length can be changed to alter
00047  * the width of the DC notch (longer lines will decrease the width).
00048  *
00049  * The long form of the filter produces a nearly flat response outside of
00050  * the notch but at the cost of a group delay of 2D-2.
00051  *
00052  * The short form of the filter does not have as flat a response in the
00053  * passband but has a group delay of only D-1 and is cheaper to compute.
00054  *
00055  * The theory behind this block can be found in the paper:
00056  *
00057  *    <B><EM>R. Yates, "DC Blocker Algorithms," IEEE Signal Processing Magazine,
00058  *        Mar. 2008, pp 132-134.</EM></B>
00059  */
00060 class moving_averager_f
00061 {
00062 public:
00063   moving_averager_f(int D);
00064   ~moving_averager_f();
00065 
00066   float filter(float x);
00067   float delayed_sig() { return d_out; }
00068 
00069 private:
00070   int d_length;
00071   float d_out, d_out_d1, d_out_d2;
00072   std::deque<float> d_delay_line;
00073 };
00074 
00075 class gr_dc_blocker_ff : public gr_sync_block
00076 {
00077  private:
00078   /*!
00079    * Build the DC blocker.
00080    * \param D          (int) the length of the delay line
00081    * \param long_form  (bool) whether to use long (true, default) or short form
00082    */
00083   friend gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D, bool long_form);
00084 
00085   int d_length;
00086   bool d_long_form;
00087   moving_averager_f *d_ma_0;
00088   moving_averager_f *d_ma_1;
00089   moving_averager_f *d_ma_2;
00090   moving_averager_f *d_ma_3;
00091   std::deque<float> d_delay_line;
00092 
00093   gr_dc_blocker_ff (int D, bool long_form);
00094 
00095 public:
00096   ~gr_dc_blocker_ff ();
00097 
00098   /*!
00099    * Get the blocker's group delay that is based on length of delay lines
00100    */
00101   int get_group_delay();
00102 
00103   //int set_length(int D);
00104   
00105   int work (int noutput_items,
00106             gr_vector_const_void_star &input_items,
00107             gr_vector_void_star &output_items);
00108 };
00109 
00110 #endif