Return the Hanning window. The Hanning window is a taper formed by using a weighted cosine. Parameters ---------- M : int Number of points in the output window. If zero or less, an empty array is returned. Returns ------- out : ndarray, shape(M,)
(M)
| 3127 | |
| 3128 | @set_module('numpy') |
| 3129 | def hanning(M): |
| 3130 | """ |
| 3131 | Return the Hanning window. |
| 3132 | |
| 3133 | The Hanning window is a taper formed by using a weighted cosine. |
| 3134 | |
| 3135 | Parameters |
| 3136 | ---------- |
| 3137 | M : int |
| 3138 | Number of points in the output window. If zero or less, an |
| 3139 | empty array is returned. |
| 3140 | |
| 3141 | Returns |
| 3142 | ------- |
| 3143 | out : ndarray, shape(M,) |
| 3144 | The window, with the maximum value normalized to one (the value |
| 3145 | one appears only if `M` is odd). |
| 3146 | |
| 3147 | See Also |
| 3148 | -------- |
| 3149 | bartlett, blackman, hamming, kaiser |
| 3150 | |
| 3151 | Notes |
| 3152 | ----- |
| 3153 | The Hanning window is defined as |
| 3154 | |
| 3155 | .. math:: w(n) = 0.5 - 0.5\\cos\\left(\\frac{2\\pi{n}}{M-1}\\right) |
| 3156 | \\qquad 0 \\leq n \\leq M-1 |
| 3157 | |
| 3158 | The Hanning was named for Julius von Hann, an Austrian meteorologist. |
| 3159 | It is also known as the Cosine Bell. Some authors prefer that it be |
| 3160 | called a Hann window, to help avoid confusion with the very similar |
| 3161 | Hamming window. |
| 3162 | |
| 3163 | Most references to the Hanning window come from the signal processing |
| 3164 | literature, where it is used as one of many windowing functions for |
| 3165 | smoothing values. It is also known as an apodization (which means |
| 3166 | "removing the foot", i.e. smoothing discontinuities at the beginning |
| 3167 | and end of the sampled signal) or tapering function. |
| 3168 | |
| 3169 | References |
| 3170 | ---------- |
| 3171 | .. [1] Blackman, R.B. and Tukey, J.W., (1958) The measurement of power |
| 3172 | spectra, Dover Publications, New York. |
| 3173 | .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", |
| 3174 | The University of Alberta Press, 1975, pp. 106-108. |
| 3175 | .. [3] Wikipedia, "Window function", |
| 3176 | https://en.wikipedia.org/wiki/Window_function |
| 3177 | .. [4] W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling, |
| 3178 | "Numerical Recipes", Cambridge University Press, 1986, page 425. |
| 3179 | |
| 3180 | Examples |
| 3181 | -------- |
| 3182 | >>> np.hanning(12) |
| 3183 | array([0. , 0.07937323, 0.29229249, 0.57115742, 0.82743037, |
| 3184 | 0.97974649, 0.97974649, 0.82743037, 0.57115742, 0.29229249, |
| 3185 | 0.07937323, 0. ]) |
| 3186 |