-
Notifications
You must be signed in to change notification settings - Fork 0
ONR GnG EEG ERP Creation
As of right now, there is no way for me to automate the next steps. Thus they will be shown by hand.
We need to extract the information from our current markers and label each one with a numeric value. This has to happen for the following functions in ERPLAB to work. First, we will use the pop_squeezevents(EEG)
function to know what the current marker names of our EEG data are and how many there are in the data. This should be the same for all subjects and the markers should add up to 1050 (including stimuli and response markers separately) since no segments have been rejected.
The marker names will be associated with the following numbers (Go trials are odd and NoGo are even):
1 = Colors and Shape Go trial
2 = Colors and Shape NoGo trial
3 = Colors and Shape fixed IS Go trial
4 = Colors and Shape fixed IS NoGo trial
5 = Colors Shape Arrow Go trial
6 = Colors Shape Arrow NoGo trial
7 = Colors and Shape Reverse Arrow Go trial
8 = Colors and Shape Reverse Arrow NoGo trial
9 = Saber Color Matching Go trial
10 = Saber Color Matching NoGo trial
21 = Correct trial
22 = Incorrect trial
% Create an event list - and modify marker string names to numeric
EEG = pop_creabasiceventlist( EEG , 'AlphanumericCleaning', 'on', ...
'BoundaryNumeric', { -99 1 2 3 4 5 6 7 8 9 10 21 22}, ...
'BoundaryString', { 'boundary ' ...
'Colors_and_Shape_Go_trial ' ...
'Colors_and_Shape_No_Go_trial' ...
'Colors_and_Shape_fixed_ISI_Go_trial' ...
'Colors_and_Shape_fixed_ISI_No_Go_trial' ...
'Colors_Shape_Arrow_Go_trial' ...
'Colors_Shape_Arrow_No_Go_trial' ...
'Colors_Shape_Reverse_Arrow_Go_trial' ...
'Colors_Shape_Reverse_Arrow_No_Go_trial' ...
'Saber_Color_Matching_Go_trial' ...
'Saber_Color_Matching_No_Go_trial' ...
'Correct_Response' ...
'Incorrect_Response'}, 'Eventlist', ...
'M:\EEG_XDFs_Copy_2\EventList\001_Day1_EventList.txt' ); % GUI: 29-Feb-2024 00:18:33
This is useful if you want to place multiple markers into two or more groups. In our case, we are only interested in two markers for correct trials. So both of our bins will contain only one marker type. We need to essentially do two things. The first create a text file that specifies which markers are going to go in which bins and whether they are conditional on the presence of another marker. We will be doing just that, and writing a code for only Color and Shape Go trials and Color and Shape NoGo trials (each in a separate bin) that were correct (21)
The text document needed below:
bin 1
Color and Shape Go trial followed by correct response
.{1}{21}
bin 2
Color and Shape NoGo followed by correct response
.{2}{21}
And then the actual code to use this text document above to create the two bins
EEG = pop_binlister( EEG , 'BDF', 'M:\EEG_XDFs_Copy_2\binlister_demo_1.txt', ...
'IndexEL', 1, 'SendEL2', 'EEG', 'Voutput', 'EEG' ); % GUI: 29-Feb-2024 00:48:35
Now we use the information above to extract epochs based on their bin category. This means that the continuous EEG data now becomes segmented. Additionally, we can pick the size of the segments. We decide to do -400 to 1,000 ms.
% Extract the epochs
EEG = pop_epochbin( EEG , [-400.0 1000.0], 'pre');
There was a reason we did not do segmentation rejection in the earlier preprocessing script. This is because we do not want to accidently remove parts of the EEG data before epoching the data based on the markers, since doing so could result in disrupting the latency of the ERP. Thus, we will be doing it now and flagging any segments that should be removed for having activity larger than 100 microVolts.
EEG = pop_artmwppth( EEG , 'Channel', 1:16, 'Flag', [ 1 2], ...
'LowPass', -1, 'Threshold', 100, 'Twindow', [ -200 798], ...
'Windowsize', 200, 'Windowstep', 100 );
The next step is done by hand. We have to ERPLAB > Computer averaged ERPs. Then we want to 'Exclude epochs marked during artifact detection (highly recommended)' and then save the dataset.
Below are the ERPs for 001 Day1. This looks promising?
We will first start by creating a for loop that will take each EEG files with the correct marker names and do the following.
-
Create an event list
-
Create bins (two of them)
-
Segment the data by the event markers of interest
-
Identify segments to be removed for having artifacts
-
Averaging all the segments to make ERPs (and save them)
-
Extract the N2 values of averaged Go and NoGo trials for each channel
Here are the objects at the top of the code
% 1. Set the folder with correct marker names
folder = 'M:\EEG_XDFs_Copy_2\4_Fixed Markers Here'; % replace with the path to your folder
% 2. Set the folder path that you want to save the overall ERP information
save_pathway = 'M:\EEG_XDFs_Copy_2\5_GnG EEG ERPs';
% 3. Set the pathway and file name of the bin lister text code to use
binlister = 'M:\EEG_XDFs_Copy_2\binlister_demo_1.txt'
% 3. Set a folder to save event lists created
save_pathway_event = 'M:\EEG_XDFs_Copy_2\5.5_EventList'
% 4. Set the folder path where you will save all of the N2 of the averaged
% Go and NoGo trials.
save_ERP_means_pathway = 'M:\EEG_XDFs_Copy_2\6_GnG_EEG ERPs means'
Followed by the main script
for ii = 1:length(eegFiles)
Current_eegFile = eegFiles{ii}; %MUST BE SQUIGGLY LINE FOR SEGMENTATION TO WORK!!!!
Pathway = [folder '\'];
fullpath = strcat(Pathway,Current_eegFile);
% Load in EXISTING EEG files
EEG = pop_loadset('filename',Current_eegFile,'filepath',Pathway);
% Create a general name that does not include '.set'
% Create a pathway to save the
Current_eegFileGeneral = erase(Current_eegFile, ".set")
EventList_save = [save_pathway_event '\' Current_eegFileGeneral '_EventList.txt']
% Create an event list - and modify marker string names to numeric
EEG = pop_creabasiceventlist( EEG , 'AlphanumericCleaning', 'on', ...
'BoundaryNumeric', { -99 1 2 3 4 5 6 7 8 9 10 21 22}, ...
'BoundaryString', { 'boundary ' ...
'Colors_and_Shape_Go_trial ' ...
'Colors_and_Shape_No_Go_trial' ...
'Colors_and_Shape_fixed_ISI_Go_trial' ...
'Colors_and_Shape_fixed_ISI_No_Go_trial' ...
'Colors_Shape_Arrow_Go_trial' ...
'Colors_Shape_Arrow_No_Go_trial' ...
'Colors_Shape_Reverse_Arrow_Go_trial' ...
'Colors_Shape_Reverse_Arrow_No_Go_trial' ...
'Saber_Color_Matching_Go_trial' ...
'Saber_Color_Matching_No_Go_trial' ...
'Correct_Response' ...
'Incorrect_Response'}, 'Eventlist', ...
EventList_save);
% Use the event list to create bins (two of them)
EEG = pop_binlister( EEG , 'BDF', binlister, ...
'IndexEL', 1, 'SendEL2', 'EEG', 'Voutput', 'EEG' ); % GUI: 29-Feb-2024 00:48:35
% Extract the epochs
EEG = pop_epochbin( EEG , [-400.0 1000.0], 'pre'); % GUI: 28-Feb-2024 21:47:57
% Check for artifact epochs
EEG = pop_artmwppth( EEG , 'Channel', 1:16, 'Flag', [ 1 2], ...
'LowPass', -1, 'Threshold', 100, 'Twindow', [ -200 798], ...
'Windowsize', 200, 'Windowstep', 100 ); % GUI: 28-Feb-2024 21:50:57
% Remove marked artifact segments and epoch the data
ERP = pop_averager(EEG, ...
'Criterion','good')
% Give it the ERP a name
ERP.erpname = [Current_eegFileGeneral '_ERP']
% Save this epoch data (must save for code to work)
pop_savemyerp(ERP, 'erpname', ERP.erpname, ...
'filename', [ERP.erpname '.erp'], ...
'filepath', save_pathway, 'warning', 'off');
% Obtain ERP info
ALLERP = pop_geterpvalues( ERP, [ 150 250], [ 1 2], 1:30 , 'Baseline', 'pre', 'FileFormat', 'wide', ...
'Filename', [save_ERP_means_pathway '\' Current_eegFileGeneral '_measurements_written.txt'], ...
'Fracreplace', 'NaN', 'InterpFactor', 1, 'Measure', 'meanbl', 'PeakOnset', 1, 'Resolution', 3 );
end