GNU Radio Manual and C++ API Reference  3.8.1.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  * 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/fft/window.h>
27 #include <gnuradio/filter/api.h>
28 #include <gnuradio/gr_complex.h>
29 #include <cmath>
30 #include <vector>
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 {
42 public:
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 =
54  5, //!< alias to WIN_BLACKMAN_hARRIS for capitalization consistency
55  WIN_BARTLETT = 6, //!< Barlett (triangular) window
56  WIN_FLATTOP = 7, //!< flat top window; useful in FFTs
57  };
58 
59  static std::vector<float> window(win_type type, int ntaps, double beta);
60 
61  // ... class methods ...
62 
63  /*!
64  * \brief Use "window method" to design a low-pass FIR filter. The
65  * normalized width of the transition band is what sets the number of
66  * taps required. Narrow --> more taps. Window type determines maximum
67  * attenuation and passband ripple.
68  *
69  * \param gain overall gain of filter (typically 1.0)
70  * \param sampling_freq sampling freq (Hz)
71  * \param cutoff_freq center of transition band (Hz)
72  * \param transition_width width of transition band (Hz)
73  * \param window one of firdes::win_type
74  * \param beta parameter for Kaiser window
75  */
76  static std::vector<float>
77  low_pass(double gain,
78  double sampling_freq,
79  double cutoff_freq, // Hz center of transition band
80  double transition_width, // Hz width of transition band
81  win_type window = WIN_HAMMING,
82  double beta = 6.76); // used only with Kaiser
83 
84  /*!
85  * \brief Use "window method" to design a low-pass FIR filter. The
86  * normalized width of the transition band and the required stop band
87  * attenuation is what sets the number of taps required. Narrow --> more
88  * taps More attenuation --> more taps. The window type determines
89  * maximum attentuation and passband ripple.
90  *
91  * \param gain overall gain of filter (typically 1.0)
92  * \param sampling_freq sampling freq (Hz)
93  * \param cutoff_freq beginning of transition band (Hz)
94  * \param transition_width width of transition band (Hz)
95  * \param attenuation_dB required stopband attenuation
96  * \param window one of firdes::win_type
97  * \param beta parameter for Kaiser window
98  */
99  static std::vector<float>
100  low_pass_2(double gain,
101  double sampling_freq,
102  double cutoff_freq, // Hz beginning transition band
103  double transition_width, // Hz width of transition band
104  double attenuation_dB, // out of band attenuation dB
105  win_type window = WIN_HAMMING,
106  double beta = 6.76); // used only with Kaiser
107 
108  /*!
109  * \brief Use "window method" to design a high-pass FIR filter. The
110  * normalized width of the transition band is what sets the number of
111  * taps required. Narrow --> more taps. The window determines maximum
112  * attenuation and passband ripple.
113  *
114  * \param gain overall gain of filter (typically 1.0)
115  * \param sampling_freq sampling freq (Hz)
116  * \param cutoff_freq center of transition band (Hz)
117  * \param transition_width width of transition band (Hz)
118  * \param window one of firdes::win_type
119  * \param beta parameter for Kaiser window
120  */
121  static std::vector<float>
122  high_pass(double gain,
123  double sampling_freq,
124  double cutoff_freq, // Hz center of transition band
125  double transition_width, // Hz width of transition band
126  win_type window = WIN_HAMMING,
127  double beta = 6.76); // used only with Kaiser
128 
129  /*!
130  * \brief Use "window method" to design a high-pass FIR filter. The
131  * normalized width of the transition band and the required stop band
132  * attenuation is what sets the number of taps required. Narrow --> more
133  * taps More attenuation --> more taps. The window determines maximum
134  * attenuation and passband ripple.
135  *
136  * \param gain overall gain of filter (typically 1.0)
137  * \param sampling_freq sampling freq (Hz)
138  * \param cutoff_freq center of transition band (Hz)
139  * \param transition_width width of transition band (Hz).
140  * \param attenuation_dB out of band attenuation
141  * \param window one of firdes::win_type
142  * \param beta parameter for Kaiser window
143  */
144  static std::vector<float>
145  high_pass_2(double gain,
146  double sampling_freq,
147  double cutoff_freq, // Hz center of transition band
148  double transition_width, // Hz width of transition band
149  double attenuation_dB, // out of band attenuation dB
150  win_type window = WIN_HAMMING,
151  double beta = 6.76); // used only with Kaiser
152 
153  /*!
154  * \brief Use "window method" to design a band-pass FIR filter. The
155  * normalized width of the transition band is what sets the number of
156  * taps required. Narrow --> more taps. The window determines maximum
157  * attenuation and passband ripple.
158  *
159  * \param gain overall gain of filter (typically 1.0)
160  * \param sampling_freq sampling freq (Hz)
161  * \param low_cutoff_freq center of transition band (Hz)
162  * \param high_cutoff_freq center of transition band (Hz)
163  * \param transition_width width of transition band (Hz).
164  * \param window one of firdes::win_type
165  * \param beta parameter for Kaiser window
166  */
167  static std::vector<float>
168  band_pass(double gain,
169  double sampling_freq,
170  double low_cutoff_freq, // Hz center of transition band
171  double high_cutoff_freq, // Hz center of transition band
172  double transition_width, // Hz width of transition band
173  win_type window = WIN_HAMMING,
174  double beta = 6.76); // used only with Kaiser
175 
176  /*!
177  * \brief Use "window method" to design a band-pass FIR filter. The
178  * normalized width of the transition band and the required stop band
179  * attenuation is what sets the number of taps required. Narrow --> more
180  * taps. More attenuation --> more taps. Window type determines maximum
181  * attenuation and passband ripple.
182  *
183  * \param gain overall gain of filter (typically 1.0)
184  * \param sampling_freq sampling freq (Hz)
185  * \param low_cutoff_freq center of transition band (Hz)
186  * \param high_cutoff_freq center of transition band (Hz)
187  * \param transition_width width of transition band (Hz).
188  * \param attenuation_dB out of band attenuation
189  * \param window one of firdes::win_type
190  * \param beta parameter for Kaiser window
191  */
192  static std::vector<float>
193  band_pass_2(double gain,
194  double sampling_freq,
195  double low_cutoff_freq, // Hz beginning transition band
196  double high_cutoff_freq, // Hz beginning transition band
197  double transition_width, // Hz width of transition band
198  double attenuation_dB, // out of band attenuation dB
199  win_type window = WIN_HAMMING,
200  double beta = 6.76); // used only with Kaiser
201 
202  /*!
203  * \brief Use the "window method" to design a complex band-pass FIR
204  * filter. The normalized width of the transition band is what sets the
205  * number of taps required. Narrow --> more taps. The window type
206  * determines maximum attenuation and passband ripple.
207  *
208  * \param gain overall gain of filter (typically 1.0)
209  * \param sampling_freq sampling freq (Hz)
210  * \param low_cutoff_freq center of transition band (Hz)
211  * \param high_cutoff_freq center of transition band (Hz)
212  * \param transition_width width of transition band (Hz)
213  * \param window one of firdes::win_type
214  * \param beta parameter for Kaiser window
215  */
216  static std::vector<gr_complex>
217  complex_band_pass(double gain,
218  double sampling_freq,
219  double low_cutoff_freq, // Hz center of transition band
220  double high_cutoff_freq, // Hz center of transition band
221  double transition_width, // Hz width of transition band
222  win_type window = WIN_HAMMING,
223  double beta = 6.76); // used only with Kaiser
224 
225  /*!
226  * \brief Use "window method" to design a complex band-pass FIR filter.
227  * The normalized width of the transition band and the required stop band
228  * attenuation is what sets the number of taps required. Narrow --> more
229  * taps More attenuation --> more taps. Window type determines maximum
230  * attenuation and passband ripple.
231  *
232  * \param gain overall gain of filter (typically 1.0)
233  * \param sampling_freq sampling freq (Hz)
234  * \param low_cutoff_freq center of transition band (Hz)
235  * \param high_cutoff_freq center of transition band (Hz)
236  * \param transition_width width of transition band (Hz)
237  * \param attenuation_dB out of band attenuation
238  * \param window one of firdes::win_type
239  * \param beta parameter for Kaiser window
240  */
241  static std::vector<gr_complex>
242  complex_band_pass_2(double gain,
243  double sampling_freq,
244  double low_cutoff_freq, // Hz beginning transition band
245  double high_cutoff_freq, // Hz beginning transition band
246  double transition_width, // Hz width of transition band
247  double attenuation_dB, // out of band attenuation dB
248  win_type window = WIN_HAMMING,
249  double beta = 6.76); // used only with Kaiser
250 
251  /*!
252  * \brief Use "window method" to design a band-reject FIR filter. The
253  * normalized width of the transition band is what sets the number of
254  * taps required. Narrow --> more taps. Window type determines maximum
255  * attenuation and passband ripple.
256  *
257  * \param gain overall gain of filter (typically 1.0)
258  * \param sampling_freq sampling freq (Hz)
259  * \param low_cutoff_freq center of transition band (Hz)
260  * \param high_cutoff_freq center of transition band (Hz)
261  * \param transition_width width of transition band (Hz)
262  * \param window one of firdes::win_type
263  * \param beta parameter for Kaiser window
264  */
265  static std::vector<float>
266  band_reject(double gain,
267  double sampling_freq,
268  double low_cutoff_freq, // Hz center of transition band
269  double high_cutoff_freq, // Hz center of transition band
270  double transition_width, // Hz width of transition band
271  win_type window = WIN_HAMMING,
272  double beta = 6.76); // used only with Kaiser
273 
274  /*!
275  * \brief Use "window method" to design a band-reject FIR filter. The
276  * normalized width of the transition band and the required stop band
277  * attenuation is what sets the number of taps required. Narrow --> more
278  * taps More attenuation --> more taps. Window type determines maximum
279  * attenuation and passband ripple.
280  *
281  * \param gain overall gain of filter (typically 1.0)
282  * \param sampling_freq sampling freq (Hz)
283  * \param low_cutoff_freq center of transition band (Hz)
284  * \param high_cutoff_freq center of transition band (Hz)
285  * \param transition_width width of transition band (Hz).
286  * \param attenuation_dB out of band attenuation
287  * \param window one of firdes::win_type
288  * \param beta parameter for Kaiser window
289  */
290  static std::vector<float>
291  band_reject_2(double gain,
292  double sampling_freq,
293  double low_cutoff_freq, // Hz beginning transition band
294  double high_cutoff_freq, // Hz beginning transition band
295  double transition_width, // Hz width of transition band
296  double attenuation_dB, // out of band attenuation dB
297  win_type window = WIN_HAMMING,
298  double beta = 6.76); // used only with Kaiser
299 
300  /*!\brief design a Hilbert Transform Filter
301  *
302  * \param ntaps number of taps, must be odd
303  * \param windowtype one kind of firdes::win_type
304  * \param beta parameter for Kaiser window
305  */
306  static std::vector<float> 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> gaussian(double gain,
335  double spb,
336  double bt, // Bandwidth to bitrate ratio
337  int ntaps);
338 
339 private:
340  static double bessi0(double x);
341  static void sanity_check_1f(double sampling_freq, double f1, double transition_width);
342  static void
343  sanity_check_2f(double sampling_freq, double f1, double f2, double transition_width);
344  static void sanity_check_2f_c(double sampling_freq,
345  double f1,
346  double f2,
347  double transition_width);
348 
349  static int compute_ntaps(double sampling_freq,
350  double transition_width,
351  win_type window_type,
352  double beta);
353 
354  static int compute_ntaps_windes(double sampling_freq,
355  double transition_width,
356  double attenuation_dB);
357 };
358 
359 } /* namespace filter */
360 } /* namespace gr */
361 
362 #endif /* _FILTER_FIRDES_H_ */
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
Finite Impulse Response (FIR) filter design functions.
Definition: firdes.h:40
#define FILTER_API
Definition: gr-filter/include/gnuradio/filter/api.h:30
win_type
Definition: firdes.h:45