Fieldtrip: ERPs epoching

with ICA artifact rejection

L. Bottemanne
2 min readJan 7, 2017

A script using the Matlab function do_epoch_ica.m

Go back to the reference page

Asual, first tell Matlab where your data and your scripts are and you load filedtrip.

Then, you give the specifications for the ICA rejection (that uses data files obtained from previously ran ICAs here) and for trial definition:

%%% path where datafiles from ICAs are
icapath = [datpath 'ica/'];
%%% list of the subjects (function) and nb of recording sessions %%% per subject
subjects_list = suj();
nb_blocks = 4;
%%% list of the events of interest (column of strings) for markers to %%% average:
eplist = {'event1'; 'event2'; 'eventN'};
%%% pre- and -post time windows (decimal number - 'double')
prewin = 0.2;
poswin = 0.8;

And you can perform do_epoch_ica.m in a loop , which uses the function do_epoch_ica.m:

for e = 1:size(eplist,1)


EventOfInterest = eplist(e,:);
disp (' '); disp(EventOfInterest);disp (' ');

for s = 1:size(subjects_list,1)
subject_id = subjects_list(s,:);


proc(1:nb_blocks) = NaN;

for block = 1:nb_blocks;
%%% ######
cleandata = do_epoch_ica(icapath, subject_id, block, ...
EventOfInterest, prewin, poswin);
%%% ######
%%% once the analysis is performed, reload the data with
%%% ft_preprocessing (!! needed step to finish ica rejection!)
cfg = [];
proc(block) = ft_preprocessing(cfg, cleandata);
clear cleandata;

end;% for block
%%% put all recorded sessions (block) for a subject in a
%%% single dataset matrix
datatot = ft_appenddata(cfg, ...
proc(1), proc(2), proc(3), proc(4));
datatot.grad = proc(1).grad;
clear proc;
%%% save the subject analyzed data
filename = [char(subjects_list (s,:)) ...
'_datatot_'char(eplist(e,:))];
save ([datpath filename], 'datatot', '-v7.3');
clear datatot;

end; % % for s
end; % for e
disp(' '); disp('done'); disp(' ');

Go back to the reference page

--

--