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