[Eeglablist] Power in spectopo vs. fft

Makoto Miyakoshi mmiyakoshi at ucsd.edu
Tue Apr 27 12:05:21 PDT 2021


Dear Irene,

It is an erratum to the response I posted to the list to answer to your
question 7 years ago. Maybe you are no longer a student.
About the difference between the results generated by spectopo() and
pwelch(), please see the following Wikipage for the detail.
https://sccn.ucsd.edu/wiki/Makoto%27s_useful_EEGLAB_code#Comparison_between_spectopo.28.29_and_pwelch.28.29_.2804.2F27.2F2021_added.29

Makoto

On Thu, May 8, 2014 at 11:48 AM Makoto Miyakoshi <mmiyakoshi at ucsd.edu>
wrote:

> Dear Irene,
>
> EEGLAB uses pwelch() function, not fft(). This is why they did not match.
> If you want to see if Matlab pwelch() and spectopo() results match, try
> the code below.
>
> Makoto
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> % EEGLAB spectopo function
> [spectra,freqs] = spectopo(EEG.data(2,:), 0, EEG.srate, 'nfft', 1024); %
> For channel 2 (C4)
>
> thetaIdx   = find(freqs>=4 & freqs<=8);                    % theta=4-8
> thetaPower = 10^(mean(spectra(thetaIdx))/10);              % mean theta
> power
> alphaIdx   = find(freqs>=8 & freqs<=12);                   % alpha=8-12
> alphaPower = 10^(mean(spectra(alphaIdx))/10);              % mean alpha
> power
> eeglabThetaAlphaRatio = thetaPower/alphaPower;
>
> figure; subplot(1,2,1); plot(freqs,10.^(spectra/10))
>
> % Matlab pwelch function
> x  = EEG.data(2, :);      % For channel 2 (C4)
> Fs = EEG.srate;              % Sampling frequency
> L  = EEG.pnts;               % Length of signal
> NFFT = 2^nextpow2(L);        % Next power of 2 from length of x
> % X    = fft(x,NFFT)/L;
> % freqs   = Fs/2*linspace(0,1,NFFT/2+1);
> % spectra = abs(X(1:NFFT/2+1));
>
> NOVERLAP = 0;
> WINDOW = 512;
> [spectra,freqs] = pwelch(x,WINDOW,NOVERLAP,NFFT,EEG.srate);
>
> thetaIdx   = find(freqs>=4 & freqs<=8);            % theta=4-8
> thetaPower = mean(spectra(thetaIdx));              % mean theta power
> alphaIdx   = find(freqs>=8 & freqs<=12);           % alpha=8-12
> alphaPower = mean(spectra(alphaIdx));              % mean alpha power
> matlabThetaAlphaRatio = thetaPower/alphaPower;
>
> subplot(1,2,2); plot(freqs,spectra)
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>
>
> 2014-05-08 6:31 GMT-07:00 Trilla Gros, Irene (Stud. FPN) <
> i.trilla at student.maastrichtuniversity.nl>:
>
>> Dear all,
>>
>> I am trying to calculate an index of mu suppression by doing the log
>> ratio between alpha-band power in one condition (e.g. S5) and alpha-band
>> power in baseline (e.g. B5): log(powerS5/powerS6).
>>
>> To do that, I first extracted the mean absolute power of the alpha range
>> (8-12 Hz) for condition (S5) and for baseline (B5) using spectopo in EEGLAB:
>>
>>     [spectra,freqs] = spectopo(EEG.data(2,:,:), 0, EEG.srate);
>>   % For channel 2 (C4)
>>     AlphaIdx = find(freqs>=8 & freqs<=12);
>>           % alpha=8-12
>>     AlphaPower = 10^(mean(spectra(AlphaIdx))/10);
>>    % mean power
>>
>> Additionally, I did the same analysis but using directly the FFT function
>> in MATLAB instead:
>>
>>     x = EEG.data(2, :, :);       % For channel 2 (C4)
>>     Fs = EEG.srate;                 % Sampling frequency
>>     L = EEG.pnts;                     % Length of signal
>>     NFFT = 2^nextpow2(L);    % Next power of 2 from length of x
>>
>>     X = fft(x,NFFT)/L;
>>     f = Fs/2*linspace(0,1,NFFT/2+1);
>>     power = abs(X(1:NFFT/2+1));
>>
>>     AlphaIdx = find(f>=8 & f<=12);
>>     AlphaPower = mean(power(AlphaIdx));
>>
>> When I compute the ratio (power condition/power baseline) the results are
>> very different depending on whether I use the absolute power calculated
>> with spectopo or whether I use the power from the fft function. Even if the
>> magnitudes computed with spectopo and fft differ, shouldn’t the ratio
>> between the condition and baseline be the same? Aren't these two functions
>> comparable when extracting frequency power?
>>
>> Thanks in advance for your answers!
>>
>>
>> Irene
>>
>> _______________________________________________
>> Eeglablist page: http://sccn.ucsd.edu/eeglab/eeglabmail.html
>> To unsubscribe, send an empty email to
>> eeglablist-unsubscribe at sccn.ucsd.edu
>> For digest mode, send an email with the subject "set digest mime" to
>> eeglablist-request at sccn.ucsd.edu
>>
>
>
>
> --
> Makoto Miyakoshi
> Swartz Center for Computational Neuroscience
> Institute for Neural Computation, University of California San Diego
>



More information about the eeglablist mailing list