-
Notifications
You must be signed in to change notification settings - Fork 2
37. EEG MRI analysis
Here are details of processing MRI and EEG data for the steady-state visual evoked potentials (SSVEP) experiment. Sample data are provided here.
Reconstruct brain structure using FreeSurfer and T1-weighted MRI (MPRAGE sequence) data. Details are here.
Follow the instruction here for fMRI data pre-processing, including the following
- convert meas.dat into Matlab mat files
- register between fMRI and structural MRI. See this page for details.
- prepare fMRI data on brain surfaces
The fMRI analysis using Genearal Linear Model can be found here.
EEG pre-processing includes
- suppress gradient and pulse artifacts.
- calculate event-related potentials (for event-related design).
- To do EEG source analysis, follow the procedure here.
Each session of EEG recording use the Brain Products amplifier gave three files: .vmrk, .vhdr, and .eeg files. You need all three files to process one session of EEG. NOTE: file names cannot be arbitrarily changed because data in the file were linked to the file name.
For example, for subject `180330_SYH', SSVEP_out_1.eeg, SSVEP_out_1.vhdr, and SSVEP_out_1.eeg together completed the recording of EEG outside MRI.
In the SSVEP experiment, EEG recordings for three conditions were taken:
- EEG recorded outside MRI: consequently no MRI gradient and pulse artifacts. This condition is coded by "outside MRI".
- EEG recorded inside MRI bore but no MRI were taken: consequently no MRI gradient but with pulse artifacts. This condition is coded by "inside MRI".
- EEG recorded outside MRI: consequently with both MRI gradient and pulse artifacts. This condition is coded by "SMS-InI"
Here is a table describing the file name prefix for three conditions and three subjects.
Subject | 180330_SYH | 180401_YTH | 180411_PYY |
---|---|---|---|
Outside MRI | SSVEP_out_1 | SSVEP_out_1 | SSVEP_out_1 |
Inside MRI | SSVEP_noMR_1, SSVEP_noMR_2, SSVEP_noMR_3 | SSVEP_noMR_1, SSVEP_noMR_2, SSVEP_noMR_3 | SSVEP_noMR_1, SSVEP_noMR_2, SSVEP_noMR_3 |
SMS-InI. | SSVEP_sms_1, SSVEP_sms_2, SSVEP_sms_3 | SSVEP_sms_1, SSVEP_sms_2, SSVEP_sms_3 | SSVEP_sms_1, SSVEP_sms_2, SSVEP_sms_3 |
The following codes read EEG data from one session (outside MRI). NOTE: bvloader tooolbox is needed. Please download it and make it within your Matlab path.
close all; clear all;
headerFile={
'../eeg_raw/SSVEP_out_1.vhdr';
};
% first get the continuous data as a matlab array
eeg{1} = double(bva_loadeeg(headerFile{1}));
% meta information such as samplingRate (fs), labels, etc
[fs(1) label meta] = bva_readheader(headerFile{1}
The variable eeg[1}
is the data. fs(1)
is the sample rate. label
describes the names for EEG electrodes.
EEG traces can be visualized with the following codes:
etc_trace(eeg{1},'fs',fs(1),'ch_names',label);
EEG recording of 30-s interval with electrode names will be shown.
- Check procedures of pre-processing of EEG data collected inside MRI here. The following is some repetition and modification of the suggested procedure.
ERPs are calculated following the following major steps:
- Gradient artifact removal: ONLY for data collected during MRI. Remove the large EEG signals caused by MRI gradient coil switching during MRI generation.
- High-pass filtering (default: 1 Hz): remove any slow fluctuations (< 1 Hz).
- Time series truncation (optional): remove some parts of the data, which may lack important timing stamps required for data analysis
- Gradient artifact removal: ONLY for data collected inside the MRI bore. Remove the large EEG signals caused by heartbeats and breathing inside a strong magnetic field.
- Re-reference (optional): remove the average across all EEG electrodes
- Low-pass filtering (default: 70 Hz): remove any fast fluctuation (> 70 Hz).
Here we use subject 180411_PYY
as the example.
- Estimate the ERP using the data collected outside MRI:
-- 1.1 Read EEG data with processing options: [read_outside_eeg_042124.m].
IMPORTANT!! Examine your results with the following script:
etc_trace(cat(1,EEG_orig,ECG_orig),'fs',fs(1),'ch_names',label,'aux_data',{cat(1,EEG,ECG)})
Two sets of EEG traces should should up. The dark blue ones are "main" signals, original EEG and ECG denoted by EEG_orig
and ECG_orig
. The red ones are "auxiliary signals", the EEG and ECG traces after processing denoted by EEG
and ECG
. Hint: Use Up and Down keys to switch between traces for visualization.
Pay attention to the filtering effects, which are the most prominent effects in EEG collected outside MRI.
-- 1.2 Get ERP by averaging "epochs" of processed EEG waveform over trials: [read_outside_eeg_042124.m].
NOTE: This process was done automatically by averaging all trials. In practice, each trial should be visually inspected to ensure that no outliers with excessive artifacts (noise, drifting, etc), which are very likely to overwhelem the ERP if included.
Pay attention to the following flag and thresholds:
flag_badrejection=1; %automatic bad trial rejection
badrejection_threshold=100; %microV; threshold to consider as a bad trial
These settings will automatically exclude all trials with any instant if the value of the data at any electrode in the epoch exceeds 100 uV. Try to adjust these parameters.
- Render the evoked response topology and time course: [show_erp_scalp.m]. This script needs a EEG topology definition for 31-channel Brain Products EEG [topology_31ch_default.mat] for the definition of EEG electrode locations and a head model.
Change line 3 in the show_erp_scalp.m
to supply the correct Matlab file with processed ERP to visualize. Click somewhere around the occipital lobe, where we expected to have strong SSVEP, to have the ERP plot shown below.
- Estimate the ERP using the data collected inside MRI:
-- 3.1 Read EEG data with processing options: [read_inside_eeg_042124.m]. Now ballistocardiography (BCG) artifacts were present on EEG traces. So we need to enable options to suppress them.
Parameters flag_bcg
is now set to 1 to suppress BCG artifacts!
flag_bcg= [1 1 1 1 1 1]; %BCG artifact suppression
Here you need to use Pan Tompkin's algorithm to estimate peaks in the ECG cycles. These cycles will be used to define intervals of repetitive patterns related to heartbeats. Here is the matlab script that I used.
Examine your results with the following script:
etc_trace(cat(1,EEG_orig,ECG_orig),'fs',sfreq,'ch_names',label,'aux_data',{cat(1,EEG,ECG)},'trigger',TRIGGER);
Two sets of EEG traces should should up. The dark blue ones are "main" signals, original EEG and ECG denoted by EEG_orig
and ECG_orig
. The red ones are "auxiliary signals", the EEG and ECG traces after processing denoted by EEG
and ECG
. Now you can see strong BCG artifacts on EEG traces. These artifacts are temporally synchronized with ECG.
-- 3.2 Get ERP by averaging "epochs" of processed EEG waveform over trials: [read_inside_eeg_042124.m]. Note that this script automatically rejects some trials with excessive values. You may better modify this part to avoid rejecting too many trials while avoiding bad epochs ruin your ERPs.
-
Render the evoked response topology and time course. Modify the script [show_erp_scalp.m] to load the ERP from EEG collected inside MRI. Click somewhere around the occipital lobe, where we expected to have strong SSVEP, to have the ERP plot shown below. Pay attention to the degradation of SSVEP, compared to the results from "outside MRI" condition.
-
Estimate the ERP using the data collected during MRI:
-- 3.1 Read EEG data with processing options: [read_smsini_eeg_042124.m]. Now not only BCG artifacts but also gradient artifacts were present on EEG traces. So we need to enable options to suppress them.
Parameters flag_aas
is now set to 1 to suppress gradient artifacts! We also need to enable flag_bcg
because EEG traces were still degraded by BCG.
flag_aas= [1 1 1 1 1 1]; %AAS for gradient artifact suppression
flag_bcg= [1 1 1 1 1 1]; %BCG artifact suppression
Examine your results with the following script:
etc_trace(cat(1,EEG_orig,ECG_orig),'fs',sfreq,'ch_names',label,'aux_data',{cat(1,EEG,ECG)},'trigger',TRIGGER);
Two sets of EEG traces should should up. The dark blue ones are "main" signals, original EEG and ECG denoted by EEG_orig
and ECG_orig
. The red ones are "auxiliary signals", the EEG and ECG traces after processing denoted by EEG
and ECG
. Now you can see strong gradient and BCG artifacts on EEG traces. Gradient artifacts were strong and repetitive (once every 2 s).
-- 5.2 Get ERP by averaging "epochs" of processed EEG waveform over trials: [read_smsini_eeg_042124.m]. Note that this script automatically rejects some trials with excessive values. You may better modify this part to avoid rejecting too many trials while avoiding bad epochs ruin your ERPs.
- Render the evoked response topology and time course. Modify the script [show_erp_scalp.m] to load the ERP from EEG collected inside MRI. Click somewhere around the occipital lobe, where we expected to have strong SSVEP, to have the ERP plot shown below. Pay attention to the degradation of SSVEP, compared to the results from "outside MRI" and "inside MRI" conditions.