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