Reworking variables to avoid recalculations/assignments.
[debian/gnuradio] / gnuradio-core / src / lib / filter / gr_pfb_channelizer_ccf.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2009,2010 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_CHANNELIZER_CCF_H
25 #define INCLUDED_GR_PFB_CHANNELIZER_CCF_H
26
27 #include <gr_block.h>
28
29 class gr_pfb_channelizer_ccf;
30 typedef boost::shared_ptr<gr_pfb_channelizer_ccf> gr_pfb_channelizer_ccf_sptr;
31 gr_pfb_channelizer_ccf_sptr gr_make_pfb_channelizer_ccf (unsigned int numchans, 
32                                                          const std::vector<float> &taps,
33                                                          float oversample_rate=1);
34
35 class gr_fir_ccf;
36 class gri_fft_complex;
37
38
39 /*!
40  * \class gr_pfb_channelizer_ccf
41  *
42  * \brief Polyphase filterbank channelizer with 
43  *        gr_complex input, gr_complex output and float taps
44  *
45  * \ingroup filter_blk
46  *
47  * This block takes in complex inputs and channelizes it to <EM>M</EM>
48  * channels of equal bandwidth. Each of the resulting channels is
49  * decimated to the new rate that is the input sampling rate
50  * <EM>fs</EM> divided by the number of channels, <EM>M</EM>.
51  *
52  * The PFB channelizer code takes the taps generated above and builds
53  * a set of filters. The set contains <EM>M</EM> number of filters
54  * and each filter contains ceil(taps.size()/decim) number of taps.
55  * Each tap from the filter prototype is sequentially inserted into
56  * the next filter. When all of the input taps are used, the remaining
57  * filters in the filterbank are filled out with 0's to make sure each
58  * filter has the same number of taps.
59  *
60  * Each filter operates using the gr_fir filter classs of GNU Radio,
61  * which takes the input stream at <EM>i</EM> and performs the inner
62  * product calculation to <EM>i+(n-1)</EM> where <EM>n</EM> is the
63  * number of filter taps. To efficiently handle this in the GNU Radio
64  * structure, each filter input must come from its own input
65  * stream. So the channelizer must be provided with <EM>M</EM> streams
66  * where the input stream has been deinterleaved. This is most easily
67  * done using the gr_stream_to_streams block.
68  *
69  * The output is then produced as a vector, where index <EM>i</EM> in
70  * the vector is the next sample from the <EM>i</EM>th channel. This
71  * is most easily handled by sending the output to a
72  * gr_vector_to_streams block to handle the conversion and passing
73  * <EM>M</EM> streams out.
74  *
75  * The input and output formatting is done using a hier_block2 called
76  * pfb_channelizer_ccf. This can take in a single stream and outputs
77  * <EM>M</EM> streams based on the behavior described above.
78  *
79  * The filter's taps should be based on the input sampling rate.
80  *
81  * For example, using the GNU Radio's firdes utility to building
82  * filters, we build a low-pass filter with a sampling rate of 
83  * <EM>fs</EM>, a 3-dB bandwidth of <EM>BW</EM> and a transition
84  * bandwidth of <EM>TB</EM>. We can also specify the out-of-band
85  * attenuation to use, <EM>ATT</EM>, and the filter window
86  * function (a Blackman-harris window in this case). The first input
87  *  is the gain of the filter, which we specify here as unity.
88  *
89  *      <B><EM>self._taps = gr.firdes.low_pass_2(1, fs, BW, TB, 
90  *           attenuation_dB=ATT, window=gr.firdes.WIN_BLACKMAN_hARRIS)</EM></B>
91  *
92  * The theory behind this block can be found in Chapter 6 of 
93  * the following book.
94  *
95  *    <B><EM>f. harris, "Multirate Signal Processing for Communication 
96  *       Systems," Upper Saddle River, NJ: Prentice Hall, Inc. 2004.</EM></B>
97  *
98  */
99
100 class gr_pfb_channelizer_ccf : public gr_block
101 {
102  private:
103   /*!
104    * Build the polyphase filterbank decimator.
105    * \param numchans (unsigned integer) Specifies the number of channels <EM>M</EM>
106    * \param taps    (vector/list of floats) The prototype filter to populate the filterbank.
107    */
108   friend gr_pfb_channelizer_ccf_sptr gr_make_pfb_channelizer_ccf (unsigned int numchans,
109                                                                   const std::vector<float> &taps,
110                                                                   float oversample_rate);
111
112   bool                     d_updated;
113   unsigned int             d_numchans;
114   float                    d_oversample_rate;
115   std::vector<gr_fir_ccf*> d_filters;
116   std::vector< std::vector<float> > d_taps;
117   unsigned int             d_taps_per_filter;
118   gri_fft_complex         *d_fft;
119   int                     *d_idxlut;
120   int                      d_rate_ratio;
121   int                      d_output_multiple;
122
123   /*!
124    * Build the polyphase filterbank decimator.
125    * \param numchans (unsigned integer) Specifies the number of channels <EM>M</EM>
126    * \param taps    (vector/list of floats) The prototype filter to populate the filterbank.
127    */
128   gr_pfb_channelizer_ccf (unsigned int numchans, 
129                           const std::vector<float> &taps,
130                           float oversample_rate);
131
132 public:
133   ~gr_pfb_channelizer_ccf ();
134   
135   /*!
136    * Resets the filterbank's filter taps with the new prototype filter
137    * \param taps    (vector/list of floats) The prototype filter to populate the filterbank.
138    */
139   void set_taps (const std::vector<float> &taps);
140
141   /*!
142    * Print all of the filterbank taps to screen.
143    */
144   void print_taps();
145   
146   int general_work (int noutput_items,
147                     gr_vector_int &ninput_items,
148                     gr_vector_const_void_star &input_items,
149                     gr_vector_void_star &output_items);
150 };
151
152 #endif