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