我试图通过使用 filfilt 滤波器消除信号的趋势(锯齿),但没有得到好的结果。这里是data
core_3 = pd.read_csv(filename_3, sep=";",header=0,index_col = 0,
parse_dates=True, names='date','temp'], infer_datetime_format=True, dayfirst=True)
core_7 = pd.read_csv(filename_7 ,sep=";",header=0,index_col = 0,
parse_dates=True, names=['date','temp'], infer_datetime_format=True,dayfirst=True)
当我应用巴特沃斯滤波器时
b3, a3 = sg.butter(1, 0.045)
y3 = sg.filtfilt(b3, a3, core_3.temp)
b7, a7 = sg.butter(1, 0.030)
y7 = sg.filtfilt(b7, a7, core_7.temp)
正如您所见,3 THz 信号存在锯齿趋势。在 21:45 信号有一个扰动(我想研究那个扰动)。在 7 THz 处可以清楚地观察到这种扰动。在 3 THz 处观察到锯齿中断。所以,我需要去趋势化或过滤这个信号。我尝试使用 filtfilt
过滤器,但我不知道使用 scipy.detrend
是否更方便。
最佳答案
无论是过滤还是简单的去趋势处理都不会对该信号产生任何好处。第一个问题是趋势有些周期性。第二个问题是周期性不是平稳的。我相信线性方法不能解决问题。
我建议您执行以下操作:
- 删除跳跃(“展开锯齿”)
- 然后使用低通滤波器或其他方式消除信号的趋势
这是一个例子:
import numpy as np
import scipy.signal as sps
import matplotlib.pyplot as plt
np.random.seed(123)
# create an example signal
x = []
ofs = 3.4
slope = 0.002
for t in np.linspace(0, 100, 1000):
ofs += slope
x.append(np.sin(t*2) * 0.1 + ofs)
if x[-1] > 4:
ofs =3.2
slope = np.random.rand() * 0.003 + 0.002
x = np.asarray(x)
plt.plot(x, label='original')
# detect and remove jumps
jmps = np.where(np.diff(x) < -0.5)[0] # find large, rapid drops in amplitdue
for j in jmps:
x[j+1:] += x[j] - x[j+1]
plt.plot(x, label='unrolled')
# detrend with a low-pass
order = 200
x -= sps.filtfilt([1] * order, [order], x) # this is a very simple moving average filter
plt.plot(x, label='detrended')
plt.legend(loc='best')
plt.show()
关于python - 消除趋势或过滤锯齿信号 (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35458363/