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