GNU Radio Manual and C++ API Reference  3.7.2.1
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_NONE = -1, //!< don't use a window
39  WIN_HAMMING = 0, //!< Hamming window; max attenuation 53 dB
40  WIN_HANN = 1, //!< Hann window; max attenuation 44 dB
41  WIN_BLACKMAN = 2, //!< Blackman window; max attenuation 74 dB
42  WIN_RECTANGULAR = 3, //!< Basic rectangular window
43  WIN_KAISER = 4, //!< Kaiser window; max attenuation a function of beta, google it
44  WIN_BLACKMAN_hARRIS = 5, //!< Blackman-harris window
45  WIN_BLACKMAN_HARRIS = 5, //!< alias to WIN_BLACKMAN_hARRIS for capitalization consistency
46  WIN_BARTLETT = 6, //!< Barlett (triangular) window
47  WIN_FLATTOP = 7, //!< flat top window; useful in FFTs
48  };
49 
50  /*!
51  * \brief Helper function to build cosine-based windows. 3-coefficient version.
52  */
53  static std::vector<float> coswindow(int ntaps, float c0, float c1, float c2);
54 
55  /*!
56  * \brief Helper function to build cosine-based windows. 4-coefficient version.
57  */
58  static std::vector<float> coswindow(int ntaps, float c0, float c1, float c2, float c3);
59 
60  /*!
61  * \brief Helper function to build cosine-based windows. 5-coefficient version.
62  */
63  static std::vector<float> coswindow(int ntaps, float c0, float c1, float c2, float c3, float c4);
64 
65  /*!
66  * \brief Build a rectangular window.
67  *
68  * Taps are flat across the window.
69  *
70  * \param ntaps Number of coefficients in the window.
71  */
72  static std::vector<float> rectangular(int ntaps);
73 
74  /*!
75  * \brief Build a Hamming window.
76  *
77  * See:
78  * <pre>
79  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
80  * Signal Processing," Upper Saddle River, N.J.: Prentice
81  * Hall, 2010, pp. 535-538.
82  * </pre>
83  *
84  * \param ntaps Number of coefficients in the window.
85  */
86  static std::vector<float> hamming(int ntaps);
87 
88  /*!
89  * \brief Build a Hann window (sometimes known as Hanning).
90  *
91  * See:
92  * <pre>
93  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
94  * Signal Processing," Upper Saddle River, N.J.: Prentice
95  * Hall, 2010, pp. 535-538.
96  * </pre>
97  *
98  * \param ntaps Number of coefficients in the window.
99  */
100  static std::vector<float> hann(int ntaps);
101 
102  /*!
103  * \brief Alias to build a Hann window.
104  *
105  * \param ntaps Number of coefficients in the window.
106  */
107  static std::vector<float> hanning(int ntaps);
108 
109  /*!
110  * \brief Build an exact Blackman window.
111  *
112  * See:
113  * <pre>
114  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
115  * Signal Processing," Upper Saddle River, N.J.: Prentice
116  * Hall, 2010, pp. 535-538.
117  * </pre>
118  *
119  * \param ntaps Number of coefficients in the window.
120  */
121  static std::vector<float> blackman(int ntaps);
122 
123  /*!
124  * \brief Build Blackman window, variation 1.
125  */
126  static std::vector<float> blackman2(int ntaps);
127 
128  /*!
129  * \brief Build Blackman window, variation 2.
130  */
131  static std::vector<float> blackman3(int ntaps);
132 
133  /*!
134  * \brief Build Blackman window, variation 3.
135  */
136  static std::vector<float> blackman4(int ntaps);
137 
138  /*!
139  * \brief Build a Blackman-harris window with a given attenuation.
140  *
141  * <pre>
142  * f. j. harris, "On the use of windows for harmonic analysis
143  * with the discrete Fourier transforms," Proc. IEEE, Vol. 66,
144  * ppg. 51-83, Jan. 1978.
145  * </pre>
146  *
147  * \param ntaps Number of coefficients in the window.
148 
149  * \param atten Attenuation factor. Must be [61, 67, 74, 92].
150  * See the above paper for details.
151  */
152  static std::vector<float> blackman_harris(int ntaps, int atten=92);
153 
154  /*!
155  * Alias to gr::fft::window::blakcman_harris.
156  */
157  static std::vector<float> blackmanharris(int ntaps, int atten=92);
158 
159  /*!
160  * \brief Build a Nuttal (or Blackman-Nuttal) window.
161  *
162  * See: http://en.wikipedia.org/wiki/Window_function#Blackman.E2.80.93Nuttall_window
163  *
164  * \param ntaps Number of coefficients in the window.
165  */
166  static std::vector<float> nuttal(int ntaps);
167 
168  /*!
169  * \brief Alias to the Nuttal window.
170  *
171  * \param ntaps Number of coefficients in the window.
172  */
173  static std::vector<float> blackman_nuttal(int ntaps);
174 
175  /*!
176  * \brief Build a Nuttal continuous first derivative window.
177  *
178  * See: http://en.wikipedia.org/wiki/Window_function#Nuttall_window.2C_continuous_first_derivative
179  *
180  * \param ntaps Number of coefficients in the window.
181  */
182  static std::vector<float> nuttal_cfd(int ntaps);
183 
184  /*!
185  * \brief Build a Nuttal continuous first derivative window.
186  *
187  * See: http://en.wikipedia.org/wiki/Window_function#Flat_top_window
188  *
189  * \param ntaps Number of coefficients in the window.
190  */
191  static std::vector<float> flattop(int ntaps);
192 
193  /*!
194  * \brief Build a Kaiser window with a given beta.
195  *
196  * See:
197  * <pre>
198  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
199  * Signal Processing," Upper Saddle River, N.J.: Prentice
200  * Hall, 2010, pp. 541-545.
201  * </pre>
202  *
203  * \param ntaps Number of coefficients in the window.
204  * \param beta Shaping parameter of the window. See the
205  * discussion in Oppenheim and Schafer.
206  */
207  static std::vector<float> kaiser(int ntaps, double beta);
208 
209  /*!
210  * \brief Build a Barlett (triangular) window.
211  *
212  * See:
213  * <pre>
214  * A. V. Oppenheim and R. W. Schafer, "Discrete-Time
215  * Signal Processing," Upper Saddle River, N.J.: Prentice
216  * Hall, 2010, pp. 535-538.
217  * </pre>
218  *
219  * \param ntaps Number of coefficients in the window.
220  */
221  static std::vector<float> bartlett(int ntaps);
222 
223  static std::vector<float> welch(int ntaps);
224 
225  /*!
226  * \brief Build a Parzen (or de la Valle-Poussin) window.
227  *
228  * See:
229  * <pre>
230  * A. D. Poularikas, "Handbook of Formulas and Tables for
231  * Signal Processing," Springer, Oct 28, 1998
232  * </pre>
233  *
234  * \param ntaps Number of coefficients in the window.
235  */
236  static std::vector<float> parzen(int ntaps);
237 
238  /*!
239  * \brief Build an exponential window with a given decay.
240  *
241  * See: http://en.wikipedia.org/wiki/Window_function#Exponential_or_Poisson_window
242  *
243  * \param ntaps Number of coefficients in the window.
244  * \param d Decay of \p d dB over half the window length.
245  */
246  static std::vector<float> exponential(int ntaps, double d);
247 
248  /*!
249  * \brief Build a Riemann window.
250  *
251  * See:
252  * <pre>
253  * A. D. Poularikas, "Handbook of Formulas and Tables for
254  * Signal Processing," Springer, Oct 28, 1998
255  * </pre>
256  *
257  * \param ntaps Number of coefficients in the window.
258  */
259  static std::vector<float> riemann(int ntaps);
260 
261  /*!
262  * \brief Build a window using gr::fft::win_type to index the
263  * type of window desired.
264  *
265  * \param type a gr::fft::win_type index for the type of window.
266  * \param ntaps Number of coefficients in the window.
267  * \param beta Used only for building Kaiser windows.
268  */
269  static std::vector<float> build(win_type type, int ntaps, double beta);
270  };
271 
272  } /* namespace fft */
273 } /* namespace gr */
274 
275 #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