GNU Radio Manual and C++ API Reference  3.7.13.4
The Free & Open Software Radio Ecosystem
window.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002,2007,2008,2012,2013 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 INCLUDED_FFT_WINDOW_H
24 #define INCLUDED_FFT_WINDOW_H
25 
26 #include <gnuradio/fft/api.h>
27 #include <vector>
28 #include <cmath>
29 #include <gnuradio/gr_complex.h>
30 
31 namespace gr {
32  namespace fft {
33 
34  class FFT_API window {
35  public:
36 
37  enum win_type {
38  WIN_HAMMING = 0, //!< Hamming window; max attenuation 53 dB
39  WIN_HANN = 1, //!< Hann window; max attenuation 44 dB
40  WIN_BLACKMAN = 2, //!< Blackman window; max attenuation 74 dB
41  WIN_RECTANGULAR = 3, //!< Basic rectangular window; max attenuation 21 dB
42  WIN_KAISER = 4, //!< Kaiser window; max attenuation see window::max_attenuation
43  WIN_BLACKMAN_hARRIS = 5, //!< Blackman-harris window; max attenuation 92 dB
44  WIN_BLACKMAN_HARRIS = 5, //!< alias to WIN_BLACKMAN_hARRIS for capitalization consistency
45  WIN_BARTLETT = 6, //!< Barlett (triangular) window; max attenuation 26 dB
46  WIN_FLATTOP = 7, //!< flat top window; useful in FFTs; max attenuation 93 dB
47  };
48 
49  /*!
50  * \brief Given a window::win_type, this tells you the maximum
51  * attenuation you can expect.
52  *
53  * \details
54  * For most windows, this is a set value. For the Kaiser window,
55  * the attenuation is based on the value of beta. The actual
56  * relationship is a piece-wise exponential relationship to
57  * calculate beta from the desired attenuation and can be found
58  * on page 542 of Oppenheim and Schafer (Discrete-Time Signal
59  * Processing, 3rd edition). To simplify this function to solve
60  * for A given beta, we use a linear form that is exact for
61  * attenuation >= 50 dB.
62  *
63  * For an attenuation of 50 dB, beta = 4.55.
64  *
65  * For an attenuation of 70 dB, beta = 6.76.
66  *
67  * \param type The window::win_type enumeration of the window type.
68  * \param beta Beta value only used for the Kaiser window.
69  */
70  static double max_attenuation(win_type type, double beta=6.76);
71 
72  /*!
73  * \brief Helper function to build cosine-based windows. 3-coefficient version.
74  */
75  static std::vector<float> coswindow(int ntaps, float c0, float c1, float c2);
76 
77  /*!
78  * \brief Helper function to build cosine-based windows. 4-coefficient version.
79  */
80  static std::vector<float> coswindow(int ntaps, float c0, float c1, float c2, float c3);
81 
82  /*!
83  * \brief Helper function to build cosine-based windows. 5-coefficient version.
84  */
85  static std::vector<float> coswindow(int ntaps, float c0, float c1, float c2, float c3, float c4);
86 
87  /*!
88  * \brief Build a rectangular window.
89  *
90  * Taps are flat across the window.
91  *
92  * \param ntaps Number of coefficients in the window.
93  */
94  static std::vector<float> rectangular(int ntaps);
95 
96  /*!
97  * \brief Build a Hamming window.
98  *
99  * See:
100  * <pre>
101  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
102  * Signal Processing," Upper Saddle River, N.J.: Prentice
103  * Hall, 2010, pp. 535-538.
104  * </pre>
105  *
106  * \param ntaps Number of coefficients in the window.
107  */
108  static std::vector<float> hamming(int ntaps);
109 
110  /*!
111  * \brief Build a Hann window (sometimes known as Hanning).
112  *
113  * See:
114  * <pre>
115  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
116  * Signal Processing," Upper Saddle River, N.J.: Prentice
117  * Hall, 2010, pp. 535-538.
118  * </pre>
119  *
120  * \param ntaps Number of coefficients in the window.
121  */
122  static std::vector<float> hann(int ntaps);
123 
124  /*!
125  * \brief Alias to build a Hann window.
126  *
127  * \param ntaps Number of coefficients in the window.
128  */
129  static std::vector<float> hanning(int ntaps);
130 
131  /*!
132  * \brief Build an exact Blackman window.
133  *
134  * See:
135  * <pre>
136  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
137  * Signal Processing," Upper Saddle River, N.J.: Prentice
138  * Hall, 2010, pp. 535-538.
139  * </pre>
140  *
141  * \param ntaps Number of coefficients in the window.
142  */
143  static std::vector<float> blackman(int ntaps);
144 
145  /*!
146  * \brief Build Blackman window, variation 1.
147  */
148  static std::vector<float> blackman2(int ntaps);
149 
150  /*!
151  * \brief Build Blackman window, variation 2.
152  */
153  static std::vector<float> blackman3(int ntaps);
154 
155  /*!
156  * \brief Build Blackman window, variation 3.
157  */
158  static std::vector<float> blackman4(int ntaps);
159 
160  /*!
161  * \brief Build a Blackman-harris window with a given attenuation.
162  *
163  * <pre>
164  * f. j. harris, "On the use of windows for harmonic analysis
165  * with the discrete Fourier transforms," Proc. IEEE, Vol. 66,
166  * ppg. 51-83, Jan. 1978.
167  * </pre>
168  *
169  * \param ntaps Number of coefficients in the window.
170 
171  * \param atten Attenuation factor. Must be [61, 67, 74, 92].
172  * See the above paper for details.
173  */
174  static std::vector<float> blackman_harris(int ntaps, int atten=92);
175 
176  /*!
177  * Alias to gr::fft::window::blakcman_harris.
178  */
179  static std::vector<float> blackmanharris(int ntaps, int atten=92);
180 
181  /*!
182  * \brief Build a Nuttall (or Blackman-Nuttall) window.
183  *
184  * See: http://en.wikipedia.org/wiki/Window_function#Blackman.E2.80.93Nuttall_window
185  *
186  * \param ntaps Number of coefficients in the window.
187  */
188  static std::vector<float> nuttall(int ntaps);
189 
190  /*!
191  * Deprecated: use nuttall window instead.
192  */
193  static std::vector<float> nuttal(int ntaps);
194 
195  /*!
196  * \brief Alias to the Nuttall window.
197  *
198  * \param ntaps Number of coefficients in the window.
199  */
200  static std::vector<float> blackman_nuttall(int ntaps);
201 
202  /*!
203  * Deprecated: use blackman_nuttall window instead.
204  */
205  static std::vector<float> blackman_nuttal(int ntaps);
206 
207  /*!
208  * \brief Build a Nuttall continuous first derivative window.
209  *
210  * See: http://en.wikipedia.org/wiki/Window_function#Nuttall_window.2C_continuous_first_derivative
211  *
212  * \param ntaps Number of coefficients in the window.
213  */
214  static std::vector<float> nuttall_cfd(int ntaps);
215 
216  /*!
217  * Deprecated: use nuttall_cfd window instead.
218  */
219  static std::vector<float> nuttal_cfd(int ntaps);
220 
221  /*!
222  * \brief Build a flat top window.
223  *
224  * See: http://en.wikipedia.org/wiki/Window_function#Flat_top_window
225  *
226  * \param ntaps Number of coefficients in the window.
227  */
228  static std::vector<float> flattop(int ntaps);
229 
230  /*!
231  * \brief Build a Kaiser window with a given beta.
232  *
233  * See:
234  * <pre>
235  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
236  * Signal Processing," Upper Saddle River, N.J.: Prentice
237  * Hall, 2010, pp. 541-545.
238  * </pre>
239  *
240  * \param ntaps Number of coefficients in the window.
241  * \param beta Shaping parameter of the window. See the
242  * discussion in Oppenheim and Schafer.
243  */
244  static std::vector<float> kaiser(int ntaps, double beta);
245 
246  /*!
247  * \brief Build a Barlett (triangular) window.
248  *
249  * See:
250  * <pre>
251  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
252  * Signal Processing," Upper Saddle River, N.J.: Prentice
253  * Hall, 2010, pp. 535-538.
254  * </pre>
255  *
256  * \param ntaps Number of coefficients in the window.
257  */
258  static std::vector<float> bartlett(int ntaps);
259 
260  static std::vector<float> welch(int ntaps);
261 
262  /*!
263  * \brief Build a Parzen (or de la Valle-Poussin) window.
264  *
265  * See:
266  * <pre>
267  * A. D. Poularikas, "Handbook of Formulas and Tables for
268  * Signal Processing," Springer, Oct 28, 1998
269  * </pre>
270  *
271  * \param ntaps Number of coefficients in the window.
272  */
273  static std::vector<float> parzen(int ntaps);
274 
275  /*!
276  * \brief Build an exponential window with a given decay.
277  *
278  * See: http://en.wikipedia.org/wiki/Window_function#Exponential_or_Poisson_window
279  *
280  * \param ntaps Number of coefficients in the window.
281  * \param d Decay of \p d dB over half the window length.
282  */
283  static std::vector<float> exponential(int ntaps, double d);
284 
285  /*!
286  * \brief Build a Riemann window.
287  *
288  * See:
289  * <pre>
290  * A. D. Poularikas, "Handbook of Formulas and Tables for
291  * Signal Processing," Springer, Oct 28, 1998
292  * </pre>
293  *
294  * \param ntaps Number of coefficients in the window.
295  */
296  static std::vector<float> riemann(int ntaps);
297 
298  /*!
299  * \brief Build a window using gr::fft::win_type to index the
300  * type of window desired.
301  *
302  * \param type a gr::fft::win_type index for the type of window.
303  * \param ntaps Number of coefficients in the window.
304  * \param beta Used only for building Kaiser windows.
305  */
306  static std::vector<float> build(win_type type, int ntaps, double beta);
307  };
308 
309  } /* namespace fft */
310 } /* namespace gr */
311 
312 #endif /* INCLUDED_FFT_WINDOW_H */
Definition: window.h:34
#define FFT_API
Definition: gr-fft/include/gnuradio/fft/api.h:30
Include this header to use the message passing features.
Definition: logger.h:695
win_type
Definition: window.h:37