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