MATLAB: Bandpass filtering EEG data

bandpass filter eeg

Hey guys,
I am currently messing around with ways to filter EEG data I have recorded. I am currently trying bandpass filtering my data, but the data after filtering looks funky. The raw data I record is measured in mV, and has mostly "small" values, mainly <0.5 but occasionally >1. After using the bandpass filter below, data look funny, with values become "huge" (y axis goes from -400:400). I am hoping someone can give me some basic pointers on what filter parameters I need to change.
Fstop1 = 0.1; % First Stopband Frequency
Fpass1 = 0.2; % First Passband Frequency
Fpass2 = 95; % Second Passband Frequency
Fstop2 = 100; % Second Stopband Frequency
Astop1 = 60; % First Stopband Attenuation (dB)
Apass = 1; % Passband Ripple (dB)
Astop2 = 80; % Second Stopband Attenuation (dB)
match = 'stopband'; % Band to match exactly
% Construct an FDESIGN object and call its BUTTER method.
bpfilt = fdesign.bandpass(Fstop1,Fpass1,Fpass2,Fstop2,Astop1,Apass,Astop2,Fs);
Hd = design(bpfilt, 'butter', 'MatchExactly', match);
eegdata = filter(Hd,eegdata);
I have attached images on the data plotted before and after using this filter.

Best Answer

I can’t run your code because I don’t have ‘Fs’. I almost always use the second-order-section implementation of a filter, since those tend to be stable when transfer functions are not.
Before you actually use your filter, be sure to look at the filter passband with freqz. This will tell you how stable it is and what the passband actually looks like.