def filter(self, X, Y):
if self.interpolate:
X, Y = self.simplefill(X, Y)
else:
X, Y = self.sortxy(X, Y)
order_range = list(range(self.order+1))
half_window = (self.window_size - 1) // 2
# precompute coefficients
b = np.mat([[k**i for i in order_range]
for k in range(-half_window, half_window+1)])
m = np.linalg.pinv(b).A[self.deriv]
# pad the signal at the extremes with
# values taken from the signal itself
firstvals = Y[0] - np.abs(Y[1:half_window+1][::-1] - Y[0])
lastvals = Y[-1] + np.abs(Y[-half_window-1:-1][::-1] - Y[-1])
Y1 = np.concatenate((firstvals, Y, lastvals))
Y2 = np.convolve(m, Y1, mode='valid')
return X, Y2
评论列表
文章目录