I have a problem with my butterworth bandpass filter. I have an 1D array (eeg signal) recorded with 250Hz. The cutoff frequencies are 6 and 11 Hz. What I have now is this, which doesn´t work:
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
import scipy.io
import scipy.signal
import scipy.fftpack
from scipy.signal import butter, lfilter
def butter_bandpass(lowcut, highcut, fs, order=6):
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=6):
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = lfilter(b, a, data)
return y
if __name__ == "__main__":
fs = 250.0
lowcut = 6.0
highcut = 11.0
t = range(len(eeg))
x = eeg[t]
y = butter_bandpass_filter(x, lowcut, highcut, fs, order=6)
plt.plot(t, y)
plt.show()
What´s wrong?
Thanks Mike