0

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)

1 Answers1

0

It's been a long time since I've done Fourier transforms so I could be wrong. You're using np.absoloute which could explain why you're getting only positive answers.

If you're looking at fourier transforms have you heard of scipy? The documentation is linked here.

There is a question here on using scipy to plot a fourier transform I'm not too sure on the usefullness as my Physics days are long gone but hopefully the code is relevant

  • Thank you for your answer! I thought about that as well, but without np.absolute I get values like (-0.29669067291439893+0.7540383272335334j) and I can't work with those (or at least I don't know how, because I can't interpret them as numeric values). I already tried the scipy.fft but I will take a look at it again. – laurahagedorn May 12 '21 at 10:07
  • Is this [link](https://dsp.stackexchange.com/questions/42812/calculating-power-in-frequency-band-using-power-spectral-density) of any use? Are you definitely sure you should be getting negative answers? – Connor Gill May 12 '21 at 10:16