 # Hanning at Numpy | python

Hanning Window — it is a weighted cosine cone.

`  Syntax:  numpy.hamming (M)  Parameters:   M:  Number of points in the output window.  Returns:  AN array `

Window with maximum value normalized to one (value one appears only if M is odd).

Code # 1 :

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

Exit:

` [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 a window plot and its frequency response (requires SciPy and matplot

p>

 ` 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 & amp; quot "` `) ` ` 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: 