1

我试图通过使用 filfilt 过滤器来消除信号的趋势(锯齿),但效果不佳。这里的数据

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

4

1 回答 1

3

过滤和简单的去趋势都不会对这个信号有任何好处。第一个问题是趋势有些周期性。第二个问题是周期性不是固定的。我相信线性方法不会解决问题。

我建议您执行以下操作:

  1. 移除跳跃(“展开锯齿”)
  2. 然后去趋势信号,使用低通滤波器或其他

这是一个例子:

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()

在此处输入图像描述

于 2016-02-17T14:21:40.707 回答