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