I'm working with brain wave data and am trying to use a Butterworth filter for the first time.
There plenty of helpful resources on stack exchange here (i) Butterworth filter in python and here (ii) How to implement band-pass Butterworth filter with Scipy.signal.butter
Taking advantage of these resources, I've implemented the following code:
from scipy.signal import butter, sosfilt, sosfreqz
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
sos = butter(order, [low, high], analog=False, btype='band', output='sos')
return sos
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
sos = butter_bandpass(lowcut, highcut, fs, order=order)
y = sosfilt(sos, data)
return y
The data I'm working with is on the left hand graph, my attempt to filter it is on the right: neural activity during 700 ms delay period
I believe that the issue I'm running into is with the parameters.
Order: set to 5. the frequency response looked ok for order 5
Low-cut: set to factor out anything below .5 hz
High-cut: set to filter out anything above 60 hz
FS/Sample Rate/Waves: we were able to collect 500 data points per second, so I set this to 500
N: 350. We are dealing with data over a 700 ms period, but only sampling every other millisecond
Looking at my data, it appears we have roughly 2 sinusoidal waves for a 700 ms period combined with 11 higher frequency waves...should I be able to look at this and set the low cut to 2 and the high cut to some value greater than 11? I've tried iterating over dozens of values at this point...
Thank you to anyone who attempts to help. I've been trying to figure this out for the past two days and have hit a wall.