ICA with Fieldtrip (1)

Independant Component Analysis — Computing

L. Bottemanne
2 min readDec 24, 2016

Go back to the reference page

First, you have to got tell Matlab where your data and your scripts are.

Then, you should also load subjects list (it is a function, that you have to create — hard-code — yourself).

subjects_list = suj();

We will also calculate the number of subject involved in the analysis (for the following analysis loop)


nb_subjects = size(subjects_list,1);

The loop that perform the ICA analysis on all subjects:

for s = 1:nb_subjects;do_icaeog(datpath, subjects_list (s,:));end; % for s

To have an exemple on how to look at its results: see Independant Component Analysis — Visualization

The function do_icaeog.m :

function comp = do_icaeog(datpath, name_file)
%%% perform an Independant Component Analysis on MEG raw data
%%% files list
filist = dir([datpath name_file '*.ds']);
%%% who are these files
disp(' '); disp(' ') ;
fprintf(' **** got datasets from %s ****', name_file)
disp('- these files are: '); disp(' ') ;
fprintf(' %s ', filist.name_file); disp(' '); disp(' ') ;
%%% load data
for f = 1:length(filist)
rawfiles= [datpath filist(f).name_file];
%%% load and preprocess the data
cfg = [];
%%%
cfg.channel = 'MEG';
cfg.dftfilter = 'yes';
cfg.dftfreq = [50 100 150];
cfg.padding = 2;
% cfg.headerfile
cfg.bpfilter = 'yes';
cfg.bpfreq = [1 150];
%%%
cfg.dataset = rawfiles;
cfg.continuous = 'yes';
cfg.demean = 'no'; %%%%

cleandata = ft_preprocessing(cfg); clear rawfiles;


%%% data resampling for speed
cfg = [];
cfg.resemplefs = 300;
cfg.detrend = 'no';
rsdata = ft_resampledata(cfg,cleandata);
clear cleandata;
if exist ([datpath 'ica'], 'dir') == 0
mkdir([datpath 'ica']);
end; % if exist
icapath = [datpath 'ica/'];
%%% raw resampled data are needed for further data analysis
save ([icapath name_file '_rsdata_block' num2str(f)], 'rsdata');
%%% the ICA itself
cfg = [];
cfg.method = 'runica';
comp = ft_componentanalysis(cfg, rsdata); clear rsdata;
save ([icapath name_file '_comp_block' num2str(f)], 'comp'); clear comp;

end; % for f
%%% the end

Go back to the reference page

--

--