Python| numpy 中的布莱克曼
布莱克曼窗:它是使用余弦和的前三项形成的锥度。它的设计目的是尽可能减少泄漏。它接近于最佳值,仅比 Kaiser 窗口差一点。
Parameters(numpy.blackman):
M : int Number of points in the output window.
If zero or less, an empty array is returned.
Returns:
out : array
最大值归一化为 1 的窗口(仅当样本数为奇数时才会出现值 1)。
例子:
import numpy as np
print(np.blackman(12))
输出:
[ -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]
绘制窗口及其频率响应(需要 SciPy 和 matplotlib):
代码:对于窗口:
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()
输出:
代码:对于频率:
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()
输出: