scipy.signal.
savgol_coeffs#
- scipy.signal.savgol_coeffs(window_length, polyorder, deriv=0, delta=1.0, pos=None, use='conv')[原始碼]#
計算一維 Savitzky-Golay FIR 濾波器的係數。
- 參數:
- window_lengthint
濾波器視窗的長度(即係數的數量)。
- polyorderint
用於擬合樣本的多項式階數。polyorder 必須小於 window_length。
- derivint,選用
要計算的導數階數。這必須是非負整數。預設值為 0,表示在不微分的情況下篩選資料。
- deltafloat,選用
將套用濾波器的樣本間距。僅當 deriv > 0 時使用。
- posint 或 None,選用
如果 pos 不是 None,則指定視窗內的評估位置。預設值是視窗的中心。
- usestr,選用
可以是 ‘conv’ 或 ‘dot’。此引數選擇係數的順序。預設值為 ‘conv’,表示係數的順序用於卷積。使用 use=’dot’ 時,順序會反轉,因此濾波器是透過將係數與資料集點積來套用。
- 返回:
- coeffs一維 ndarray
濾波器係數。
筆記
在 0.14.0 版本中新增。
參考文獻
A. Savitzky, M. J. E. Golay, Smoothing and Differentiation of Data by Simplified Least Squares Procedures. Analytical Chemistry, 1964, 36 (8), pp 1627-1639. Jianwen Luo, Kui Ying, and Jing Bai. 2005. Savitzky-Golay smoothing and differentiation filter for even number data. Signal Process. 85, 7 (July 2005), 1429-1434.
範例
>>> import numpy as np >>> from scipy.signal import savgol_coeffs >>> savgol_coeffs(5, 2) array([-0.08571429, 0.34285714, 0.48571429, 0.34285714, -0.08571429]) >>> savgol_coeffs(5, 2, deriv=1) array([ 2.00000000e-01, 1.00000000e-01, 2.07548111e-16, -1.00000000e-01, -2.00000000e-01])
請注意,use=’dot’ 只是反轉係數。
>>> savgol_coeffs(5, 2, pos=3) array([ 0.25714286, 0.37142857, 0.34285714, 0.17142857, -0.14285714]) >>> savgol_coeffs(5, 2, pos=3, use='dot') array([-0.14285714, 0.17142857, 0.34285714, 0.37142857, 0.25714286]) >>> savgol_coeffs(4, 2, pos=3, deriv=1, use='dot') array([0.45, -0.85, -0.65, 1.05])
x 包含來自拋物線 x = t**2 的資料,在 t = -1、0、1、2、3 時取樣。c 保留將計算最後位置導數的係數。當與 x 點積時,結果應為 6。
>>> x = np.array([1, 0, 1, 4, 9]) >>> c = savgol_coeffs(5, 2, pos=4, deriv=1, use='dot') >>> c.dot(x) 6.0