I am trying to filter EEG signals using butterworth filter and filtfilt. I have gone through a lot of documentation and these 2 commands seem sufficient for filtering. However, the results are bizarre.
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) 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()
This is the eeg data
Also, isn't the output in time domain? It seems incorrect irrespective of the domain. The order is too high i.e. 1e28 for the first 1000 points. I checked for the other points and the order is 1e17, even for points after 4000. Is this what I should expect?