本文簡要介紹 python 語言中 numpy.hanning
的用法。
用法:
numpy.hanning(M)
返回漢寧窗口。
漢寧窗是使用加權餘弦形成的錐度。
- M: int
輸出窗口中的點數。如果為零或更小,則返回一個空數組。
- out: ndarray,形狀(M,)
最大值歸一化為 1 的窗口(僅當 M 為奇數時才會出現值 1)。
參數:
返回:
注意:
漢寧窗定義為
Hanning 以奧地利氣象學家 Julius von Hann 的名字命名。它也被稱為餘弦鍾。一些作者更喜歡將其稱為 Hann 窗,以幫助避免與非常相似的 Hamming 窗混淆。
大多數對漢寧窗的引用來自信號處理文獻,它被用作平滑值的許多窗函數之一。它也被稱為變跡(表示“removing the foot”,即平滑采樣信號開始和結束處的不連續性)或錐形函數。
參考:
Blackman, R.B. 和 Tukey, J.W.,(1958) 功率譜的測量,Dover Publications,紐約。
E.R. Kanasewich,“地球物理學中的時間序列分析”,阿爾伯塔大學出版社,1975 年,第 106-108 頁。
維基百科,“Window function”,https://en.wikipedia.org/wiki/Window_function
W.H.出版社,B.P. Flannery、S.A. Teukolsky 和 W.T. Vetterling,“Numerical Recipes”,劍橋大學出版社,1986 年,第 425 頁。
1:
2:
3:
4:
例子:
>>> np.hanning(12) array([0. , 0.07937323, 0.29229249, 0.57115742, 0.82743037, 0.97974649, 0.97974649, 0.82743037, 0.57115742, 0.29229249, 0.07937323, 0. ])
繪製窗口及其頻率響應:
>>> import matplotlib.pyplot as plt >>> from numpy.fft import fft, fftshift >>> window = np.hanning(51) >>> plt.plot(window) [<matplotlib.lines.Line2D object at 0x...>] >>> plt.title("Hann window") Text(0.5, 1.0, 'Hann window') >>> plt.ylabel("Amplitude") Text(0, 0.5, 'Amplitude') >>> plt.xlabel("Sample") Text(0.5, 0, 'Sample') >>> plt.show()
>>> plt.figure() <Figure size 640x480 with 0 Axes> >>> A = fft(window, 2048) / 25.5 >>> mag = np.abs(fftshift(A)) >>> freq = np.linspace(-0.5, 0.5, len(A)) >>> with np.errstate(divide='ignore', invalid='ignore'): ... response = 20 * np.log10(mag) ... >>> response = np.clip(response, -100, 100) >>> plt.plot(freq, response) [<matplotlib.lines.Line2D object at 0x...>] >>> plt.title("Frequency response of the Hann window") Text(0.5, 1.0, 'Frequency response of the Hann window') >>> plt.ylabel("Magnitude [dB]") Text(0, 0.5, 'Magnitude [dB]') >>> plt.xlabel("Normalized frequency [cycles per sample]") Text(0.5, 0, 'Normalized frequency [cycles per sample]') >>> plt.axis('tight') ... >>> plt.show()
相關用法
- Python numpy hamming用法及代碼示例
- Python numpy hermite.hermfromroots用法及代碼示例
- Python numpy hermite_e.hermediv用法及代碼示例
- Python numpy hsplit用法及代碼示例
- Python numpy hermite.hermline用法及代碼示例
- Python numpy hermite.hermpow用法及代碼示例
- Python numpy hermite.hermx用法及代碼示例
- Python numpy hermite_e.hermefromroots用法及代碼示例
- Python numpy hermite.hermmul用法及代碼示例
- Python numpy hermite.herm2poly用法及代碼示例
- Python numpy hermite.hermsub用法及代碼示例
- Python numpy hermite_e.hermeline用法及代碼示例
- Python numpy hermite_e.hermeint用法及代碼示例
- Python numpy hermite_e.hermeadd用法及代碼示例
- Python numpy hstack用法及代碼示例
- Python numpy hermite_e.poly2herme用法及代碼示例
- Python numpy hermite.hermdiv用法及代碼示例
- Python numpy hermite_e.hermevander用法及代碼示例
- Python numpy hermite_e.hermepow用法及代碼示例
- Python numpy hermite.poly2herm用法及代碼示例
- Python numpy hermite_e.hermetrim用法及代碼示例
- Python numpy hermite_e.hermezero用法及代碼示例
- Python numpy hermite.hermdomain用法及代碼示例
- Python numpy hermite_e.hermex用法及代碼示例
- Python numpy hypot用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.hanning。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。