Bartlett窗口與三角形窗口非常相似,不同之處在於端點為零。它通常用於信號處理中以使信號逐漸變細,而不會在頻域中產生過多的紋波。
Parameters(numpy.bartlett(M)): M:int Number of points in the output window. If zero or less, an empty array is returned. 返回: out:array
最大值標準化為1的三角形窗口(僅當樣本數為奇數時才出現值1),第一個和最後一個樣本等於零。
例:
import numpy as np
print(np.bartlett(12))
輸出:
[ 0. 0.18181818 0.36363636 0.54545455 0.72727273 0.90909091 0.90909091 0.72727273 0.54545455 0.36363636 0.18181818 0. ]
繪製窗口及其頻率響應(需要SciPy和matplotlib):
對於窗口:
import numpy as np
import matplotlib.pyplot as plt
from numpy.fft import fft, fftshift
window = np.bartlett(51)
plt.plot(window)
plt.title("Bartlett 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.bartlett(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 Bartlett window")
plt.ylabel("Magnitude [dB]")
plt.xlabel("Normalized frequency [cycles per sample]")
plt.axis('tight')
plt.show()
輸出:
相關用法
- Python Numpy numpy.ndarray.__mod__()用法及代碼示例
- Python Numpy numpy.ndarray.__divmod__()用法及代碼示例
- Python Numpy numpy.ndarray.__floordiv__()用法及代碼示例
- Python Numpy numpy.ndarray.__invert__()用法及代碼示例
- Python Numpy numpy.ndarray.__or__()用法及代碼示例
- Python Numpy numpy.ndarray.__sub__()用法及代碼示例
- Python Numpy numpy.ndarray.__lshift__()用法及代碼示例
- Python Numpy numpy.ndarray.__rshift__()用法及代碼示例
- Python Numpy numpy.ndarray.__pow__()用法及代碼示例
- Python Numpy numpy.ndarray.__eq__()用法及代碼示例
- Python Numpy numpy.ndarray.__ge__()用法及代碼示例
- Python Numpy numpy.ndarray.__le__()用法及代碼示例
- Python Numpy numpy.ndarray.__gt__()用法及代碼示例
- Python Numpy numpy.ndarray.__ne__()用法及代碼示例
- Python Numpy numpy.ndarray.__neg__()用法及代碼示例
注:本文由純淨天空篩選整理自RituRajSingh7大神的英文原創作品 numpy bartlett() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。