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