Fieldtrip: ERPs epoching

with ICA artifact rejection

L. Bottemanne
1 min readJan 7, 2017

Matlab function do_epoch_ica.m for the epoching script.

function cleandata = do_epoch_ica(icapath, subject_id, block, ...
EventOfInterest, prewin, poswin)
rsfile = [icapath subject_id '_rsdata_block' num2str(block)];
icafile = [icapath subject_id '_comp_block' num2str(block)];
run ica_components; % comp to reject
component_2reject = eval(['rejcomp.' subject_id '.block' num2str(block)]) ;
% load ([icapath subject_id '_rsdata_block' num2str(block)], 'rsdata');
cfg_reject=[];
cfg_reject.component = component_2reject;
load(rsfile, 'rsdata');
run markers;
cfg_cut = [];
cfg_cut.headerfile = rsdata.cfg.previous.headerfile;
cfg_cut.channel = 'MEG';
cfg_cut.trialdef.eventtype = 'UPPT001';
cfg_cut.trialdef.eventvalue = eval([char(EventOfInterest) '_markers']);
cfg_cut.trialdef.prestim = prewin;
cfg_cut.trialdef.poststim = poswin;
cfg_def = ft_definetrial(cfg_cut);
% segment it into pieces
cfg_cut= [];
cfg_cut.channel = 'MEG';
cfg_cut.continuous = 'yes';
cfg_cut.demean = 'yes';
cfg_cut.lpfilter = 'yes';
cfg_cut.lpfreq = 40;
% cfg.hpfilter = 'yes';
% cfg.hpfreq = filter.hp;
cut_rsdata = ft_preprocessing(cfg_def);
load (icafile, 'comp');%%% ICA rejection itself
cleandata = ft_rejectcomponent(cfg_reject, comp, cut_rsdata);
%%% comp is the output structure from ft_componentanalysis
% %%% cut_rsdata is the output structure from ft_resampledata
save ([icapath ...
char(subject_id) '_cleandata_block' num2str(block) '_' char(EventOfInterest)],...
'cleandata');

--

--