/EEGLAB-Pipeline

A standardized pipeline for EEG preprocessing and artifact rejection using EEGLAB

Primary LanguageMATLABMIT LicenseMIT

EEGLAB-Pipeline

A standardized pipeline for EEG preprocessing and artifact rejection using EEGLAB

Installation

  1. Install EEGLAB using the instructions here.
  2. Add the eeglab directory to your path using "Set Path > Add Folder..." (you do not need to add with subfolders).
  3. Install ERPLAB with the EEGLAB plugin manager using the instructions here.
  4. Install EYE-EEG with the EEGLAB plugin manager.
    a. Instructions for using EYE-EEG are here.
    b. Importantly, eyetracking messages that synchronize with the EEG parallel portcodes must have a synchronize keyword before the digits. See more details about Method 2: Messages+triggers.
  5. Install bva-io with the EEGLAB plugin manager.
  6. Install the EEGLAB Signal Processing Toolbox.
    NOTE: It may be possible to avoid using this expensive plugin. I believe the only function that requires it is pop_resample which changes the sampling rate of your eyetracking/EEG.
  7. git clone this repo (or download as a zip) into your desired folder.
  8. Optionally, download the test_data with source get_test_data.sh
  9. You also need a way to convert EDF eyetracking files to ASC files that are viewable in MATLAB. Learn more here.

Usage

This script is essentially a template which you can copy and edit per project. After running this script, you will have saved "unchecked" .set files which can then be opened in EEGLAB. The trials that have been flagged for rejection are not yet removed. The rejection flags are stored in EEG.reject. You can visually inspect the rejections using this command:
pop_eegplot( EEG, 1, 1, 1);
This allows you to scroll through the EEG data. You have the option to manually add or remove rejections by clicking the trials of interest. Once you are done, you can press the "Reject" button and it will remove all trials flagged for rejection.

To simply apply the pipeline's rejections automatically, you can use the command:
EEG = pop_rejepoch(EEG,EEG.reject.rejmanual,0);

Optionally, you can align the channels and stack them during visual inspection. To do this, use the align_channels function before visual inspection with this command:
EEG = align_channels(EEG,true)
After plotting the EEG, press the "Stack" button and all EEG channels will be aligned in the middle. EOG and Stimtrak will be above. Eyetracking will be below. Then you can reject as usual. It is recommended that you undo the alignment before saving your data. Do this with the same function:
EEG = align_channels(EEG,false)

Options

subjectParentDir (str): folder that contains subjects' data folders
subjectDirectories (cell array of str): which subject folders to include in analysis
noEyetracking (cell array of str): which subjects to not do eyetracking rejection on
doEogRejection (cell array of str): which subject to do EOG rejection on

lowboundFilterHz (float): lower range for bandpass filtering of EEG
highboundFilterHz (float): upper range for bandpass filtering of EEG

rerefType (str): what type of referencing to do on EEG
rerefExcludeChans (cell array of str): which, if any, channels to exclude from rereferencing (e.g. you shouldn't rereference EOG channels)

EYEEEGKeyword (str): keyword sent with eyetracking messages to sync events to portcodes
startEvent (int): portcode to signal beginning of session (can be the first instance of many)
endEvent (int): portcode to signal end of session (can be the last instance of many)
eyeRecorded (str): which eyes were tracked

binlistFile (str):
timelockCodes (vector of int): portcodes to timelock to (will become time 0 in epoch)
trialStart (float): how many milliseconds to grab before timelocked event
trialEnd (float): how many milliseconds to grab after timelocked event
baselineStart (float): beginning of baseline period of epoch
baselineEnd (float): ending of baseline period of epoch
rejectionStart (float): beginning of artifact rejection period of epoch (useful if you only want to reject based on a portion of epoch)
rejectionEnd (float): ending of artifact rejection period of epoch

eyeMoveThresh (float): eye movement rejection threshold in degrees
distFromScreen (float): how many millimeters from screen subject sits
monitorWidth (float): monitor width in mm
monitorHeight (float): monitor height in mm
screenResX (float): monitor resolution width in pixels
screenResY (float): monitor resolution height in pixels
(the previous 5 parameters are necessary for calculating degrees of eye movement)

eegResampleRate (float): optional sampling rate to resample EEG at
eegResample (bool): set to true to resample EEG

eogThresh (float): eog rejection threshold in microvolts

eegThresh (float): eeg rejection threshold in microvolts
eegNoiseThresh (float): eeg noise rejection threshold in microvolts (see pop_artmwppth in ERPLAB)
eegMinSlop (flot): %minimal absolute slope of the linear trend of the activity for rejection
eegResample (bool): %minimal R^2 for rejection

rejFlatline (bool): remove trials with flatline data