GNU Radio 3.6.3 C++ API
gr_dc_blocker_ff.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2011 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 
24 #ifndef INCLUDED_GR_DC_BLOCKER_FF_H
25 #define INCLUDED_GR_DC_BLOCKER_FF_H
26 
27 #include <gr_core_api.h>
28 #include <gr_sync_block.h>
29 #include <deque>
30 
32 {
33 public:
34  moving_averager_f(int D);
36 
37  float filter(float x);
38  float delayed_sig() { return d_out; }
39 
40 private:
41  int d_length;
42  float d_out, d_out_d1, d_out_d2;
43  std::deque<float> d_delay_line;
44 };
45 
46 
47 class gr_dc_blocker_ff;
49 GR_CORE_API gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D=32, bool long_form=true);
50 
51 /*!
52  * \class gr_dc_blocker_ff
53  * \brief a computationally efficient controllable DC blocker
54  *
55  * \ingroup filter_blk
56  *
57  * This block implements a computationally efficient DC blocker that produces
58  * a tighter notch filter around DC for a smaller group delay than an
59  * equivalent FIR filter or using a single pole IIR filter (though the IIR
60  * filter is computationally cheaper).
61  *
62  * The block defaults to using a delay line of length 32 and the long form
63  * of the filter. Optionally, the delay line length can be changed to alter
64  * the width of the DC notch (longer lines will decrease the width).
65  *
66  * The long form of the filter produces a nearly flat response outside of
67  * the notch but at the cost of a group delay of 2D-2.
68  *
69  * The short form of the filter does not have as flat a response in the
70  * passband but has a group delay of only D-1 and is cheaper to compute.
71  *
72  * The theory behind this block can be found in the paper:
73  *
74  * <B><EM>R. Yates, "DC Blocker Algorithms," IEEE Signal Processing Magazine,
75  * Mar. 2008, pp 132-134.</EM></B>
76  */
78 {
79  private:
80  /*!
81  * Build the DC blocker.
82  * \param D (int) the length of the delay line
83  * \param long_form (bool) whether to use long (true, default) or short form
84  */
85  friend GR_CORE_API gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D, bool long_form);
86 
87  int d_length;
88  bool d_long_form;
89  moving_averager_f *d_ma_0;
90  moving_averager_f *d_ma_1;
91  moving_averager_f *d_ma_2;
92  moving_averager_f *d_ma_3;
93  std::deque<float> d_delay_line;
94 
95  gr_dc_blocker_ff (int D, bool long_form);
96 
97 public:
98  ~gr_dc_blocker_ff ();
99 
100  /*!
101  * Get the blocker's group delay that is based on length of delay lines
102  */
103  int get_group_delay();
104 
105  //int set_length(int D);
106 
107  int work (int noutput_items,
108  gr_vector_const_void_star &input_items,
109  gr_vector_void_star &output_items);
110 };
111 
112 #endif