0
$\begingroup$

I am trying to bandpass filter an EEG signal, nothing fancy but it's coming out pretty distorted. EEG data is taken from forehead. Sampling rate is 250 Hz. Cutoff is 2.5 Hz & 120 Hz.

Tried in both matlab & python, getting same results.

Matlab code:

data = load("rawdata.mat");
data = data.data;
figure
bandpass(data,[2.5 120],250)

enter image description here

Here is the python code:

Fs = 250
lowcut = 2.5
highcut = 120
order=5

plotbutterworth(lowcut, highcut, Fs, order)

plt.figure()
fr, y_m = Fourier(250, data)
plt.stem(fr, y_m, use_line_collection = True)
plt.title('Freq CH7')
plt.xlabel("Frequency (Hz)")
plt.ylabel("Amplitude (microvolts)")

filtered = butter_bandpass_filter(data, lowcut, highcut, Fs, order)

plt.figure()
fr, y_m = Fourier(250, filtered)
plt.stem(fr, y_m, use_line_collection= True)
plt.title('Freq CH7 -- without EKG')
plt.xlabel("Frequency (Hz)")
plt.ylabel("Amplitude (microvolts)")

plt.figure()
plt.plot(data)
plt.plot(filtered)
plt.xlabel("Time")
plt.ylabel("Amplitude (microvolts)")
plt.legend(['original','filtered'],loc='best')

enter image description here

enter image description here

enter image description here

enter image description here

$\endgroup$

1 Answer 1

1
$\begingroup$

I believe the power spectrum as originally shown is affected by the large DC offset and lack of windowing prior to taking the DFT (when computing the spectrum); you are seeing the very large sidelobes of a rectangular window (Sinc function in frequency) that convolves with that large DC tone and ends up burying the rest of the spectrum in the sidelobes. The bandpass filter is removing the DC so eliminating that effect, but windowing prior to doing the FFT can also help.

The “distortion” in the final plot showing the filter output is just the initial transient for the filter (which is expected). I suggest truncating that and viewing the remaining portion of the file to see if it represents what you are expecting.

As an alternative to the filter used (which is basically removing DC and Nyquist but not much else), consider DC removal by simply subtracting the mean (if post-processing), or using this DC-nulling filter.

$\endgroup$
2
  • 1
    $\begingroup$ Another option is to properly seed the filter state. $\endgroup$
    – Hilmar
    Feb 22, 2023 at 5:09
  • $\begingroup$ @fillifilterbutterfly did this answer your question? $\endgroup$ Feb 26, 2023 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.