GNU Radio 3.4.2 C++ API
gr_pfb_decimator_ccf.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2009 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_DECIMATOR_CCF_H
00025 #define INCLUDED_GR_PFB_DECIMATOR_CCF_H
00026 
00027 #include <gr_sync_block.h>
00028 
00029 class gr_pfb_decimator_ccf;
00030 typedef boost::shared_ptr<gr_pfb_decimator_ccf> gr_pfb_decimator_ccf_sptr;
00031 gr_pfb_decimator_ccf_sptr gr_make_pfb_decimator_ccf (unsigned int decim, 
00032                                                      const std::vector<float> &taps,
00033                                                      unsigned int channel=0);
00034 
00035 class gr_fir_ccf;
00036 class gri_fft_complex;
00037 
00038 /*!
00039  * \class gr_pfb_decimator_ccf
00040  * \brief Polyphase filterbank bandpass decimator with gr_complex 
00041  *        input, gr_complex output and float taps
00042  *
00043  * \ingroup filter_blk
00044  * 
00045  * This block takes in a signal stream and performs interger down-
00046  * sampling (decimation) with a polyphase filterbank. The first input
00047  * is the integer specifying how much to decimate by. The second
00048  * input is a vector (Python list) of floating-point taps of the 
00049  * prototype filter. The third input specifies the channel to extract.
00050  * By default, the zeroth channel is used, which is the baseband 
00051  * channel (first Nyquist zone).
00052  *
00053  * The <EM>channel</EM> parameter specifies which channel to use since
00054  * this class is capable of bandpass decimation. Given a complex input
00055  * stream at a sampling rate of <EM>fs</EM> and a decimation rate of
00056  * <EM>decim</EM>, the input frequency domain is split into 
00057  * <EM>decim</EM> channels that represent the Nyquist zones. Using the
00058  * polyphase filterbank, we can select any one of these channels to
00059  * decimate.
00060  *
00061  * The output signal will be the basebanded and decimated signal from
00062  * that channel. This concept is very similar to the PFB channelizer
00063  * (see #gr_pfb_channelizer_ccf) where only a single channel is 
00064  * extracted at a time.
00065  *
00066  * The filter's taps should be based on the sampling rate before
00067  * decimation.
00068  *
00069  * For example, using the GNU Radio's firdes utility to building
00070  * filters, we build a low-pass filter with a sampling rate of 
00071  * <EM>fs</EM>, a 3-dB bandwidth of <EM>BW</EM> and a transition
00072  * bandwidth of <EM>TB</EM>. We can also specify the out-of-band
00073  * attenuation to use, <EM>ATT</EM>, and the filter window
00074  * function (a Blackman-harris window in this case). The first input
00075  *  is the gain of the filter, which we specify here as unity.
00076  *
00077  *      <B><EM>self._taps = gr.firdes.low_pass_2(1, fs, BW, TB, 
00078  *           attenuation_dB=ATT, window=gr.firdes.WIN_BLACKMAN_hARRIS)</EM></B>
00079  *
00080  * The PFB decimator code takes the taps generated above and builds a
00081  * set of filters. The set contains <EM>decim</EM> number of filters
00082  * and each filter contains ceil(taps.size()/decim) number of taps.
00083  * Each tap from the filter prototype is sequentially inserted into
00084  * the next filter. When all of the input taps are used, the remaining
00085  * filters in the filterbank are filled out with 0's to make sure each 
00086  * filter has the same number of taps.
00087  *
00088  * The theory behind this block can be found in Chapter 6 of 
00089  * the following book.
00090  *
00091  *    <B><EM>f. harris, "Multirate Signal Processing for Communication 
00092  *       Systems," Upper Saddle River, NJ: Prentice Hall, Inc. 2004.</EM></B>
00093  */
00094 
00095 class gr_pfb_decimator_ccf : public gr_sync_block
00096 {
00097  private:
00098   /*!
00099    * Build the polyphase filterbank decimator.
00100    * \param decim   (unsigned integer) Specifies the decimation rate to use
00101    * \param taps    (vector/list of floats) The prototype filter to populate the filterbank.
00102    * \param channel (unsigned integer) Selects the channel to return [default=0].
00103    */
00104   friend gr_pfb_decimator_ccf_sptr gr_make_pfb_decimator_ccf (unsigned int decim,
00105                                                               const std::vector<float> &taps,
00106                                                               unsigned int channel);
00107 
00108   std::vector<gr_fir_ccf*> d_filters;
00109   std::vector< std::vector<float> > d_taps;
00110   gri_fft_complex         *d_fft;
00111   unsigned int             d_rate;
00112   unsigned int             d_chan;
00113   unsigned int             d_taps_per_filter;
00114   bool                     d_updated;
00115   gr_complex              *d_rotator;
00116 
00117   /*!
00118    * Build the polyphase filterbank decimator.
00119    * \param decim   (unsigned integer) Specifies the decimation rate to use
00120    * \param taps    (vector/list of floats) The prototype filter to populate the filterbank.
00121    * \param channel (unsigned integer) Selects the channel to return [default=0].
00122    */
00123   gr_pfb_decimator_ccf (unsigned int decim, 
00124                         const std::vector<float> &taps,
00125                         unsigned int channel);
00126 
00127 public:
00128   ~gr_pfb_decimator_ccf ();
00129   
00130   /*!
00131    * Resets the filterbank's filter taps with the new prototype filter
00132    * \param taps    (vector/list of floats) The prototype filter to populate the filterbank.
00133    */
00134    void set_taps (const std::vector<float> &taps);
00135 
00136   /*!
00137    * Print all of the filterbank taps to screen.
00138    */
00139   void print_taps();
00140    
00141  //void set_channel (unsigned int channel);
00142 
00143   int work (int noutput_items,
00144             gr_vector_const_void_star &input_items,
00145             gr_vector_void_star &output_items);
00146 };
00147 
00148 #endif