Use of numpy.hanning()

use:

  • This is a common function in the numpy library. It generates a cosine window function or a Gaussian function, which is used to filter or highlight an object.
  • Input parameters: M.
    -Output: vector of one row and M columns

Code example 1:

#numpy.hanning
import numpy as np
import matplotlib.pyplot as plt
window=np.hanning(50)
print('w2:',window)
plt.plot(window)
plt.show()


Insert image description here

Output:

w2: [0.         0.00410499 0.01635257 0.03654162 0.06434065 0.09929319
 0.14082532 0.1882551  0.24080372 0.29760833 0.35773621 0.42020005
 0.48397421 0.54801151 0.61126047 0.67268253 0.73126915 0.78605833
 0.83615045 0.88072298 0.91904405 0.95048443 0.97452787 0.99077958
 0.9989727  0.9989727  0.99077958 0.97452787 0.95048443 0.91904405
 0.88072298 0.83615045 0.78605833 0.73126915 0.67268253 0.61126047
 0.54801151 0.48397421 0.42020005 0.35773621 0.29760833 0.24080372
 0.1882551  0.14082532 0.09929319 0.06434065 0.03654162 0.01635257
 0.00410499 0.    

Code example 2:


import  numpy as np
window_len=50
window = 'hanning'
w1 = getattr(np, window)(window_len)
print('w1:',w1)

Output:

w1: [0.         0.00410499 0.01635257 0.03654162 0.06434065 0.09929319
 0.14082532 0.1882551  0.24080372 0.29760833 0.35773621 0.42020005
 0.48397421 0.54801151 0.61126047 0.67268253 0.73126915 0.78605833
 0.83615045 0.88072298 0.91904405 0.95048443 0.97452787 0.99077958
 0.9989727  0.9989727  0.99077958 0.97452787 0.95048443 0.91904405
 0.88072298 0.83615045 0.78605833 0.73126915 0.67268253 0.61126047
 0.54801151 0.48397421 0.42020005 0.35773621 0.29760833 0.24080372
 0.1882551  0.14082532 0.09929319 0.06434065 0.03654162 0.01635257
 0.00410499 0.        ]

Process finished with exit code 0

Guess you like

Origin blog.csdn.net/qq_38978225/article/details/130422010