Python | Blackman in NumPy

NumPy | Python Methods and Functions

Blackman Window: is a cone formed using the first three terms of the sum of the cosines. It has been designed to have almost the lowest possible leakage. This is close to optimal, only slightly worse than the 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

Window with maximum value normalized to one (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 () 

Exit:

,

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 (m ag)

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 ()

Exit: 

,



Get Solution for free from DataCamp guru