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