GNU Radio 3.6.5.1 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  * \brief a computationally efficient controllable DC blocker
53  *
54  * This block implements a computationally efficient DC blocker that produces
55  * a tighter notch filter around DC for a smaller group delay than an
56  * equivalent FIR filter or using a single pole IIR filter (though the IIR
57  * filter is computationally cheaper).
58  *
59  * The block defaults to using a delay line of length 32 and the long form
60  * of the filter. Optionally, the delay line length can be changed to alter
61  * the width of the DC notch (longer lines will decrease the width).
62  *
63  * The long form of the filter produces a nearly flat response outside of
64  * the notch but at the cost of a group delay of 2D-2.
65  *
66  * The short form of the filter does not have as flat a response in the
67  * passband but has a group delay of only D-1 and is cheaper to compute.
68  *
69  * The theory behind this block can be found in the paper:
70  *
71  * <B><EM>R. Yates, "DC Blocker Algorithms," IEEE Signal Processing Magazine,
72  * Mar. 2008, pp 132-134.</EM></B>
73  */
75 {
76  private:
77  /*!
78  * Build the DC blocker.
79  * \param D (int) the length of the delay line
80  * \param long_form (bool) whether to use long (true, default) or short form
81  */
82  friend GR_CORE_API gr_dc_blocker_ff_sptr gr_make_dc_blocker_ff (int D, bool long_form);
83 
84  int d_length;
85  bool d_long_form;
86  moving_averager_f *d_ma_0;
87  moving_averager_f *d_ma_1;
88  moving_averager_f *d_ma_2;
89  moving_averager_f *d_ma_3;
90  std::deque<float> d_delay_line;
91 
92  gr_dc_blocker_ff (int D, bool long_form);
93 
94 public:
95  ~gr_dc_blocker_ff ();
96 
97  /*!
98  * Get the blocker's group delay that is based on length of delay lines
99  */
100  int get_group_delay();
101 
102  //int set_length(int D);
103 
104  int work (int noutput_items,
105  gr_vector_const_void_star &input_items,
106  gr_vector_void_star &output_items);
107 };
108 
109 #endif