Clear Filters
Clear Filters

Calculate average power of EEG interval

21 views (last 30 days)
Laura Hagedorn
Laura Hagedorn on 22 May 2023
Answered: Shreeya on 5 Sep 2023
Hello, I have EEG data from 42 participants (stored as .mat files in "from_path" directory). Each data file contains about 25,000 - 30,000 time stamps and 16 channels. I want to split the data into 3 intervals: from 1 to n1, from n1 to n2, and from 2 to the end (n1 and n2 are columns) and then calculate the average powers of the delta, theta, alpha, beta and gamma band. Then I want to store the output in a 16x5 table and save it.
Below is the my code, which calculates the average powers for the whole EEG file. How can I adjust in such a way that it calculates the average power for each segment?
Thank you in advance!
files = dir(strcat(from_path,'\*.mat'))
for i = 1:length(files)
filename = files(i).name;
data = load(filename).eeg;
srate = 250;
nChans = 16;
n1 = ..; % i have another function to extract the desired column
n2 = ..;
seg1 = data(:,1:n1);
seg2 = data(:,n1:n1+n2);
seg3 = data(:,n1+n2:end);
powers = zeros(1, 5);
for chan = 1:nChans
[spectra, freqs] = spectopo(data(chan,:,:), 0, srate,'windowsize',srate,'plot','off');
deltaIdx = find(freqs>0.5 & freqs<4);
thetaIdx = find(freqs>4 & freqs<8);
alphaIdx = find(freqs>8 & freqs<13);
betaIdx = find(freqs>13 & freqs<30);
gammaIdx = find(freqs>30 & freqs<45);
deltaPower = mean(10.^(spectra(deltaIdx)/10));
thetaPower = mean(10.^(spectra(thetaIdx)/10));
alphaPower = mean(10.^(spectra(alphaIdx)/10));
betaPower = mean(10.^(spectra(betaIdx)/10));
gammaPower = mean(10.^(spectra(gammaIdx)/10));
pow = [deltaPower, thetaPower, alphaPower, betaPower, gammaPower];
powers(end+1,:) = pow;
end;
powers(1,:) = []
ps = table(powers);
proc_filename = strcat(filename,".csv");
writetable(ps,proc_filename);
end;

Answers (1)

Shreeya
Shreeya on 5 Sep 2023
Hi Laura
I understand that you want to segment the EEG data in 3 intervals, calculate the average power of various frequency bands such as alpha, beta, gamma etc. and then store the results in a table.
MATLAB’s “bandpower” function can be used for this purpose. After segmenting the data in three parts, the average power of alpha band in one of the segment can be calculated as:
bandpower(seg1,fs,[8,12])
Refer to the documentation for more details: https://in.mathworks.com/help/signal/ref/bandpower.html
Hope this helps!

Categories

Find more on Biomedical Signal Processing in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!