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