I need to compute the mean power of the mu frequency band (8-13Hz). I want to do it with the Fourier Transform, but I don't get the correct results.
What I'm doing exactly is not important for the question, but maybe it helps understanding the code: I have many EEG-recordings of participants that imagine left or right-hand movement and I want to calculate their average mu power during rest (not imagining movement) and their average mu power during the imagery period (imaging left/right-hand movement) and then use the formula: (power during imagery - power during rest) / power during rest
However, the problem is, that I almost only get positive values, but they should be negative, so I think that there is a problem with the Fourier Transform. Can someone help?
My code looks like this:
# left trial (C4)-------------------------------------------------
fs = 250.
lrest = np.array(left_df.loc[left_df['Rest/Imagery'] == 'rest','C4'])
limagery = np.array(left_df.loc[left_df['Rest/Imagery'] == 'imagery','C4'])
low,high = 8,13 #mu waves
### rest period
#get amplitude of FFT
fft_vals = np.absolute(np.fft.rfft(lrest))
#get frequencies for amplitude in Hz
fft_freq = np.fft.rfftfreq(len(lrest),1.0/fs)
#take mean of fft amplutide for the mu band
freq_ix = np.where((fft_freq >= low) & (fft_freq <= high))
meanlrest = np.mean(fft_vals[freq_ix])
### imagery period
fft_vals = np.absolute(np.fft.rfft(limagery))
fft_freq = np.fft.rfftfreq(len(limagery),1.0/fs)
freq_ix = np.where((fft_freq >= low) & (fft_freq <= high))
meanlimg = np.mean(fft_vals[freq_ix])
ERDS_left = (meanlimg - meanlrest)/meanlrest
ERDS_subject_left_fourier.append(ERDS_left)
# right trial (C3)--------------------------------------
rrest = np.array(right_df.loc[right_df['Rest/Imagery'] == 'rest','C3'])
rimagery = np.array(right_df.loc[right_df['Rest/Imagery'] == 'imagery','C3'])
### rest period
fft_vals = np.absolute(np.fft.rfft(rrest))
fft_freq = np.fft.rfftfreq(len(rrest),1.0/fs)
freq_ix = np.where((fft_freq >= low) & (fft_freq <= high))
meanlrest = np.mean(fft_vals[freq_ix])
### imagery period
fft_vals = np.absolute(np.fft.rfft(rimagery))
fft_freq = np.fft.rfftfreq(len(limagery),1.0/fs)
freq_ix = np.where((fft_freq >= low) & (fft_freq <= high))
meanlimg = np.mean(fft_vals[freq_ix])
ERDS_left = (meanrimg - meanrrest)/meanrrest
ERDS_subject_right_fourier.append(ERDS_right)