[FieldTrip] DICS for EEG
Anwar, Abdul Rauf
aanwar at ukaachen.de
Tue Sep 3 18:26:07 CEST 2024
Hi
I am trying to use the DICS method on the simulated EEG data. I have used template head model and source model. However, I am still unable to find the source in the correct position. I have also ensured that electrodes are well aligned with the head model. Below given is the script. Any further directions to pursue will be appreciated.
Thanks
% Add FieldTrip path and set defaults
addpath('C:\ToolBoxes\fieldtrip-20240110');
ft_defaults;
frequency = 10; % Frequency of interest
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create template head model and source model and lead field matrix
mri = ft_read_mri('C:\ToolBoxes\fieldtrip-20240110\template\headmodel\standard_mri.mat');
cfg = [];
segmented_mri = ft_volumesegment(cfg, mri);
headmodel = load('C:\ToolBoxes\fieldtrip-20240110\template\headmodel\standard_bem.mat'); % Load a standard BEM model
headmodel=headmodel.vol;
sourcemodel=load('C:\ToolBoxes\fieldtrip-20240110\template\sourcemodel\standard_sourcemodel3d5mm.mat');
sourcemodel=sourcemodel.sourcemodel;
elec = ft_read_sens('C:\ToolBoxes\fieldtrip-20240110\template\electrode\standard_1020.elc');
cfg = [];
cfg.grid = sourcemodel;
cfg.elec = elec; % Standard electrode positions (e.g., 10-20 system)
cfg.headmodel = headmodel;
cfg.reducerank = 2; % Reduce rank for EEG
leadfield = ft_prepare_leadfield(cfg);
%%%%%%%%%%%%%%%%%%%
% Create simulated data
cfg = [];
cfg.ntrials = 10;
cfg.triallength = 10;
cfg.fsample = 1000;
cfg.dip.unit = 'mm';
cfg.dip.pos = [-40 -20 50]; % left motor cortex
cfg.dip.mom = cfg.dip.pos/norm(cfg.dip.pos); % radial
cfg.dip.frequency = frequency;
cfg.elec = elec;
cfg.headmodel = headmodel;
data = ft_dipolesimulation(cfg);
%figure
%ft_plot_dipole(cfg.dip.pos, cfg.dip.mom, 'unit', 'mm')
figure
ft_plot_sens(elec, 'label', 'label');
ft_plot_headmodel(headmodel);
%%%%%%%%%%%%%%%%%%%
% Create reference channel for coherence
trial = cell(size(data.trial));
for k = 1:numel(trial)
trial{k} = sin(2.*pi.*frequency.*data.time{k});
end
refdata.trial = trial;
refdata.time = data.time;
refdata.label = {'refchan'};
data = ft_appenddata([], data, refdata);
%%%%%%%%%%%%%%%%%%%
% Time frequency analysis
cfg = [];
cfg.method = 'mtmfft';
cfg.output = 'powandcsd';
cfg.tapsmofrq = 4;
cfg.foilim = [frequency frequency];
freq = ft_freqanalysis(cfg, data);
%%%%%%%%%%%%%%%%%%%%
% DICS source analysis
cfg = [];
cfg.method = 'dics';
cfg.frequency = frequency;
cfg.grid = leadfield;
cfg.headmodel = headmodel;
cfg.dics.projectnoise = 'yes';
cfg.dics.lambda = '10%';
cfg.dics.keepfilter = 'yes';
cfg.dics.realfilter = 'yes';
cfg.channel = 'EEG';
cfg.senstype = 'eeg';
cfg.refchan = {'refchan'};
cfg.elec = elec;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plotting the source
source = ft_sourceanalysis(cfg, freq);
sourceNAI = source;
sourceNAI.avg.pow = source.avg.pow ./ source.avg.noise;
cfg = [];
cfg.downsample = 2;
cfg.parameter = 'pow';
sourceNAIInt = ft_sourceinterpolate(cfg, sourceNAI , mri);
maxval = max(sourceNAIInt.pow, [], 'all');
cfg = [];
cfg.method = 'ortho';
cfg.funparameter = 'pow';
cfg.funcolormap = 'cool';
ft_sourceplot(cfg, sourceNAIInt);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240903/60713cbb/attachment.htm>
More information about the fieldtrip
mailing list