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