User Tools

Site Tools



EEGLAB Hackathon
Main Website


This is an old revision of the document!

Be patient :) This page will go live on Wed, 5th at 10am.

Until then, check the overview page where you will find all the info about the hackathon.
You can also download the necessary files here.

Session Two: Post-Processing & Analysis (GUI)

Preparation of Day Crew Script for analysis in ERPLAB

As we have seen once we ran the Night Crew we get a set which contains ICA weights. At this point human supervision is unavoidable as we need to explore ICs and subtract the ones that are responsible for artefacts.

At the end of each set we will have saved a set which will not only contain ICA weights but which will have been corrected by subtracting ICs responsible for artefacts.

1. Loading ICAed set

We will not use pop_loadcnt() this time because the final set that the Night Crew created is in the EEGLAB format. To load a *.set file we use pop_loadset()

EEG = pop_loadset('filename', 503_ICAC.set);


2. Make ERPLab happy: epoched to continuous dataset

As we saw earlier ERPLab wants a continuous set. Luckily its developers provide a function for that:

EEG = pop_epoch2continuous(EEG);

Yes! Just as easy as this!

3. Create Eventlist

The following line will create a simple event list and will convert the “mess” created by the previous function by converting the strings boundary to a numerical value -99.

EEG  = pop_creabasiceventlist( EEG , 'AlphanumericCleaning', 'on', 'BoundaryNumeric', { -99 }, 'BoundaryString', { 'boundary' } );

4. Assign bins

Don't forget to update the path of the BDF file.

EEG  = pop_binlister( EEG , 'BDF', '/Path/Of/BDFFile', 'ExportEL', 503_bin.txt', 'IndexEL',  1, 'SendEL2', 'All', 'UpdateEEG', 'on', 'Voutput', 'EEG' );

5. Extract bin-based epochs (& baseline correct)

Does what it says on the tin. Specify limits of epoch window. Third argument sets the baseline correction (here pre for pre-stimulus interval)

EEG = pop_epochbin(EEG , [-100  1000], 'pre');

6. Detect & Mark Artefacts for rejection

  • Specify channel array, in that example we excluded VEOG & HEOG
  • Flag 1, dictates how the artefacted epoch is labeled. Here it will have a flag value of 1 but could be set tp another number (say because we want to perform other types of artefacts detections)
  • Threshold, min max array.
  • Time window, min max array
EEG  = pop_artextval( EEG , 'Channel', [1:65 67], 'Flag',  1, 'Threshold', [-75 75], 'Twindow',...
 [-100 1000] );

7. Averaging

  • Criterion:
    • 1=Exclude trials labelled as artefacts
    • 0=Include all trials
    • 2=Only trials with artefacts
    • SEM here will be calculated.
ERP = pop_averager(EEG , 'Criterion', 1, 'SEM', 'on');

NOTE: The result from the averaging is now assigned to a new object called ERP!

7. Saving ERP set

At this point we will want to save the result of our batch. While for all other previous steps we use the pop_saveset() command, because we are now dealing with and ERP set, we need another command to save this ERPset:

ERP = pop_savemyerp(ERP, 'erpname', 503_ERP , 'filename', 503_ERPs.erp');

8. Save a summary of artefact detection

It may come in handy to save a summary of the Artefact Detection for each subject so you can review it once you come back to your computer. Here's how to do that:

pop_summary_AR_eeg_detection(EEG, 503_AR_Summary.txt');


Just as we did for the Night Crew, your task now is to prepare a DayCrew that will take the ICA corrected set and bring it to an ERP set analysable by ERPLab.

For extra luxury we may want to have our script perform the following:

  • that it saves the a set after just before averaging
  • make sure your loop doesn't get stuck because of a buggy dataset.
  • save final dataset. (NOTE. when saving datasets you might want to think of a way to name the dataset with the subject information).

For REAL luxury

  • make matlab create the destination directory. Maybe you want to keep your ERPsets in a different folder from the other EEGLAB-type sets? If you feel brave think about this too.


subject={'504', '505'};
for i=1:length(subject)
   fprintf('Processing Subject #g : %s?\n', i, subject{i});
%creates the destination folder assuming you have not created it manually before
%if test makes sure the folder only gets created once.
    if isequal(exist(pathname_write, 'dir'),7) %7 = directory
        display('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Destination folder exists. All Good to go!');
        [mdirstatus, mdirmessage]=mkdir(pathname_writePostProc)
        display('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Destination folder does not exist. Chillax! Will be created');
    %add electrode positions, and specify online ref
	EEG = pop_loadcnt([pathname_read subject{i} '.cnt'] , 'dataformat', 'int32', 'memmapfile', '');
	EEG = pop_chanedit(EEG, 'append',66,'changefield',{67 'labels' 'Cz'},'lookup','/Users/pss059/Documents/MATLAB/eeglab12_0_2_5b/plugins/dipfit2.2/standard_BESA/standard-10-5-cap385.elp','setref',{'1:67' 'Cz'});
    %re-reference to common average & reconstruct signal at current reference
    EEG = pop_reref( EEG, [],'refloc',struct('labels',{'Cz'},'type',{''},'theta',{0},'radius',{0},'X',{5.2047e-15},'Y',{0},'Z',{85},'sph_theta',{0},'sph_phi',{90},'sph_radius',{85},'urchan',{67},'ref',{'Cz'},'datachan',{0}), 'exclude',[65 66]);
    %make epochs (all triggers of interest individually
    %we will in fact comment the remove baseline step since at the minute
    %we just want to cut the file to reduce dimensions.
    EEG = pop_epoch( EEG, {  '111'  '112'  '113'  '114'  '121'  '122'  '123'  '124'  '131'  '132'  '133'  '134'  '141'  '142'  '143'  '144'  '151'  '152'  '153'  '154'  '211'  '212'  '213'  '214'  '221'  '222'  '223'  '224'  '231'  '232'  '233'  '234'  '241'  '242'  '243'  '244'  '251'  '252'  '253'  '254'  }, [-0.1 1], 'epochinfo', 'yes');
    %EEG = pop_rmbase( EEG, [-100    0]);
    %We could already delete epochs which are followed by an incorrect
    %response. Although I prefer to keep this for the subsequent Day Crews
    %EEG = pop_selectevent( EEG, 'type',1,'deleteevents','off','deleteepochs','on','invertepochs','off');
    %Save set prior to filtering (in case of crash)
    EEG.setname = [subject{i} 'RREP'];
    EEG = pop_saveset( EEG,  'filename', [pathname_write subject{i} '_RREP.set']);
    %filter the data
    EEG  = pop_basicfilter( EEG,  1:67 , 'Cutoff', [ 0.1 30], 'Design', 'butter', 'Filter', 'bandpass', 'Order',  4 );
    %Save intermediary set in case ICA crashes
    EEG.setname = [subject{i} 'RREPF'];
    EEG = pop_saveset( EEG,  'filename', [pathname_write subject{i} '_RREPF.set']);
    %run ICA decomposition
    EEG = pop_runica(EEG, 'extended',1,'interupt','on');
    %Save final set
    EEG.setname = [subject{i} 'RREPFICA'];
    EEG = pop_saveset( EEG,  'filename', [pathname_write subject{i} '_RREPFICA.set']);
        disp(['%%%%%%%%%%%%%%%%%%%%%%%%%Something went wrong with participant ' subject{i} ' ! Skipping to next participant %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%']);
eeglabsessh2b.1391372455.txt.gz · Last modified: 2014/10/08 03:14 (external edit)