And applying SciPy’s Fourier transform functions to plot the frequency domain of my recording:
N = len(EEG[['FP1-F7']]) #921600
f = 256 #256 Hz
xf = fftfreq(N, 1/f)
yf = fft(EEG[['FP1-F7']])
plt.plot(xf, np.abs(yf))
plt.xlabel("Frequency")
plt.ylabel("Amplitude")
plt.title("Frequency domain (Fourier transform) of single signal")
plt.show()
I still receive a frequency domain plot ranging from -128 to +128 Hz with considerable amplitudes across all frequencies, e.g. a large spike at 60 Hz still (Imgur: The magic of the Internet).
Shouldn’t the high-pass, low-pass filtering filter out the frequencies outside the range specified (in my case: 1 to 40Hz) as per the filtering applied, more or less flattening the amplitudes outside of that range? I.e., in my plot, should the amplitudes before 0 and after 40 Hz be almost flat?
Hi Mathieu! Thank you sincerely for your reply. You’re right! The filter is applied as can be seen in the following two graphs (without and with filtering resp.):
Indeed after applying the filter I checked the EEG data-frame I am creating, and the values do change.
So I must be fundamentally mistaken how Fourier Transform works (in Python).
If I were to plot the frequency domain of one of the EEG channels after filtering, shouldn’t the plot reflect this change? I.e., shouldn’t the power in the red boxed be close to zero in the following plot?
You’re right! This worked for me! Thank you so much.
Side-note, do you have any idea what those two large spikes might be in my data? Some noise presumably? I hate to take more of your time so please ignore if you don’t feel like / have time for responding!
No idea, but you should investigate. Try to look at raw.plot() and to find this activity in the temporal domain, try to figure out if it is a constant background noise or if it just happens at specific timings/intervals.
I’m going to guess an ICA should be able to isolate it well.
ASIDE: Just an FYI to make your life easier: there is a raw.to_data_frame() method that handles column names automatically, scales EEG from V to uV, lets you subselect specific channels or time ranges, etc. mne.io.Raw — MNE 1.6.0 documentation