GNU Radio Manual and C++ API Reference  3.7.4
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 Nuttal (or Blackman-Nuttal) 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> nuttal(int ntaps);
189 
190  /*!
191  * \brief Alias to the Nuttal window.
192  *
193  * \param ntaps Number of coefficients in the window.
194  */
195  static std::vector<float> blackman_nuttal(int ntaps);
196 
197  /*!
198  * \brief Build a Nuttal continuous first derivative window.
199  *
200  * See: http://en.wikipedia.org/wiki/Window_function#Nuttall_window.2C_continuous_first_derivative
201  *
202  * \param ntaps Number of coefficients in the window.
203  */
204  static std::vector<float> nuttal_cfd(int ntaps);
205 
206  /*!
207  * \brief Build a Nuttal continuous first derivative window.
208  *
209  * See: http://en.wikipedia.org/wiki/Window_function#Flat_top_window
210  *
211  * \param ntaps Number of coefficients in the window.
212  */
213  static std::vector<float> flattop(int ntaps);
214 
215  /*!
216  * \brief Build a Kaiser window with a given beta.
217  *
218  * See:
219  * <pre>
220  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
221  * Signal Processing," Upper Saddle River, N.J.: Prentice
222  * Hall, 2010, pp. 541-545.
223  * </pre>
224  *
225  * \param ntaps Number of coefficients in the window.
226  * \param beta Shaping parameter of the window. See the
227  * discussion in Oppenheim and Schafer.
228  */
229  static std::vector<float> kaiser(int ntaps, double beta);
230 
231  /*!
232  * \brief Build a Barlett (triangular) window.
233  *
234  * See:
235  * <pre>
236  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
237  * Signal Processing," Upper Saddle River, N.J.: Prentice
238  * Hall, 2010, pp. 535-538.
239  * </pre>
240  *
241  * \param ntaps Number of coefficients in the window.
242  */
243  static std::vector<float> bartlett(int ntaps);
244 
245  static std::vector<float> welch(int ntaps);
246 
247  /*!
248  * \brief Build a Parzen (or de la Valle-Poussin) window.
249  *
250  * See:
251  * <pre>
252  * A. D. Poularikas, "Handbook of Formulas and Tables for
253  * Signal Processing," Springer, Oct 28, 1998
254  * </pre>
255  *
256  * \param ntaps Number of coefficients in the window.
257  */
258  static std::vector<float> parzen(int ntaps);
259 
260  /*!
261  * \brief Build an exponential window with a given decay.
262  *
263  * See: http://en.wikipedia.org/wiki/Window_function#Exponential_or_Poisson_window
264  *
265  * \param ntaps Number of coefficients in the window.
266  * \param d Decay of \p d dB over half the window length.
267  */
268  static std::vector<float> exponential(int ntaps, double d);
269 
270  /*!
271  * \brief Build a Riemann window.
272  *
273  * See:
274  * <pre>
275  * A. D. Poularikas, "Handbook of Formulas and Tables for
276  * Signal Processing," Springer, Oct 28, 1998
277  * </pre>
278  *
279  * \param ntaps Number of coefficients in the window.
280  */
281  static std::vector<float> riemann(int ntaps);
282 
283  /*!
284  * \brief Build a window using gr::fft::win_type to index the
285  * type of window desired.
286  *
287  * \param type a gr::fft::win_type index for the type of window.
288  * \param ntaps Number of coefficients in the window.
289  * \param beta Used only for building Kaiser windows.
290  */
291  static std::vector<float> build(win_type type, int ntaps, double beta);
292  };
293 
294  } /* namespace fft */
295 } /* namespace gr */
296 
297 #endif /* INCLUDED_FFT_WINDOW_H */
Definition: window.h:34
#define FFT_API
Definition: gr-fft/include/gnuradio/fft/api.h:30
win_type
Definition: window.h:37