我正在尝试使用巴特沃斯滤波器和 filtfilt 过滤 EEG 信号。我浏览了很多文档,这两个命令似乎足以过滤。然而,结果很奇怪。
from scipy.signal import butter, filtfilt
import sys, pickle
from numpy import *
import matplotlib.pyplot as plt
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
return b, a
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = filtfilt(b, a, data)
return y
with open(sys.argv[1]) as eeg:
eeg_data = pickle.load(eeg)
eeg_data = eeg_data[:,3]
fs = 128
lowcut = 1
highcut = 40.0
y = butter_bandpass_filter(eeg_data, lowcut, highcut, fs, order = 9)
plt.plot(y,'r')
plt.show()
这是脑电图数据
另外,不是时域的输出吗?无论域如何,它似乎都不正确。顺序太高,即前 1000 个点为 1e28。我检查了其他点,顺序是 1e17,即使是 4000 之后的点。这是我应该期待的吗?