# Hanning in Numpy | Python

The Hanning window is a taper formed by using a weighted cosine.

```Syntax:  numpy.hamming(M)

Parameters:
M :  Number of points in the output window.

Returns:  AN array```

The window, with the maximum value normalized to one (the value one appears only if M is odd).

Code #1:

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

Output:

```[ 0.          0.07937323  0.29229249  0.57115742  0.82743037  0.97974649
0.97974649  0.82743037  0.57115742  0.29229249  0.07937323  0.        ]
```

Code #2: Plotting the window and its frequency response (requires SciPy and matplotlib).

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

Output: For frequency:

 `import` `numpy as np ` `import` `matplotlib.pyplot as plt ` `from` `numpy.fft ``import` `fft, fftshift ` ` `  `window ``=` `np.hanning(``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 Hanning window"``) ` `plt.ylabel(``"Magnitude [dB]"``) ` `plt.xlabel(``"Normalized frequency [cycles per sample]"``) ` `plt.axis(``"tight"``) ` `plt.show() `

Output: 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.