Sorting EEG epochs using the EEGLAB toolbox

11 次查看(过去 30 天)
Dear EEGLAB users,
I was wondering if someone could help me. I have EEG datasets that need an unconventional treatment before analysis. In this experiment, participants hear a beep (event 1), and 2 seconds later, a series of 5 stimuli are shown, with 1 second of separation in between (events from 2 to 6). After pre-processing and epoching, epochs with event label 1 are 2000 ms long (from 0 to 2000 ms, no stimulus) and the other epochs are 1000 ms long (from -500 to +500 ms, where time zero indicates stimulus presentation).
How can I average across all the epochs with event label 1, 2, 3, 4, 5, and 6, and then copy the epochs with event label 1 to every other epoch so the resulting epochs are 2000 ms (duration of epoch 1) + 1000 ms (duration of each stimulus epoch)? Thus, we’d have resulting epochs of -2000 ms to +1000 ms. The objective is to use the epoch with event number 1 as baseline for the stimulus-related epochs (event numbers 2, 3, 4, 5, and 6). Could someone help me with the code?
Thank you so much!

回答(1 个)

Anurag
Anurag 2023-10-25
编辑:Anurag 2023-10-25
Hi Neuro,
I understand that you want to ensure a consistent baseline correction across your EEG data for both types of events. Please refer to the following code to help you achieve this.
EEG = pop_loadset('filename', 'your_eeg_data.set');
% Define event codes for each event type
event1 = 1;
event2 = 2;
event3 = 3;
event4 = 4;
event5 = 5;
event6 = 6;
% Define baseline period
baseline_start = -2000; % -2000 ms
baseline_end = 0; % 0 ms
% Extract event indices for each event type
indices1 = find(ismember([EEG.event.type], event1));
indices2 = find(ismember([EEG.event.type], event2));
indices3 = find(ismember([EEG.event.type], event3));
indices4 = find(ismember([EEG.event.type], event4));
indices5 = find(ismember([EEG.event.type], event5));
indices6 = find(ismember([EEG.event.type], event6));
% Baseline correction for event 1
EEG = pop_rmbase(EEG, [baseline_start, baseline_end], indices1);
% Create new epochs for events 2, 3, 4, 5, and 6 with baseline correction
EEG2 = pop_select(EEG, 'trial', indices2);
EEG3 = pop_select(EEG, 'trial', indices3);
EEG4 = pop_select(EEG, 'trial', indices4);
EEG5 = pop_select(EEG, 'trial', indices5);
EEG6 = pop_select(EEG, 'trial', indices6);
% Adjust time points for events 2, 3, 4, 5, and 6 to have the same baseline
EEG2 = pop_editeventvals(EEG2, 'type', event1, 'latency', [EEG2.event.latency] - baseline_start);
EEG3 = pop_editeventvals(EEG3, 'type', event1, 'latency', [EEG3.event.latency] - baseline_start);
EEG4 = pop_editeventvals(EEG4, 'type', event1, 'latency', [EEG4.event.latency] - baseline_start);
EEG5 = pop_editeventvals(EEG5, 'type', event1, 'latency', [EEG5.event.latency] - baseline_start);
EEG6 = pop_editeventvals(EEG6, 'type', event1, 'latency', [EEG6.event.latency] - baseline_start);
Hope this helped.
Regards,
Anurag

类别

Help CenterFile Exchange 中查找有关 EEG/MEG/ECoG 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by