numpy.hanning()的使用

用途:

  • 这是numpy库中比较常见的函数,它生成余弦窗函数或者高斯函数,用于过滤或者突出某个物体。
  • 输入参数:M.
    -输出:一行M列的向量

代码示例1:

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


在这里插入图片描述

输出:

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.    

代码示例2:


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

输出:

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

猜你喜欢

转载自blog.csdn.net/qq_38978225/article/details/130422010