GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
firdes.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002,2008,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 #ifndef _FILTER_FIRDES_H_
12 #define _FILTER_FIRDES_H_
13 
14 #include <gnuradio/fft/window.h>
15 #include <gnuradio/filter/api.h>
16 #include <gnuradio/gr_complex.h>
17 #include <cmath>
18 #include <vector>
19 
20 namespace gr {
21 namespace filter {
22 
23 /*!
24  * \brief Finite Impulse Response (FIR) filter design functions.
25  * \ingroup filter_design
26  */
27 
29 {
30 public:
31  static std::vector<float> window(fft::window::win_type type, int ntaps, double param);
32 
33  // ... class methods ...
34 
35  /*!
36  * \brief Use "window method" to design a low-pass FIR filter. The
37  * normalized width of the transition band is what sets the number of
38  * taps required. Narrow --> more taps. Window type determines maximum
39  * attenuation and passband ripple.
40  *
41  * \param gain overall gain of filter (typically 1.0)
42  * \param sampling_freq sampling freq (Hz)
43  * \param cutoff_freq center of transition band (Hz)
44  * \param transition_width width of transition band (Hz)
45  * \param window one of fft::window::win_type
46  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
47  */
48  static std::vector<float>
49  low_pass(double gain,
50  double sampling_freq,
51  double cutoff_freq, // Hz center of transition band
52  double transition_width, // Hz width of transition band
53  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
54  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
55 
56  /*!
57  * \brief Use "window method" to design a low-pass FIR filter. The
58  * normalized width of the transition band and the required stop band
59  * attenuation is what sets the number of taps required. Narrow --> more
60  * taps More attenuation --> more taps. The window type determines
61  * maximum attenuation and passband ripple.
62  *
63  * \param gain overall gain of filter (typically 1.0)
64  * \param sampling_freq sampling freq (Hz)
65  * \param cutoff_freq beginning of transition band (Hz)
66  * \param transition_width width of transition band (Hz)
67  * \param attenuation_dB required stopband attenuation
68  * \param window one of fft::window::win_type
69  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
70  */
71  static std::vector<float>
72  low_pass_2(double gain,
73  double sampling_freq,
74  double cutoff_freq, // Hz beginning transition band
75  double transition_width, // Hz width of transition band
76  double attenuation_dB, // out of band attenuation dB
77  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
78  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
79 
80  /*!
81  * \brief Use "window method" to design a high-pass FIR filter. The
82  * normalized width of the transition band is what sets the number of
83  * taps required. Narrow --> more taps. The window determines maximum
84  * attenuation and passband ripple.
85  *
86  * \param gain overall gain of filter (typically 1.0)
87  * \param sampling_freq sampling freq (Hz)
88  * \param cutoff_freq center of transition band (Hz)
89  * \param transition_width width of transition band (Hz)
90  * \param window one of fft::window::win_type
91  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
92  */
93  static std::vector<float>
94  high_pass(double gain,
95  double sampling_freq,
96  double cutoff_freq, // Hz center of transition band
97  double transition_width, // Hz width of transition band
98  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
99  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
100 
101  /*!
102  * \brief Use "window method" to design a high-pass FIR filter. The
103  * normalized width of the transition band and the required stop band
104  * attenuation is what sets the number of taps required. Narrow --> more
105  * taps More attenuation --> more taps. The window determines maximum
106  * attenuation and passband ripple.
107  *
108  * \param gain overall gain of filter (typically 1.0)
109  * \param sampling_freq sampling freq (Hz)
110  * \param cutoff_freq center of transition band (Hz)
111  * \param transition_width width of transition band (Hz).
112  * \param attenuation_dB out of band attenuation
113  * \param window one of fft::window::win_type
114  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
115  */
116  static std::vector<float>
117  high_pass_2(double gain,
118  double sampling_freq,
119  double cutoff_freq, // Hz center of transition band
120  double transition_width, // Hz width of transition band
121  double attenuation_dB, // out of band attenuation dB
122  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
123  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
124 
125  /*!
126  * \brief Use "window method" to design a band-pass FIR filter. The
127  * normalized width of the transition band is what sets the number of
128  * taps required. Narrow --> more taps. The window determines maximum
129  * attenuation and passband ripple.
130  *
131  * \param gain overall gain of filter (typically 1.0)
132  * \param sampling_freq sampling freq (Hz)
133  * \param low_cutoff_freq center of transition band (Hz)
134  * \param high_cutoff_freq center of transition band (Hz)
135  * \param transition_width width of transition band (Hz).
136  * \param window one of fft::window::win_type
137  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
138  */
139  static std::vector<float>
140  band_pass(double gain,
141  double sampling_freq,
142  double low_cutoff_freq, // Hz center of transition band
143  double high_cutoff_freq, // Hz center of transition band
144  double transition_width, // Hz width of transition band
145  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
146  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
147 
148  /*!
149  * \brief Use "window method" to design a band-pass FIR filter. The
150  * normalized width of the transition band and the required stop band
151  * attenuation is what sets the number of taps required. Narrow --> more
152  * taps. More attenuation --> more taps. Window type determines maximum
153  * attenuation and passband ripple.
154  *
155  * \param gain overall gain of filter (typically 1.0)
156  * \param sampling_freq sampling freq (Hz)
157  * \param low_cutoff_freq center of transition band (Hz)
158  * \param high_cutoff_freq center of transition band (Hz)
159  * \param transition_width width of transition band (Hz).
160  * \param attenuation_dB out of band attenuation
161  * \param window one of fft::window::win_type
162  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
163  */
164  static std::vector<float>
165  band_pass_2(double gain,
166  double sampling_freq,
167  double low_cutoff_freq, // Hz beginning transition band
168  double high_cutoff_freq, // Hz beginning transition band
169  double transition_width, // Hz width of transition band
170  double attenuation_dB, // out of band attenuation dB
171  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
172  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
173  /*!
174  * \brief Use the "window method" to design a complex band-reject FIR
175  * filter. The normalized width of the transition band is what sets the
176  * number of taps required. Narrow --> more taps. The window type
177  * determines maximum attenuation and passband ripple.
178  *
179  * \param gain overall gain of filter (typically 1.0)
180  * \param sampling_freq sampling freq (Hz)
181  * \param low_cutoff_freq center of transition band (Hz)
182  * \param high_cutoff_freq center of transition band (Hz)
183  * \param transition_width width of transition band (Hz)
184  * \param window one of fft::window::win_type
185  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
186  */
187  static std::vector<gr_complex> complex_band_reject(
188  double gain,
189  double sampling_freq,
190  double low_cutoff_freq,
191  double high_cutoff_freq,
192  double transition_width, // Hz width of transition band
193  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
194  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
195 
196  /*!
197  * \brief Use "window method" to design a complex band-reject FIR filter.
198  * The normalized width of the transition band and the required stop band
199  * attenuation is what sets the number of taps required. Narrow --> more
200  * taps More attenuation --> more taps. Window type determines maximum
201  * attenuation and passband ripple.
202  *
203  * \param gain overall gain of filter (typically 1.0)
204  * \param sampling_freq sampling freq (Hz)
205  * \param low_cutoff_freq center of transition band (Hz)
206  * \param high_cutoff_freq center of transition band (Hz)
207  * \param transition_width width of transition band (Hz)
208  * \param attenuation_dB out of band attenuation
209  * \param window one of fft::window::win_type
210  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
211  */
212  static std::vector<gr_complex> complex_band_reject_2(
213  double gain,
214  double sampling_freq,
215  double low_cutoff_freq, // Hz beginning transition band
216  double high_cutoff_freq, // Hz beginning transition band
217  double transition_width, // Hz width of transition band
218  double attenuation_dB, // out of band attenuation dB
219  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
220  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
221 
222  /*!
223  * \brief Use the "window method" to design a complex band-pass FIR
224  * filter. The normalized width of the transition band is what sets the
225  * number of taps required. Narrow --> more taps. The window type
226  * determines maximum attenuation and passband ripple.
227  *
228  * \param gain overall gain of filter (typically 1.0)
229  * \param sampling_freq sampling freq (Hz)
230  * \param low_cutoff_freq center of transition band (Hz)
231  * \param high_cutoff_freq center of transition band (Hz)
232  * \param transition_width width of transition band (Hz)
233  * \param window one of fft::window::win_type
234  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
235  */
236  static std::vector<gr_complex> complex_band_pass(
237  double gain,
238  double sampling_freq,
239  double low_cutoff_freq, // Hz center of transition band
240  double high_cutoff_freq, // Hz center of transition band
241  double transition_width, // Hz width of transition band
242  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
243  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
244 
245  /*!
246  * \brief Use "window method" to design a complex band-pass FIR filter.
247  * The normalized width of the transition band and the required stop band
248  * attenuation is what sets the number of taps required. Narrow --> more
249  * taps More attenuation --> more taps. Window type determines maximum
250  * attenuation and passband ripple.
251  *
252  * \param gain overall gain of filter (typically 1.0)
253  * \param sampling_freq sampling freq (Hz)
254  * \param low_cutoff_freq center of transition band (Hz)
255  * \param high_cutoff_freq center of transition band (Hz)
256  * \param transition_width width of transition band (Hz)
257  * \param attenuation_dB out of band attenuation
258  * \param window one of fft::window::win_type
259  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
260  */
261  static std::vector<gr_complex> complex_band_pass_2(
262  double gain,
263  double sampling_freq,
264  double low_cutoff_freq, // Hz beginning transition band
265  double high_cutoff_freq, // Hz beginning transition band
266  double transition_width, // Hz width of transition band
267  double attenuation_dB, // out of band attenuation dB
268  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
269  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
270 
271  /*!
272  * \brief Use "window method" to design a band-reject FIR filter. The
273  * normalized width of the transition band is what sets the number of
274  * taps required. Narrow --> more taps. Window type determines maximum
275  * attenuation and passband ripple.
276  *
277  * \param gain overall gain of filter (typically 1.0)
278  * \param sampling_freq sampling freq (Hz)
279  * \param low_cutoff_freq center of transition band (Hz)
280  * \param high_cutoff_freq center of transition band (Hz)
281  * \param transition_width width of transition band (Hz)
282  * \param window one of fft::window::win_type
283  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
284  */
285  static std::vector<float>
286  band_reject(double gain,
287  double sampling_freq,
288  double low_cutoff_freq, // Hz center of transition band
289  double high_cutoff_freq, // Hz center of transition band
290  double transition_width, // Hz width of transition band
291  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
292  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
293 
294  /*!
295  * \brief Use "window method" to design a band-reject FIR filter. The
296  * normalized width of the transition band and the required stop band
297  * attenuation is what sets the number of taps required. Narrow --> more
298  * taps More attenuation --> more taps. Window type determines maximum
299  * attenuation and passband ripple.
300  *
301  * \param gain overall gain of filter (typically 1.0)
302  * \param sampling_freq sampling freq (Hz)
303  * \param low_cutoff_freq center of transition band (Hz)
304  * \param high_cutoff_freq center of transition band (Hz)
305  * \param transition_width width of transition band (Hz).
306  * \param attenuation_dB out of band attenuation
307  * \param window one of fft::window::win_type
308  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
309  */
310  static std::vector<float>
311  band_reject_2(double gain,
312  double sampling_freq,
313  double low_cutoff_freq, // Hz beginning transition band
314  double high_cutoff_freq, // Hz beginning transition band
315  double transition_width, // Hz width of transition band
316  double attenuation_dB, // out of band attenuation dB
317  fft::window::win_type window = fft::window::win_type::WIN_HAMMING,
318  double param = 6.76); // used for Kaiser, Exp., Gaussian, Tukey windows
319 
320  /*!\brief design a Hilbert Transform Filter
321  *
322  * \param ntaps number of taps, must be odd
323  * \param windowtype one kind of fft::window::win_type
324  * \param param parameter for Kaiser, Exp., Gaussian, Tukey windows
325  */
326  static std::vector<float>
327  hilbert(unsigned int ntaps = 19,
328  fft::window::win_type windowtype = fft::window::win_type::WIN_RECTANGULAR,
329  double param = 6.76);
330 
331  /*!
332  * \brief design a Root Cosine FIR Filter (do we need a window?)
333  *
334  * \param gain overall gain of filter (typically 1.0)
335  * \param sampling_freq sampling freq (Hz)
336  * \param symbol_rate symbol rate, must be a factor of sample rate
337  * \param alpha excess bandwidth factor
338  * \param ntaps number of taps
339  */
340  static std::vector<float>
341  root_raised_cosine(double gain,
342  double sampling_freq,
343  double symbol_rate, // Symbol rate, NOT bitrate (unless BPSK)
344  double alpha, // Excess Bandwidth Factor
345  int ntaps);
346 
347  /*!
348  * \brief design a Gaussian filter
349  *
350  * \param gain overall gain of filter (typically 1.0)
351  * \param spb symbol rate, must be a factor of sample rate
352  * \param bt bandwidth to bitrate ratio
353  * \param ntaps number of taps
354  */
355  static std::vector<float> gaussian(double gain,
356  double spb,
357  double bt, // Bandwidth to bitrate ratio
358  int ntaps);
359 
360 private:
361  static double bessi0(double x);
362  static void sanity_check_1f(double sampling_freq, double f1, double transition_width);
363  static void
364  sanity_check_2f(double sampling_freq, double f1, double f2, double transition_width);
365  static void sanity_check_2f_c(double sampling_freq,
366  double f1,
367  double f2,
368  double transition_width);
369 
370  static int compute_ntaps(double sampling_freq,
371  double transition_width,
372  fft::window::win_type window_type,
373  double param);
374 
375  static int compute_ntaps_windes(double sampling_freq,
376  double transition_width,
377  double attenuation_dB);
378 };
379 
380 } /* namespace filter */
381 } /* namespace gr */
382 
383 #endif /* _FILTER_FIRDES_H_ */
win_type
Definition: window.h:28
Finite Impulse Response (FIR) filter design functions.
Definition: firdes.h:29
static std::vector< float > window(fft::window::win_type type, int ntaps, double param)
static std::vector< float > high_pass_2(double gain, double sampling_freq, double cutoff_freq, double transition_width, double attenuation_dB, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use "window method" to design a high-pass FIR filter. The normalized width of the transition band and...
static std::vector< float > low_pass_2(double gain, double sampling_freq, double cutoff_freq, double transition_width, double attenuation_dB, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use "window method" to design a low-pass FIR filter. The normalized width of the transition band and ...
static std::vector< float > band_reject(double gain, double sampling_freq, double low_cutoff_freq, double high_cutoff_freq, double transition_width, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use "window method" to design a band-reject FIR filter. The normalized width of the transition band i...
static std::vector< float > band_pass_2(double gain, double sampling_freq, double low_cutoff_freq, double high_cutoff_freq, double transition_width, double attenuation_dB, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use "window method" to design a band-pass FIR filter. The normalized width of the transition band and...
static std::vector< gr_complex > complex_band_reject_2(double gain, double sampling_freq, double low_cutoff_freq, double high_cutoff_freq, double transition_width, double attenuation_dB, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use "window method" to design a complex band-reject FIR filter. The normalized width of the transitio...
static std::vector< float > band_reject_2(double gain, double sampling_freq, double low_cutoff_freq, double high_cutoff_freq, double transition_width, double attenuation_dB, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use "window method" to design a band-reject FIR filter. The normalized width of the transition band a...
static std::vector< float > hilbert(unsigned int ntaps=19, fft::window::win_type windowtype=fft::window::win_type::WIN_RECTANGULAR, double param=6.76)
design a Hilbert Transform Filter
static std::vector< float > gaussian(double gain, double spb, double bt, int ntaps)
design a Gaussian filter
static std::vector< float > band_pass(double gain, double sampling_freq, double low_cutoff_freq, double high_cutoff_freq, double transition_width, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use "window method" to design a band-pass FIR filter. The normalized width of the transition band is ...
static std::vector< gr_complex > complex_band_pass(double gain, double sampling_freq, double low_cutoff_freq, double high_cutoff_freq, double transition_width, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use the "window method" to design a complex band-pass FIR filter. The normalized width of the transit...
static std::vector< float > low_pass(double gain, double sampling_freq, double cutoff_freq, double transition_width, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use "window method" to design a low-pass FIR filter. The normalized width of the transition band is w...
static std::vector< gr_complex > complex_band_reject(double gain, double sampling_freq, double low_cutoff_freq, double high_cutoff_freq, double transition_width, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use the "window method" to design a complex band-reject FIR filter. The normalized width of the trans...
static std::vector< gr_complex > complex_band_pass_2(double gain, double sampling_freq, double low_cutoff_freq, double high_cutoff_freq, double transition_width, double attenuation_dB, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use "window method" to design a complex band-pass FIR filter. The normalized width of the transition ...
static std::vector< float > root_raised_cosine(double gain, double sampling_freq, double symbol_rate, double alpha, int ntaps)
design a Root Cosine FIR Filter (do we need a window?)
static std::vector< float > high_pass(double gain, double sampling_freq, double cutoff_freq, double transition_width, fft::window::win_type window=fft::window::win_type::WIN_HAMMING, double param=6.76)
Use "window method" to design a high-pass FIR filter. The normalized width of the transition band is ...
#define FILTER_API
Definition: gr-filter/include/gnuradio/filter/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29