# Hamming in Numpy

The Hamming window is a taper formed by using a weighted cosine

```Parameters(numpy.hamming(M)):

M : int Number of points in the output window.
If zero or less, an empty array is returned.

Returns:
out : array```

The window, with the maximum value normalized to one (the value one appears only if the number of samples is odd).
Example:

 `import` `numpy as np  ` `print``(np.hamming(``12``)) `

Output:

```[ 0.08        0.15302337  0.34890909  0.60546483  0.84123594  0.98136677
0.98136677  0.84123594  0.60546483  0.34890909  0.15302337  0.08      ]
```

Plotting the window and its frequency response (requires SciPy and matplotlib):
For Window:

 `import` `numpy as np  ` `import` `matplotlib.pyplot as plt  ` `from` `numpy.fft ``import` `fft, fftshift  ` ` `  `window ``=` `np.hamming(``51``) ` ` `  `plt.plot(window)  ` `plt.title(``"Hamming window"``) ` `plt.ylabel(``"Amplitude"``)  ` `plt.xlabel(``"Sample"``)  ` `plt.show()  `

Output: hamming_window

For frequency:

 `import` `numpy as np  ` `import` `matplotlib.pyplot as plt  ` `from` `numpy.fft ``import` `fft, fftshift  ` ` `  `window ``=` `np.hamming(``51``) ` ` `  `plt.figure() ` ` `  `A ``=` `fft(window, ``2048``) ``/` `25.5` `mag ``=` `np.``abs``(fftshift(A)) ` `freq ``=` `np.linspace(``-``0.5``, ``0.5``, ``len``(A)) ` `response ``=` `20` `*` `np.log10(mag) ` `response ``=` `np.clip(response, ``-``100``, ``100``) ` ` `  `plt.plot(freq, response) ` `plt.title(``"Frequency response of Hamming window"``) ` `plt.ylabel(``"Magnitude [dB]"``) ` `plt.xlabel(``"Normalized frequency [cycles per sample]"``) ` `plt.axis(``'tight'``) ` `plt.show() `

Output: hamming_frequency

My Personal Notes arrow_drop_up I am an enthusiast of the opensource who loves for the contribution in python and cpp

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.