Merging trondeau/pfb r11249:11581 into trunk. This adds a few polyphase filterbank...
[debian/gnuradio] / gnuradio-core / src / lib / filter / gr_pfb_decimator_ccf.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2009 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_PFB_DECIMATOR_CCF_H
25 #define INCLUDED_GR_PFB_DECIMATOR_CCF_H
26
27 #include <gr_sync_block.h>
28
29 class gr_pfb_decimator_ccf;
30 typedef boost::shared_ptr<gr_pfb_decimator_ccf> gr_pfb_decimator_ccf_sptr;
31 gr_pfb_decimator_ccf_sptr gr_make_pfb_decimator_ccf (unsigned int decim, 
32                                                      const std::vector<float> &taps,
33                                                      unsigned int channel=0);
34
35 class gr_fir_ccf;
36 class gri_fft_complex;
37
38 /*!
39  * \class gr_pfb_decimator_ccf
40  * \brief Polyphase filterbank bandpass decimator with gr_complex 
41  *        input, gr_complex output and float taps
42  *
43  * \ingroup filter_blk
44  * 
45  * This block takes in a signal stream and performs interger down-
46  * sampling (decimation) with a polyphase filterbank. The first input
47  * is the integer specifying how much to decimate by. The second
48  * input is a vector (Python list) of floating-point taps of the 
49  * prototype filter. The third input specifies the channel to extract.
50  * By default, the zeroth channel is used, which is the baseband 
51  * channel (first Nyquist zone).
52  *
53  * The <EM>channel</EM> parameter specifies which channel to use since
54  * this class is capable of bandpass decimation. Given a complex input
55  * stream at a sampling rate of <EM>fs</EM> and a decimation rate of
56  * <EM>decim</EM>, the input frequency domain is split into 
57  * <EM>decim</EM> channels that represent the Nyquist zones. Using the
58  * polyphase filterbank, we can select any one of these channels to
59  * decimate.
60  *
61  * The output signal will be the basebanded and decimated signal from
62  * that channel. This concept is very similar to the PFB channelizer
63  * (see #gr_pfb_channelizer_ccf) where only a single channel is 
64  * extracted at a time.
65  *
66  * The filter's taps should be based on the sampling rate before
67  * decimation.
68  *
69  * For example, using the GNU Radio's firdes utility to building
70  * filters, we build a low-pass filter with a sampling rate of 
71  * <EM>fs</EM>, a 3-dB bandwidth of <EM>BW</EM> and a transition
72  * bandwidth of <EM>TB</EM>. We can also specify the out-of-band
73  * attenuation to use, <EM>ATT</EM>, and the filter window
74  * function (a Blackman-harris window in this case). The first input
75  *  is the gain of the filter, which we specify here as unity.
76  *
77  *      <B><EM>self._taps = gr.firdes.low_pass_2(1, fs, BW, TB, 
78  *           attenuation_dB=ATT, window=gr.firdes.WIN_BLACKMAN_hARRIS)</EM></B>
79  *
80  * The PFB decimator code takes the taps generated above and builds a
81  * set of filters. The set contains <EM>decim</EM> number of filters
82  * and each filter contains ceil(taps.size()/decim) number of taps.
83  * Each tap from the filter prototype is sequentially inserted into
84  * the next filter. When all of the input taps are used, the remaining
85  * filters in the filterbank are filled out with 0's to make sure each 
86  * filter has the same number of taps.
87  *
88  * The theory behind this block can be found in Chapter 6 of 
89  * the following book.
90  *
91  *    <B><EM>f. harris, Multirate Signal Processing for Communication 
92  *       Systems," Upper Saddle River, NJ: Prentice Hall, Inc. 2004.</EM></B>
93  */
94
95 class gr_pfb_decimator_ccf : public gr_sync_block
96 {
97  private:
98   /*!
99    * Build the polyphase filterbank decimator.
100    * \param decim   (unsigned integer) Specifies the decimation rate to use
101    * \param taps    (vector/list of floats) The prototype filter to populate the filterbank.
102    * \param channel (unsigned integer) Selects the channel to return [default=0].
103    */
104   friend gr_pfb_decimator_ccf_sptr gr_make_pfb_decimator_ccf (unsigned int decim,
105                                                               const std::vector<float> &taps,
106                                                               unsigned int channel);
107
108   std::vector<gr_fir_ccf*> d_filters;
109   std::vector< std::vector<float> > d_taps;
110   gri_fft_complex         *d_fft;
111   unsigned int             d_rate;
112   unsigned int             d_chan;
113   unsigned int             d_taps_per_filter;
114   bool                     d_updated;
115   gr_complex              *d_rotator;
116
117   /*!
118    * Build the polyphase filterbank decimator.
119    * \param decim   (unsigned integer) Specifies the decimation rate to use
120    * \param taps    (vector/list of floats) The prototype filter to populate the filterbank.
121    * \param channel (unsigned integer) Selects the channel to return [default=0].
122    */
123   gr_pfb_decimator_ccf (unsigned int decim, 
124                         const std::vector<float> &taps,
125                         unsigned int channel);
126
127 public:
128   ~gr_pfb_decimator_ccf ();
129   
130   /*!
131    * Resets the filterbank's filter taps with the new prototype filter
132    * \param taps    (vector/list of floats) The prototype filter to populate the filterbank.
133    */
134    void set_taps (const std::vector<float> &taps);
135
136   /*!
137    * Print all of the filterbank taps to screen.
138    */
139   void print_taps();
140    
141  //void set_channel (unsigned int channel);
142
143   int work (int noutput_items,
144             gr_vector_const_void_star &input_items,
145             gr_vector_void_star &output_items);
146 };
147
148 #endif