GNU Radio 3.6.4.1 C++ API
polyphase_filterbank.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012 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_FILTER_POLYPHASE_FILTERBANK_H
25 #define INCLUDED_FILTER_POLYPHASE_FILTERBANK_H
26 
27 #include <filter/api.h>
28 #include <filter/fir_filter.h>
29 #include <fft/fft.h>
30 
31 namespace gr {
32  namespace filter {
33  namespace kernel {
34 
35  /*!
36  * \class polyphase_filterbank
37  *
38  * \brief Polyphase filterbank parent class
39  *
40  * \ingroup filter_blk
41  * \ingroup pfb_blk
42  *
43  * This block takes in complex inputs and channelizes it to
44  * <EM>M</EM> channels of equal bandwidth. Each of the resulting
45  * channels is decimated to the new rate that is the input
46  * sampling rate <EM>fs</EM> divided by the number of channels,
47  * <EM>M</EM>.
48  *
49  * The PFB channelizer code takes the taps generated above and
50  * builds a set of filters. The set contains <EM>M</EM> number
51  * of filters and each filter contains ceil(taps.size()/decim)
52  * number of taps. Each tap from the filter prototype is
53  * sequentially inserted into the next filter. When all of the
54  * input taps are used, the remaining filters in the filterbank
55  * are filled out with 0's to make sure each filter has the same
56  * number of taps.
57  *
58  * Each filter operates using the gr_fir filter classs of GNU
59  * Radio, which takes the input stream at <EM>i</EM> and
60  * performs the inner product calculation to <EM>i+(n-1)</EM>
61  * where <EM>n</EM> is the number of filter taps. To efficiently
62  * handle this in the GNU Radio structure, each filter input
63  * must come from its own input stream. So the channelizer must
64  * be provided with <EM>M</EM> streams where the input stream
65  * has been deinterleaved. This is most easily done using the
66  * gr_stream_to_streams block.
67  *
68  * The output is then produced as a vector, where index
69  * <EM>i</EM> in the vector is the next sample from the
70  * <EM>i</EM>th channel. This is most easily handled by sending
71  * the output to a gr_vector_to_streams block to handle the
72  * conversion and passing <EM>M</EM> streams out.
73  *
74  * The input and output formatting is done using a hier_block2
75  * called pfb_channelizer_ccf. This can take in a single stream
76  * and outputs <EM>M</EM> streams based on the behavior
77  * 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
87  * input is the gain of the filter, which we specify here as
88  * unity.
89  *
90  * <B><EM>self._taps = filter.firdes.low_pass_2(1, fs, BW, TB,
91  * attenuation_dB=ATT, window=filter.firdes.WIN_BLACKMAN_hARRIS)</EM></B>
92  *
93  * More on the theory of polyphase filterbanks can be found in
94  * the following book.
95  *
96  * <B><EM>f. harris, "Multirate Signal Processing for
97  * Communication Systems," Upper Saddle River, NJ:
98  * Prentice Hall, Inc. 2004.</EM></B>
99  *
100  */
101 
103  {
104  protected:
105  unsigned int d_nfilts;
106  std::vector<kernel::fir_filter_ccf*> d_filters;
107  std::vector< std::vector<float> > d_taps;
108  unsigned int d_taps_per_filter;
110 
111  public:
112  /*!
113  * Build the polyphase filterbank decimator.
114  * \param nfilts (unsigned integer) Specifies the number of
115  * channels <EM>M</EM>
116  * \param taps (vector/list of floats) The prototype filter to
117  * populate the filterbank.
118  */
119  polyphase_filterbank(unsigned int nfilts,
120  const std::vector<float> &taps);
121 
123 
124  /*!
125  * Update the filterbank's filter taps from a prototype
126  * filter.
127  *
128  * \param taps (vector/list of floats) The prototype filter to
129  * populate the filterbank.
130  */
131  void set_taps(const std::vector<float> &taps);
132 
133  /*!
134  * Print all of the filterbank taps to screen.
135  */
136  void print_taps();
137 
138  /*!
139  * Return a vector<vector<>> of the filterbank taps
140  */
141  std::vector<std::vector<float> > taps() const;
142  };
143 
144  } /* namespace kernel */
145  } /* namespace filter */
146 } /* namespace gr */
147 
148 #endif /* INCLUDED_FILTER_POLYPHASE_FILTERBANK_H */