我有代码可以平滑列中的一些加速度计x,y,z值(玩具数据):
import numpy as np
import pandas as pd
from scipy.interpolate import make_interp_spline, BSpline
idx = [1,2,3,4]
ts_length = 200
idx = np.array(idx,dtype=int)
accel = [[-0.7437,0.1118,-0.5367],
[-0.5471,0.0062,-0.6338],
[-0.7437,0.1216,-0.5255],
[-0.4437,0.3216,-0.3255],
]
print(accel)
accel = np.array(accel,dtype=float)
accel_sm = np.zeros([ts_length,3])
idxnew = np.linspace(idx.min(), idx.max(), ts_length)
for i in range (0,3):
c = accel[:,i]
spl = make_interp_spline(idx, c, k=3)
c_smooth = spl(idxnew)
accel_sm[:, i] = c_smooth
print(accel_sm)
我只是随便选了ts_length = 200,因为我只是想让这个例子工作。但我在想是否有经验法则来确定它相对于len(idx)应该有多大,才能在不使平滑数组变得不必要的大的情况下做好平滑工作?
1条答案
按热度按时间k0pti3hp1#
make_interp_spline不进行任何平滑,其结果通过数据。
要进行平滑,请使用make_smoothing_spline或splrep。