MCPcopy Create free account
hub / github.com/numpy/numpy / hamming

Function hamming

numpy/lib/function_base.py:3238–3339  ·  view source on GitHub ↗

Return the Hamming window. The Hamming 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 The

(M)

Source from the content-addressed store, hash-verified

3236
3237@set_module('numpy')
3238def hamming(M):
3239 """
3240 Return the Hamming window.
3241
3242 The Hamming window is a taper formed by using a weighted cosine.
3243
3244 Parameters
3245 ----------
3246 M : int
3247 Number of points in the output window. If zero or less, an
3248 empty array is returned.
3249
3250 Returns
3251 -------
3252 out : ndarray
3253 The window, with the maximum value normalized to one (the value
3254 one appears only if the number of samples is odd).
3255
3256 See Also
3257 --------
3258 bartlett, blackman, hanning, kaiser
3259
3260 Notes
3261 -----
3262 The Hamming window is defined as
3263
3264 .. math:: w(n) = 0.54 - 0.46\\cos\\left(\\frac{2\\pi{n}}{M-1}\\right)
3265 \\qquad 0 \\leq n \\leq M-1
3266
3267 The Hamming was named for R. W. Hamming, an associate of J. W. Tukey
3268 and is described in Blackman and Tukey. It was recommended for
3269 smoothing the truncated autocovariance function in the time domain.
3270 Most references to the Hamming window come from the signal processing
3271 literature, where it is used as one of many windowing functions for
3272 smoothing values. It is also known as an apodization (which means
3273 "removing the foot", i.e. smoothing discontinuities at the beginning
3274 and end of the sampled signal) or tapering function.
3275
3276 References
3277 ----------
3278 .. [1] Blackman, R.B. and Tukey, J.W., (1958) The measurement of power
3279 spectra, Dover Publications, New York.
3280 .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", The
3281 University of Alberta Press, 1975, pp. 109-110.
3282 .. [3] Wikipedia, "Window function",
3283 https://en.wikipedia.org/wiki/Window_function
3284 .. [4] W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling,
3285 "Numerical Recipes", Cambridge University Press, 1986, page 425.
3286
3287 Examples
3288 --------
3289 >>> np.hamming(12)
3290 array([ 0.08 , 0.15302337, 0.34890909, 0.60546483, 0.84123594, # may vary
3291 0.98136677, 0.98136677, 0.84123594, 0.60546483, 0.34890909,
3292 0.15302337, 0.08 ])
3293
3294 Plot the window and the frequency response:
3295

Callers 1

test_hammingMethod · 0.90

Calls 4

onesFunction · 0.90
arangeFunction · 0.85
cosFunction · 0.85
arrayFunction · 0.50

Tested by 1

test_hammingMethod · 0.72