KBB Developing MMN ERPs - LeoLedesma237/LeoWebsite GitHub Wiki
Overview
The goal of this script is to create ERPs from the markers of interest and then saving them for analysis or visualization in R. There are 8 parts to this script.
- Part 1: Identifying Markers and removing ones we do not need
- Part 2: Creating an Event List
- Part 3: Assigning Bins
- Part 4: Extracting Epochs
- Part 5: Computing the averages for each ERP
- Part 6: (Optional) Visualizing the ERPs for each channel
- Part 7: Saving ERP data as a CSV file
Part 1: Identify the type and frequency of markers and remove unwanted ones
- Use the
pop_squeezevents(EEG)
to obtain these numbers. - This function only works if ERPLAB is installed.
Next remove these unwanted markers (They are noise).
- R4
- R7
% Find indices of events that contain 'R 4' or 'R 7' in their type
unwanted_marker_indices = [];
for i = 1:length(EEG.event)
if contains(EEG.event(i).type, {'R 4', 'R 7', 'empty'})
unwanted_marker_indices = [unwanted_marker_indices i];
end
end
% Delete the unwanted events
EEG.event(unwanted_marker_indices) = [];
Part 2: Create an Event List
This is best done by code, however it is quite odd! As in Part 1, we use the pop_squeezevents(EEG)
function to identify the types of markers and their frequency. For the Tone Condition, we have markers whose names include spaces Ex: 'S 1' or 'S 2'. This is problematic however the code below can get around this. We first present that the marker names do not have spaces between the characters. Then, we run the code that gives then a numeric value. This code will not work for these markers but will for 'boundary'- they get converted to -99. Additionally, the marker names get changes from 'S 1' and 'S 2' to 'S1' and 'S2' respectively. The reason for this is unclear but it can be verified using the pop_squeezevents(EEG)
function again. Then we rerun the same code and now the markers S1
and 'S2' get converted into the numeric values we need.
Result:
- 'S1' = 1 (deviant)
- 'S2' = 2 (standard)
pop_squeezevents(EEG)
EEG = pop_creabasiceventlist( EEG , ...
'BoundaryNumeric', { -99 1 2 }, ...
'BoundaryString', { 'boundary ' 'S1 ' 'S2'}, ...
'Eventlist', 'Z:\Leo\KBB_EEG_Pilot\6_ERPLAB\Event List\MMN_Tone_Condition_event_list.txt' );
pop_squeezevents(EEG)
EEG = pop_creabasiceventlist( EEG , ...
'BoundaryNumeric', { -99 1 2 }, ...
'BoundaryString', { 'boundary ' 'S1 ' 'S2'}, ...
'Eventlist', 'Z:\Leo\KBB_EEG_Pilot\6_ERPLAB\Event List\MMN_Tone_Condition_event_list.txt' );
pop_squeezevents(EEG)
For the syllable condition
Result:
- 'S3' = 3 (deviant)
- 'S4' = 4 (standard)
pop_squeezevents(EEG)
EEG = pop_creabasiceventlist( EEG , ...
'BoundaryNumeric', { -99 3 4 }, ...
'BoundaryString', { 'boundary ' 'S3 ' 'S4'}, ...
'Eventlist', 'Z:\Leo\KBB_EEG_Pilot\6_ERPLAB\Event List\MMN_Syllable_Condition_event_list.txt' );
pop_squeezevents(EEG)
EEG = pop_creabasiceventlist( EEG , ...
'BoundaryNumeric', { -99 3 4 }, ...
'BoundaryString', { 'boundary ' 'S3 ' 'S4'}, ...
'Eventlist', 'Z:\Leo\KBB_EEG_Pilot\6_ERPLAB\Event List\MMN_Syllable_Condition_event_list.txt' );
pop_squeezevents(EEG)
Part 3: Creating Bins
The step before was necessary to create this text file. In other tasks, like the GnG Paradigm, you can add markers after markers to make them conditional. For example, interest in this marker only if it is followed by a marker that indicates if it is correct. In our case, we are interested solely in each marker separately. This is because the task is passive.
- Create an assigned bin. You can create it in MATLAB and then save it as a .txt file.
- For every bin, it needs a name Ex:
bin 1
. - The second row will be the name of trial when averaged and plotted.
- The third row is the numeric value that represents the original marker.
Tone MMN Bin
bin 1
Deviant 1200Hz Tone
.{1}
bin 2
Standard 1000Hz Tone
.{2}
Syllable MMN Bin
bin 1
Deviant stimulus
.{3}
bin 2
Standard stimulus
.{4}
- Set the pathway to the assigned bin on the GUI.
- Look at your output in the Command Window. It will inform you if this was successful or not. Ex:
Successful Trials per bin : 50 486
Part 4: Extracting Epochs
- Set the time range of interest
- We did -100 to 350, which should capture the MMN
Part 5: Compute average ERPs
This saves the ERP information that we created by averaging brain activity from each marker that was chosen in assigned bins. We can then use this information to plot our ERPs or save them as a numeric value for data analysis.
- Naming and saving ERPs
Part 6: (Optional) Manually Inspect the ERPs for each channel
This is option. The downside is that I have not been able to figure out how to take the difference from the brain activity shown.
Part 7: Saving the data from each ERP as a text file
Make sure that both bins (1 and 2) are present. This will print out 2 CSV files. Each will have information of voltage for the respective ERP type across time. This data can then be uploaded into R for data visualization and analysis.