Contents

%%%Om #!/usr/local/bin/matlab%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MATLAB Script to interpolate missing channels (and throw some away)
% 1. Load THE_ICA_PRUNED_DATASET from the previous step.
% 2. Interpolate missing channels
% 3. And if you like, throw away some peripheral channels (optional)
% 4. Save the dataset.
% 5. Export it to the good old EEP format using the eepio plugin.
%    https://github.com/widmann/eepio
%
% Author: R. Muralikrishnan -- 24.02.2017; Last modified: 07.03.2017
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%m
clear all;
close all;

eeglab;

V_Folder_EEGLabData = '/home/muralir/Documents/AB/Experiments/NeuroFemi/EEGLab-Data/';

V_Participant = 'xx';
% CA_x => CellArray
% CA_Participants = {'NF01','NF02','NF03','NF05','NF06','NF07','NF09','NF10','NF11','NF12','NF13','NF14','NF15','NF16','NF20','NF21','NF22','NF23','NF24','NF25','NF27','NF28','NF30','NF32','NF33','NF34','NF37','NF38','NF39','NF42','NF43','NF45','NF46','NF47','NF48','NF49','NF51','NF52','NF53','NF54','NF55','NF56'};

Participants who are ruled out a priori, and for whom NO ICA needs to be done

% NF41, NF36 : Incomplete/non-existent data
% NF29, NF44, NF50 : Left-handed/handedness unclear
% NF04, NF08, NF17, NF18, NF19, NF26, NF31, NF35, NF40 : Too few correct responses. See Avr-Rej-Details-Filetered.txt (in EEG-Data folder).
% NF21      ADJUST SASICA didn't work for some reason!

% Remaining participants 56-15 = 41.

INTERPOLATE MISSING CHANNELS and WRITE CNT DATA

CA_Participants = {'NF01','NF02','NF03','NF05','NF06','NF07','NF09','NF10','NF11','NF12','NF13','NF14','NF15','NF16','NF20','NF22','NF23','NF24','NF25','NF27','NF28','NF30','NF32','NF33','NF34','NF37','NF38','NF39','NF42','NF43','NF45','NF46','NF47','NF48','NF49','NF51','NF52','NF53','NF54','NF55','NF56'};

%CA_Participants = {'NF01'};

for V_Counter = 1:length(CA_Participants)
    V_Participant = CA_Participants{V_Counter};

    V_DataFile = fullfile(V_Folder_EEGLabData, V_Participant, [V_Participant, '_bp03_40r_ica_pruned.set']);
    EEG = pop_loadset('filename', V_DataFile);

INTERPOLATE missing channels

    % Adapted from Katrin Cunitz
    % Depends on mg_eeg_interpol_spherical.m by Maren Grigutsch, which is
    % minimally modified to not perform average referencing of the data.

    % Settings for channel interpolation (using spherical spline method).

    ElectrodeLocations_file = 'GSN-HydroCel-129.sfp';
    ElectrodeLocations = readlocs(ElectrodeLocations_file);
    ElectrodeLocations = ElectrodeLocations(4:end);             % Exclude Fiducial Channels (1 to 3)
    ElectrodeLocations = pop_chancenter(ElectrodeLocations,[]); % See the following script for details about centering

    % Spherical Interpolation of all missing channels
    EEG = mg_eeg_interpol_spherical(EEG,ElectrodeLocations);

Remove most channels in the periphery (again, because they were re-introduced in the interpolation above)!

    EEG = pop_select(EEG, 'nochannel', [1,121,114,95,89,82,74,69,64,44,38,32,120,113,107,99,94,88,81,73,68,63,56,49,43,119,48]);

    % Save the resultant file as an EEGLab .set

    EEG.filename = [V_Participant '_bp03_40r_sphint'];
    EEG.filepath = [V_Folder_EEGLabData, V_Participant];
    EEG.comments = char([V_Participant, '_bp03_40r_sphint'], '; Sampling Rate: 500 Hz; BPF: 0.3-40 Hz; ReRef: Linked Mastoids; SASICA based ICA Pruned Original Data with interpolated missing channels');
    pop_saveset(EEG, 'filename', EEG.filename, 'filepath', EEG.filepath);

WRITE the ICA Pruned Interpolated dataset as EEP CNT/TRG files using EEPIO plugin functions

Use the EEPIO plugin to export the EEGLab .set as a .cnt file. The 'noboundaryevents' argument needs to be set to 1 if no rejections were performed on the dataset within EEGLab (and thus there won't be any boundary events). For datasets such as xyz_ica_out.set, in which there are boundary events due to pre-ICA clean-up rejections, this argument is optional (this was the default)...but if supplied, it must be set to 0. We've adapted pop_writeeepcnt and pop_writeeeptrg to introduce the noboundaryevents argument, and handle files with and without boundary events appropriately.

    CNT_filename = [V_Participant '_bp03_40r_sphint.cnt'];
    TRG_filename = [V_Participant '_bp03_40r_sphint.trgcorcues'];
    CNT_filepath = [V_Folder_EEGLabData, V_Participant];

    % Export CNT and TRG files using the eepio plugin

    pop_writeeepcnt(EEG, 'filename', CNT_filename, 'pathname', CNT_filepath, 'noboundaryevents', 1);
    pop_writeeeptrg(EEG, 'filename', TRG_filename, 'pathname', CNT_filepath, 'noboundaryevents', 1);


    fprintf('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n');
    fprintf('Saved ICA Pruned Interpolated data as EEP CNT file ... %s.\n\n', V_Participant);
    fprintf('########################################################\n\n');

%  Om
end;