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