GNU Radio 3.4.0 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2009,2010 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_PFB_CHANNELIZER_CCF_H 00025 #define INCLUDED_GR_PFB_CHANNELIZER_CCF_H 00026 00027 #include <gr_block.h> 00028 00029 class gr_pfb_channelizer_ccf; 00030 typedef boost::shared_ptr<gr_pfb_channelizer_ccf> gr_pfb_channelizer_ccf_sptr; 00031 gr_pfb_channelizer_ccf_sptr gr_make_pfb_channelizer_ccf (unsigned int numchans, 00032 const std::vector<float> &taps, 00033 float oversample_rate=1); 00034 00035 class gr_fir_ccf; 00036 class gri_fft_complex; 00037 00038 00039 /*! 00040 * \class gr_pfb_channelizer_ccf 00041 * 00042 * \brief Polyphase filterbank channelizer with 00043 * gr_complex input, gr_complex output and float taps 00044 * 00045 * \ingroup filter_blk 00046 * 00047 * This block takes in complex inputs and channelizes it to <EM>M</EM> 00048 * channels of equal bandwidth. Each of the resulting channels is 00049 * decimated to the new rate that is the input sampling rate 00050 * <EM>fs</EM> divided by the number of channels, <EM>M</EM>. 00051 * 00052 * The PFB channelizer code takes the taps generated above and builds 00053 * a set of filters. The set contains <EM>M</EM> number of filters 00054 * and each filter contains ceil(taps.size()/decim) number of taps. 00055 * Each tap from the filter prototype is sequentially inserted into 00056 * the next filter. When all of the input taps are used, the remaining 00057 * filters in the filterbank are filled out with 0's to make sure each 00058 * filter has the same number of taps. 00059 * 00060 * Each filter operates using the gr_fir filter classs of GNU Radio, 00061 * which takes the input stream at <EM>i</EM> and performs the inner 00062 * product calculation to <EM>i+(n-1)</EM> where <EM>n</EM> is the 00063 * number of filter taps. To efficiently handle this in the GNU Radio 00064 * structure, each filter input must come from its own input 00065 * stream. So the channelizer must be provided with <EM>M</EM> streams 00066 * where the input stream has been deinterleaved. This is most easily 00067 * done using the gr_stream_to_streams block. 00068 * 00069 * The output is then produced as a vector, where index <EM>i</EM> in 00070 * the vector is the next sample from the <EM>i</EM>th channel. This 00071 * is most easily handled by sending the output to a 00072 * gr_vector_to_streams block to handle the conversion and passing 00073 * <EM>M</EM> streams out. 00074 * 00075 * The input and output formatting is done using a hier_block2 called 00076 * pfb_channelizer_ccf. This can take in a single stream and outputs 00077 * <EM>M</EM> streams based on the behavior described above. 00078 * 00079 * The filter's taps should be based on the input sampling rate. 00080 * 00081 * For example, using the GNU Radio's firdes utility to building 00082 * filters, we build a low-pass filter with a sampling rate of 00083 * <EM>fs</EM>, a 3-dB bandwidth of <EM>BW</EM> and a transition 00084 * bandwidth of <EM>TB</EM>. We can also specify the out-of-band 00085 * attenuation to use, <EM>ATT</EM>, and the filter window 00086 * function (a Blackman-harris window in this case). The first input 00087 * is the gain of the filter, which we specify here as unity. 00088 * 00089 * <B><EM>self._taps = gr.firdes.low_pass_2(1, fs, BW, TB, 00090 * attenuation_dB=ATT, window=gr.firdes.WIN_BLACKMAN_hARRIS)</EM></B> 00091 * 00092 * The filter output can also be overs ampled. The over sampling rate 00093 * is the ratio of the the actual output sampling rate to the normal 00094 * output sampling rate. It must be rationally related to the number 00095 * of channels as N/i for i in [1,N], which gives an outputsample rate 00096 * of [fs/N, fs] where fs is the input sample rate and N is the number 00097 * of channels. 00098 * 00099 * For example, for 6 channels with fs = 6000 Hz, the normal rate is 00100 * 6000/6 = 1000 Hz. Allowable oversampling rates are 6/6, 6/5, 6/4, 00101 * 6/3, 6/2, and 6/1 where the output sample rate of a 6/1 oversample 00102 * ratio is 6000 Hz, or 6 times the normal 1000 Hz. A rate of 6/5 = 1.2, 00103 * so the output rate would be 1200 Hz. 00104 * 00105 * The theory behind this block can be found in Chapter 6 of 00106 * the following book. 00107 * 00108 * <B><EM>f. harris, "Multirate Signal Processing for Communication 00109 * Systems," Upper Saddle River, NJ: Prentice Hall, Inc. 2004.</EM></B> 00110 * 00111 */ 00112 00113 class gr_pfb_channelizer_ccf : public gr_block 00114 { 00115 private: 00116 /*! 00117 * Build the polyphase filterbank decimator. 00118 * \param numchans (unsigned integer) Specifies the number of channels <EM>M</EM> 00119 * \param taps (vector/list of floats) The prototype filter to populate the filterbank. 00120 * \param oversample_rate (float) The over sampling rate is the ratio of the the actual 00121 * output sampling rate to the normal output sampling rate. 00122 * It must be rationally related to the number of channels 00123 * as N/i for i in [1,N], which gives an outputsample rate 00124 * of [fs/N, fs] where fs is the input sample rate and N is 00125 * the number of channels. 00126 * 00127 * For example, for 6 channels with fs = 6000 Hz, the normal 00128 * rate is 6000/6 = 1000 Hz. Allowable oversampling rates 00129 * are 6/6, 6/5, 6/4, 6/3, 6/2, and 6/1 where the output 00130 * sample rate of a 6/1 oversample ratio is 6000 Hz, or 00131 * 6 times the normal 1000 Hz. 00132 */ 00133 friend gr_pfb_channelizer_ccf_sptr gr_make_pfb_channelizer_ccf (unsigned int numchans, 00134 const std::vector<float> &taps, 00135 float oversample_rate); 00136 00137 bool d_updated; 00138 unsigned int d_numchans; 00139 float d_oversample_rate; 00140 std::vector<gr_fir_ccf*> d_filters; 00141 std::vector< std::vector<float> > d_taps; 00142 unsigned int d_taps_per_filter; 00143 gri_fft_complex *d_fft; 00144 int *d_idxlut; 00145 int d_rate_ratio; 00146 int d_output_multiple; 00147 00148 /*! 00149 * Build the polyphase filterbank decimator. 00150 * \param numchans (unsigned integer) Specifies the number of channels <EM>M</EM> 00151 * \param taps (vector/list of floats) The prototype filter to populate the filterbank. 00152 * \param oversample_rate (float) The output over sampling rate. 00153 */ 00154 gr_pfb_channelizer_ccf (unsigned int numchans, 00155 const std::vector<float> &taps, 00156 float oversample_rate); 00157 00158 public: 00159 ~gr_pfb_channelizer_ccf (); 00160 00161 /*! 00162 * Resets the filterbank's filter taps with the new prototype filter 00163 * \param taps (vector/list of floats) The prototype filter to populate the filterbank. 00164 */ 00165 void set_taps (const std::vector<float> &taps); 00166 00167 /*! 00168 * Print all of the filterbank taps to screen. 00169 */ 00170 void print_taps(); 00171 00172 int general_work (int noutput_items, 00173 gr_vector_int &ninput_items, 00174 gr_vector_const_void_star &input_items, 00175 gr_vector_void_star &output_items); 00176 }; 00177 00178 #endif