Help with opening a .set file(a filtered eeg .edf file) and computing the power for each frequency band

43 ビュー (過去 30 日間)
Toni
Toni 2022 年 11 月 9 日
回答済み: Rishav 2023 年 9 月 11 日
Hello!
Please I need help with computing the power for each frequency band of an eeg signal. The initial filedata I have is in .edf format, which I filtered and is now in .set format. I found this code online;
% This example Matlab code shows how to compute power spectrum of epoched data, channel 2.
[spectra,freqs] = spectopo(EEG.data(2,:,:), 0, EEG.srate);
% Set the following frequency bands: delta=1-4, theta=4-8, alpha=8-13, beta=13-30, gamma=30-80.
deltaIdx = find(freqs>1 & 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<80);
% Compute absolute power.
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));
But I've just been trying to figure out how to open my .set file in matlab and perform the necessary calculations.
I will greatly appreciate anyone's help on this. Thanks

回答 (1 件)

Rishav
Rishav 2023 年 9 月 11 日
Hi Toni,
To open the EEG data from a .set file, you can use the EEGLAB toolbox in MATLAB.
You can download and install the EEGLAB toolbox from the below mentioned link:
After installing the EEGLAB toolbox, follow the steps mentioned below:
  • Open MATLAB and start EEGLAB by typing 'eeglab' in the MATLAB command window. This will open the EEGLAB GUI.
  • In the EEGLAB GUI, click on 'File' and then select 'Load existing dataset'.
  • Navigate to your .set file and open it.
After loading your EEG data, you can compute power for each frequency band using EEGLAB's functions. Here is an example:
% Set the frequency bands.
freq_bands = [1 4; 4 8; 8 13; 13 30; 30 80];
% Initialize variables to store power values.
deltaPower = zeros(1, EEG.trials);
thetaPower = zeros(1, EEG.trials);
alphaPower = zeros(1, EEG.trials);
betaPower = zeros(1, EEG.trials);
gammaPower = zeros(1, EEG.trials);
% Loop through trials and compute power for each frequency band.
for trial = 1:EEG.trials
% Extract data for the current trial and channel (e.g., channel 2).
trial_data = EEG.data(2, :, trial);
% Compute the power spectrum.
[spectra, freqs] = spectopo(trial_data, 0, EEG.srate);
% Compute power for each frequency band.
for band_idx = 1:size(freq_bands, 1)
band_range = freq_bands(band_idx, :);
band_idx_range = find(freqs >= band_range(1) & freqs <= band_range(2));
band_power = mean(10.^(spectra(band_idx_range) / 10));
% Store the power in the appropriate variable.
switch band_idx
case 1
deltaPower(trial) = band_power;
case 2
thetaPower(trial) = band_power;
case 3
alphaPower(trial) = band_power;
case 4
betaPower(trial) = band_power;
case 5
gammaPower(trial) = band_power;
end
end
end
This script will compute the power values for each frequency band in separate variables.
Thank you,
Rishav Saha

カテゴリ

Help Center および File ExchangeBiomedical Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by