Related Articles
Python | Blackman in numpy
• Last Updated : 24 Jun, 2019

Blackman window : It is a taper formed by using the first three terms of a summation of cosines. It was designed to have close to the minimal leakage possible. It is close to optimal, only slightly worse than a Kaiser window.

```Parameters(numpy.blackman):
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.blackman(``12``))`

Output:

```[ -1.38777878e-17   3.26064346e-02   1.59903635e-01   4.14397981e-01
7.36045180e-01   9.67046769e-01   9.67046769e-01   7.36045180e-01
4.14397981e-01   1.59903635e-01   3.26064346e-02  -1.38777878e-17]
```

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

Code : For Window:

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

Output:

.

Code : For frequency:

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

Output:

.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up