GNU Radio 3.6.2 C++ API
pfb_arb_resampler_fff.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2009-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_PFB_ARB_RESAMPLER_FFF_H
25 #define INCLUDED_PFB_ARB_RESAMPLER_FFF_H
26 
27 #include <filter/api.h>
28 #include <gr_block.h>
29 
30 namespace gr {
31  namespace filter {
32 
33  /*!
34  * \class pfb_arb_resampler_fff
35  *
36  * \brief Polyphase filterbank arbitrary resampler with
37  * float input, float output and float taps
38  *
39  * \ingroup filter_blk
40  * \ingroup pfb_blk
41  *
42  * This block takes in a signal stream and performs arbitrary
43  * resampling. The resampling rate can be any real number
44  * <EM>r</EM>. The resampling is done by constructing <EM>N</EM>
45  * filters where <EM>N</EM> is the interpolation rate. We then
46  * calculate <EM>D</EM> where <EM>D = floor(N/r)</EM>.
47  *
48  * Using <EM>N</EM> and <EM>D</EM>, we can perform rational
49  * resampling where <EM>N/D</EM> is a rational number close to the
50  * input rate <EM>r</EM> where we have <EM>N</EM> filters and we
51  * cycle through them as a polyphase filterbank with a stride of
52  * <EM>D</EM> so that <EM>i+1 = (i + D) % N</EM>.
53  *
54  * To get the arbitrary rate, we want to interpolate between two
55  * points. For each value out, we take an output from the current
56  * filter, <EM>i</EM>, and the next filter <EM>i+1</EM> and then
57  * linearly interpolate between the two based on the real
58  * resampling rate we want.
59  *
60  * The linear interpolation only provides us with an approximation
61  * to the real sampling rate specified. The error is a
62  * quantization error between the two filters we used as our
63  * interpolation points. To this end, the number of filters,
64  * <EM>N</EM>, used determines the quantization error; the larger
65  * <EM>N</EM>, the smaller the noise. You can design for a
66  * specified noise floor by setting the filter size (parameters
67  * <EM>filter_size</EM>). The size defaults to 32 filters, which
68  * is about as good as most implementations need.
69  *
70  * The trick with designing this filter is in how to specify the
71  * taps of the prototype filter. Like the PFB interpolator, the
72  * taps are specified using the interpolated filter rate. In this
73  * case, that rate is the input sample rate multiplied by the
74  * number of filters in the filterbank, which is also the
75  * interpolation rate. All other values should be relative to this
76  * rate.
77  *
78  * For example, for a 32-filter arbitrary resampler and using the
79  * GNU Radio's firdes utility to build the filter, we build a
80  * low-pass filter with a sampling rate of <EM>fs</EM>, a 3-dB
81  * bandwidth of <EM>BW</EM> and a transition bandwidth of
82  * <EM>TB</EM>. We can also specify the out-of-band attenuation to
83  * use, <EM>ATT</EM>, and the filter window function (a
84  * Blackman-harris window in this case). The first input is the
85  * gain of the filter, which we specify here as the interpolation
86  * rate (<EM>32</EM>).
87  *
88  * <B><EM>self._taps = filter.firdes.low_pass_2(32, 32*fs, BW, TB,
89  * attenuation_dB=ATT, window=filter.firdes.WIN_BLACKMAN_hARRIS)</EM></B>
90  *
91  * The theory behind this block can be found in Chapter 7.5 of the
92  * following book.
93  *
94  * <B><EM>f. harris, "Multirate Signal Processing for Communication
95  * Systems", Upper Saddle River, NJ: Prentice Hall, Inc. 2004.</EM></B>
96  */
97 
98  class FILTER_API pfb_arb_resampler_fff : virtual public gr_block
99  {
100  public:
101  // gr::filter::pfb_arb_resampler_fff::sptr
103 
104  /*!
105  * Build the polyphase filterbank arbitray resampler.
106  * \param rate (float) Specifies the resampling rate to use
107  * \param taps (vector/list of floats) The prototype filter to populate the filterbank. The taps
108  * should be generated at the filter_size sampling rate.
109  * \param filter_size (unsigned int) The number of filters in the filter bank. This is directly
110  * related to quantization noise introduced during the resampling.
111  * Defaults to 32 filters.
112  */
113  static sptr make(float rate,
114  const std::vector<float> &taps,
115  unsigned int filter_size=32);
116 
117  /*!
118  * Resets the filterbank's filter taps with the new prototype filter
119  * \param taps (vector/list of floats) The prototype filter to populate the filterbank.
120  */
121  virtual void set_taps(const std::vector<float> &taps) = 0;
122 
123  /*!
124  * Return a vector<vector<>> of the filterbank taps
125  */
126  virtual std::vector<std::vector<float> > taps() const = 0;
127 
128  /*!
129  * Print all of the filterbank taps to screen.
130  */
131  virtual void print_taps() = 0;
132 
133  /*!
134  * Sets the resampling rate of the block.
135  */
136  virtual void set_rate (float rate) = 0;
137 
138  /*!
139  * Sets the current phase offset in radians (0 to 2pi).
140  */
141  virtual void set_phase(float ph) = 0;
142 
143  /*!
144  * Gets the current phase of the resampler in radians (2 to 2pi).
145  */
146  virtual float phase() const = 0;
147  };
148 
149  } /* namespace filter */
150 } /* namespace gr */
151 
152 #endif /* INCLUDED_PFB_ARB_RESAMPLER_FFF_H */