GNU Radio 3.6.4.1 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 #include <gruel/thread.h>
30 
34  const std::vector<float> &taps,
35  float oversample_rate=1);
36 
37 class gr_fir_ccf;
38 class gri_fft_complex;
39 
40 
41 /*!
42  * \class gr_pfb_channelizer_ccf
43  *
44  * \brief Polyphase filterbank channelizer with
45  * gr_complex input, gr_complex output and float taps
46  *
47  * \ingroup filter_blk
48  * \ingroup pfb_blk
49  *
50  * This block takes in complex inputs and channelizes it to <EM>M</EM>
51  * channels of equal bandwidth. Each of the resulting channels is
52  * decimated to the new rate that is the input sampling rate
53  * <EM>fs</EM> divided by the number of channels, <EM>M</EM>.
54  *
55  * The PFB channelizer code takes the taps generated above and builds
56  * a set of filters. The set contains <EM>M</EM> number of filters
57  * and each filter contains ceil(taps.size()/decim) number of taps.
58  * Each tap from the filter prototype is sequentially inserted into
59  * the next filter. When all of the input taps are used, the remaining
60  * filters in the filterbank are filled out with 0's to make sure each
61  * filter has the same number of taps.
62  *
63  * Each filter operates using the gr_fir filter classs of GNU Radio,
64  * which takes the input stream at <EM>i</EM> and performs the inner
65  * product calculation to <EM>i+(n-1)</EM> where <EM>n</EM> is the
66  * number of filter taps. To efficiently handle this in the GNU Radio
67  * structure, each filter input must come from its own input
68  * stream. So the channelizer must be provided with <EM>M</EM> streams
69  * where the input stream has been deinterleaved. This is most easily
70  * done using the gr_stream_to_streams block.
71  *
72  * The output is then produced as a vector, where index <EM>i</EM> in
73  * the vector is the next sample from the <EM>i</EM>th channel. This
74  * is most easily handled by sending the output to a
75  * gr_vector_to_streams block to handle the conversion and passing
76  * <EM>M</EM> streams out.
77  *
78  * The input and output formatting is done using a hier_block2 called
79  * pfb_channelizer_ccf. This can take in a single stream and outputs
80  * <EM>M</EM> streams based on the behavior described above.
81  *
82  * The filter's taps should be based on the input sampling rate.
83  *
84  * For example, using the GNU Radio's firdes utility to building
85  * filters, we build a low-pass filter with a sampling rate of
86  * <EM>fs</EM>, a 3-dB bandwidth of <EM>BW</EM> and a transition
87  * bandwidth of <EM>TB</EM>. We can also specify the out-of-band
88  * attenuation to use, <EM>ATT</EM>, and the filter window
89  * function (a Blackman-harris window in this case). The first input
90  * is the gain of the filter, which we specify here as unity.
91  *
92  * <B><EM>self._taps = gr.firdes.low_pass_2(1, fs, BW, TB,
93  * attenuation_dB=ATT, window=gr.firdes.WIN_BLACKMAN_hARRIS)</EM></B>
94  *
95  * The filter output can also be overs ampled. The over sampling rate
96  * is the ratio of the the actual output sampling rate to the normal
97  * output sampling rate. It must be rationally related to the number
98  * of channels as N/i for i in [1,N], which gives an outputsample rate
99  * of [fs/N, fs] where fs is the input sample rate and N is the number
100  * of channels.
101  *
102  * For example, for 6 channels with fs = 6000 Hz, the normal rate is
103  * 6000/6 = 1000 Hz. Allowable oversampling rates are 6/6, 6/5, 6/4,
104  * 6/3, 6/2, and 6/1 where the output sample rate of a 6/1 oversample
105  * ratio is 6000 Hz, or 6 times the normal 1000 Hz. A rate of 6/5 = 1.2,
106  * so the output rate would be 1200 Hz.
107  *
108  * The theory behind this block can be found in Chapter 6 of
109  * the following book.
110  *
111  * <B><EM>f. harris, "Multirate Signal Processing for Communication
112  * Systems," Upper Saddle River, NJ: Prentice Hall, Inc. 2004.</EM></B>
113  *
114  */
115 
117 {
118  private:
119  /*!
120  * Build the polyphase filterbank decimator.
121  * \param numchans (unsigned integer) Specifies the number of channels <EM>M</EM>
122  * \param taps (vector/list of floats) The prototype filter to populate the filterbank.
123  * \param oversample_rate (float) The over sampling rate is the ratio of the the actual
124  * output sampling rate to the normal output sampling rate.
125  * It must be rationally related to the number of channels
126  * as N/i for i in [1,N], which gives an outputsample rate
127  * of [fs/N, fs] where fs is the input sample rate and N is
128  * the number of channels.
129  *
130  * For example, for 6 channels with fs = 6000 Hz, the normal
131  * rate is 6000/6 = 1000 Hz. Allowable oversampling rates
132  * are 6/6, 6/5, 6/4, 6/3, 6/2, and 6/1 where the output
133  * sample rate of a 6/1 oversample ratio is 6000 Hz, or
134  * 6 times the normal 1000 Hz.
135  */
137  const std::vector<float> &taps,
138  float oversample_rate);
139 
140  bool d_updated;
141  unsigned int d_numchans;
142  float d_oversample_rate;
143  std::vector<gr_fir_ccf*> d_filters;
144  std::vector< std::vector<float> > d_taps;
145  unsigned int d_taps_per_filter;
146  gri_fft_complex *d_fft;
147  int *d_idxlut;
148  int d_rate_ratio;
149  int d_output_multiple;
150  std::vector<int> d_channel_map;
151  gruel::mutex d_mutex; // mutex to protect set/work access
152 
153  /*!
154  * Build the polyphase filterbank decimator.
155  * \param numchans (unsigned integer) Specifies the number of channels <EM>M</EM>
156  * \param taps (vector/list of floats) The prototype filter to populate the filterbank.
157  * \param oversample_rate (float) The output over sampling rate.
158  */
159  gr_pfb_channelizer_ccf (unsigned int numchans,
160  const std::vector<float> &taps,
161  float oversample_rate);
162 
163 public:
165 
166  /*!
167  * Resets the filterbank's filter taps with the new prototype filter
168  * \param taps (vector/list of floats) The prototype filter to populate the filterbank.
169  */
170  void set_taps (const std::vector<float> &taps);
171 
172  /*!
173  * Print all of the filterbank taps to screen.
174  */
175  void print_taps();
176 
177  /*!
178  * Return a vector<vector<>> of the filterbank taps
179  */
180  std::vector<std::vector<float> > taps() const;
181 
182  /*!
183  * Set the channel map. Channels are numbers as:
184  *
185  * N/2+1 | ... | N-1 | 0 | 1 | 2 | ... | N/2
186  * <------------------- 0 -------------------->
187  * freq
188  *
189  * So output stream 0 comes from channel 0, etc. Setting a new
190  * channel map allows the user to specify which channel in frequency
191  * he/she wants to got to which output stream.
192  *
193  * The map should have the same number of elements as the number of
194  * output connections from the block. The minimum value of the map
195  * is 0 (for the 0th channel) and the maximum number is N-1 where N
196  * is the number of channels.
197  *
198  * We specify M as the number of output connections made where M <=
199  * N, so only M out of N channels are driven to an output
200  * stream. The number of items in the channel map should be at least
201  * M long. If there are more channels specified, any value in the
202  * map over M-1 will be ignored. If the size of the map is less than
203  * M the behavior is unknown (we don't wish to check every entry
204  * into the work function).
205  *
206  * This means that if the channelizer is splitting the signal up
207  * into N channels but only M channels are specified in the map
208  * (where M <= N), then M output streams must be connected and the
209  * map and the channel numbers used must be less than N-1. Output
210  * channel number can be reused, too. By default, the map is
211  * [0...M-1] with M = N.
212  */
213  void set_channel_map(const std::vector<int> &map);
214 
215  /*!
216  * Gets the current channel map.
217  */
218  std::vector<int> channel_map() const;
219 
220  int general_work (int noutput_items,
221  gr_vector_int &ninput_items,
222  gr_vector_const_void_star &input_items,
223  gr_vector_void_star &output_items);
224 };
225 
226 #endif