使用 SavitzkyGolay 过滤器
给出一个嘈杂的信号:
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1)
x = np.linspace(0,2*np.pi,100)
y = np.sin(x) + np.random.random(100) * 0.2
plt.plot(x,y)
plt.show()
可以使用 scipy.signal.savgol_filter()
方法使用 Savitzky-Golay 过滤器来平滑它 :
import scipy.signal
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1)
x = np.linspace(0,2*np.pi,100)
y = np.sin(x) + np.random.random(100) * 0.2
yhat = scipy.signal.savgol_filter(y, 51, 3) # window size 51, polynomial order 3
plt.plot(x,y)
plt.plot(x,yhat, color='red')
plt.show()