0

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; 

0 Answers0