[FieldTrip] Source analysis of EEG oscillatory activity/ NaN values in the leadfield matrices
Tyler Grummett
tyler.grummett at flinders.edu.au
Tue Jul 22 03:50:14 CEST 2014
Hello Azadeh,
Again, fieldtrip experts please let me know if I am wrong, I dont want to lead azadeh or myself astray.
The code I use to create my headmodel is the following:
cfg = [];
cfg.write = 'no';
cfg.coordsys = 'spm';
cfg.output = { 'scalp', 'skull', 'brain'};
segmentedmri = ft_volumesegment(cfg, mri);
cfg = [];
cfg.method = 'iso2mesh';
cfg.numvertices = 10000;
bnd = ft_prepare_mesh( cfg, segmentedmri);
% fix mesh
[ bnd( 1).pnt, bnd( 1).tri] = meshresample( bnd( 1).pnt, bnd( 1).tri, 1000/size( bnd( 1).pnt, 1));
[ bnd( 2).pnt, bnd( 2).tri] = meshresample( bnd( 2).pnt, bnd( 2).tri, 2000/size( bnd( 2).pnt, 1));
[ bnd( 3).pnt, bnd( 3).tri] = meshresample( bnd( 3).pnt, bnd( 3).tri, 3000/size( bnd( 3).pnt, 1));
for ii = 1:size( bnd),
[ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'dup');
[ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'isolated');
[ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'deep');
[ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'meshfix');
end
% calculate headmodel % reordered to brain skull scalp
cfg = [];
cfg.method = 'bemcp'; %openmeeg doesnt work with multiple output from ft_volumesegment
vol = ft_prepare_headmodel(cfg, bnd);
clear bnd
Also with your previous issue:
??? Error using ==> svd
Input to SVD must not contain NaN or Inf.
Error in ==> beamformer_dics>pinv at 650
[U,S,V] = svd(A,0);
Error in ==> beamformer_dics at 339
filt = pinv(lf' * invCf * lf) * lf' * invCf; % Gross eqn. 3, use PINV/SVD to cover rank
deficient leadfield
Error in ==> ft_sourceanalysis at 572
dip(i) = beamformer_dics(grid, sens, vol, [], squeeze(Cf(i,:,:)), optarg{:});
Error in ==> test_sourceanalysis at 12
sourceTF = ft_sourceanalysis(cfg, data_TF);
Can you check the variables lf invCf
lf should be: number of channels x 3
invCf should be: number of channels x number of channels
Previously I would get an error if the number of channels didnt match up because when I select only EEG channels, it doesnt update
the data.elec field. So you may need to check that also.
Hopefully this works.
tyler
*************************
Tyler Grummett ( BBSc, BSc(Hons I))
PhD Candidate
Brain Signals Laboratory
Flinders University
Rm 5A301
Ext 66124
________________________________
From: fieldtrip-bounces at science.ru.nl <fieldtrip-bounces at science.ru.nl> on behalf of Azadeh Hajihosseini <azadehh at uvic.ca>
Sent: Tuesday, 22 July 2014 3:42 AM
To: FieldTrip discussion list
Subject: Re: [FieldTrip] Source analysis of EEG oscillatory activity/ NaN values in the leadfield matrices
Hi Tyler,
Thanks for responding! Actually, I have 51 electrodes. I also checked the units again and they are all 'mm'.
It looks like there is a problem in preparing the head model because when I call the line:
vol = ft_prepare_headmodel(cfg, segmentedmri_template),
there is this warning:
Warning: Matrix is singular, close to singular or badly scaled.
Results may be inaccurate. RCOND = NaN.
coming from ft_headmodel_bemcp. Any idea about this?
Thanks again!!
Azadeh
On Sun, Jul 20, 2014 at 2:14 AM, Tyler Grummett <tyler.grummett at flinders.edu.au<mailto:tyler.grummett at flinders.edu.au>> wrote:
Also are the units the same for your Headmodel, electrodes and sourcemodel(?)
Sent from my iPad
On 20 Jul 2014, at 4:08 pm, "Tyler Grummett" <tyler.grummett at flinders.edu.au<mailto:tyler.grummett at flinders.edu.au>> wrote:
I don't know if this advice is at all correct but I usually get that error if I've got a relatively small number of electrodes (~29) or a small data set (30 seconds of data).
Does that sound familiar?
I usually clear all and run it again and it will work eventually haha
Sent from my iPad
On 19 Jul 2014, at 8:01 am, "Azadeh Hajihosseini" <azadehh at uvic.ca<mailto:azadehh at uvic.ca>> wrote:
Hello FieldTrip members,
I am trying to source localize EEG oscillatory activity and have a few problems in constructing the forward model and eventually running the source analysis. I think the problems are related to each other. Here is what happens:
1- When I run the source analysis, I get this error message:
??? Error using ==> svd
Input to SVD must not contain NaN or Inf.
Error in ==> beamformer_dics>pinv at 650
[U,S,V] = svd(A,0);
Error in ==> beamformer_dics at 339
filt = pinv(lf' * invCf * lf) * lf' * invCf; % Gross eqn. 3, use PINV/SVD to cover rank
deficient leadfield
Error in ==> ft_sourceanalysis at 572
dip(i) = beamformer_dics(grid, sens, vol, [], squeeze(Cf(i,:,:)), optarg{:});
Error in ==> test_sourceanalysis at 12
sourceTF = ft_sourceanalysis(cfg, data_TF);
2- Checking the leadfiled matrices, I see there are a lot of NaN values.
3- When I visualize the head model I have created, the plots don't look right. The third field, vol.bnd(3), which is supposed to be the brain tissue, looks like a cube.
And here are my code lines:
% CONSTRUCT A HEAD MODEL from the template mri in FT's template/anatomy
mri = ft_read_mri('template\anatomy\single_subj_T1.nii');
mri.coordsys = 'spm';
%SEGMENTATION:
cfg = [];
cfg.output = {'brain','skull','scalp'};
segmentedmri_template = ft_volumesegment(cfg, mri); % Using NOT resliced data
save segmentedmri_template segmentedmri_template
%CREATE THE HEAD MODEL (VOLUME CONDUCTION MODEL)
cfg = [];
cfg.method ='bemcp';
cfg.tissue ={'brain','skull','scalp'};
% cfg.outputfile = 'template_';
vol = ft_prepare_headmodel(cfg, segmentedmri_template);
save vol vol
%Visualization of the head model
figure;
ft_plot_mesh(vol.bnd(1),'facecolor','none'); %scalp
figure;
ft_plot_mesh(vol.bnd(2),'facecolor','none'); %skull
figure;
ft_plot_mesh(vol.bnd(3),'facecolor','none'); %brain This one looks like a cube
% Align electrodes
elec = ft_read_sens('template\electrode\standard_1020.elc');
% load volume conduction model
% load vol;
%interactive allignment
cfg = [];
cfg.method = 'interactive';
cfg.elec = elec;
cfg.headshape = vol.bnd(1);
elec_aligned = ft_electroderealign(cfg);
save elec_aligned elec_aligned
% Prepare leadfield
load data_TF
cfg=[];
cfg.vol = vol; %structure with volume conduction model
cfg.elec = elec_aligned;%structure with electrode positions
[grid] = ft_prepare_leadfield(cfg, data_TF);
% Find source
cfg = [];
cfg.method = 'dics';
cfg.frequency = 25;
cfg.grid = grid;
cfg.vol = vol;
cfg.latency = .4;%single number in seconds, for time-frequency analysis
cfg.dics.projectnoise = 'yes';
cfg.dics.lambda = 0;
cfg.elec = elec_aligned;%structure with electrode positions
sourceTF = ft_sourceanalysis(cfg, data_TF);
I am using wavelet with a fourier output for the time-frequency analysis (data_TF). Do you have any idea what might be wrong here?
I also have a more general question. What type of time-frequency data can be input to source analysis? ft_freqanalysis provides power, power and cross-spectra, and complex fourier outputs. But is source-localization based on only power data correct? I couldn't find any explanations regarding this issue in the tutorial.
I look forward to hearing from anyone who might have ideas about any of these issues!
Many thanks,
--
Azadeh HajiHosseini
_______________________________________________
fieldtrip mailing list
fieldtrip at donders.ru.nl<mailto:fieldtrip at donders.ru.nl>
http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
_______________________________________________
fieldtrip mailing list
fieldtrip at donders.ru.nl<mailto:fieldtrip at donders.ru.nl>
http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
_______________________________________________
fieldtrip mailing list
fieldtrip at donders.ru.nl<mailto:fieldtrip at donders.ru.nl>
http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20140722/4e6e7749/attachment-0002.html>
More information about the fieldtrip
mailing list