Saturday, October 25, 2025
HomeLanguagesPython | Blackman in numpy

Python | Blackman in numpy

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:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS