[FieldTrip] Source Reconstruction - Leadfield has NaNs

tibor.auer at gmail.com tibor.auer at gmail.com
Sun Dec 26 17:45:47 CET 2021

Dear Emilie,


It is usually due to rank deficiency in the leadfield. I suggest removing the affected sources. See how it is implemented in Automatic Analysis:


I hope it helps.


Kind regards,



Dr Tibor Auer, MD., PhD.

 <mailto:tibor.auer at gmail.com> tibor.auer at gmail.com


 <https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftwitter.com%2FTiborAuer&data=04%7C01%7Ct.auer%40surrey.ac.uk%7C5f32dba325f5422f5c5a08d8becc029f%7C6b902693107440aa9e21d89446a2ebb5%7C0%7C0%7C637469131016806177%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=wkpejqTmmo%2Fe4JA9QIaA6Z3%2BzipbFY%2FCEmRXC9UvKJs%3D&reserved=0> @TiborAuer


Feladó: fieldtrip <fieldtrip-bounces at science.ru.nl> E személy nevében: Emilie Caspar via fieldtrip
Küldve: 09 December 2021 11:16
Címzett: FieldTrip discussion list <fieldtrip at science.ru.nl>
Másolatot kap: Emilie Caspar <ecaspar at ulb.ac.be>
Tárgy: [FieldTrip] Source Reconstruction - Leadfield has NaNs


Dear Fieldtripper, 

I am currently trying to compute a source reconstruction on my EEG data (Biosemi, 64 electrodes).


I use the following code:


load Subject01_sourcemodel_15684;

headmodel = ft_read_headmodel('headmodel/standard_bem.mat');





cfg = [];

cfg.method = 'interactive';

cfg.elec = electr_pos;

cfg.headshape = headmodel.bnd(1); %1 = skin

elec = ft_electroderealign(cfg, electr_pos);


cfg         = [];

cfg.elec = elec;   % sensor information

cfg.channel = elec.label;%;  % the used channels

cfg.sourcemodel    = sourcemodel;   % source points

cfg.headmodel = headmodel;   % volume conduction model

cfg.singleshell.batchsize = 5000; % speeds up the computation

leadfield   = ft_prepare_leadfield(cfg);


cfg               = [];

cfg.method        = 'mne';

cfg.elec = elec;

cfg.grid          = leadfield;

cfg.headmodel     = headmodel;

cfg.mne.prewhiten = 'yes';

cfg.mne.lambda    = 3;

cfg.mne.scalesourcecov = 'yes';


source_GA_GroupPerpetrators_Parents_Neutral_DOUL = ft_sourceanalysis(cfg, GA_GroupPerpetrators_Parents_Neutral_DOUL);


However, I got the following error when computing the ft_sourceanalysis:


Error using svd

Input to SVD must not contain NaN or Inf.


Error in beamformer_lcmv>pinv (line 415)

  [U,S,V] = svd(A,0);


Error in beamformer_lcmv (line 297)

    filt = pinv(lf' * invCy * lf) * lf' * invCy;              % van Veen eqn.

    23, use PINV/SVD to cover rank deficient leadfield


Error in ft_sourceanalysis (line 950)

      dip(i) = beamformer_lcmv(grid, sens, headmodel, squeeze_avg, squeeze_Cy,



I checked in all the datafiles I use, and the only NaN I found are in the leadfield.leadfield but all the previous steps appear to be correct and contain the correct electrode locations, data, covariance matrix etc.


I am thus not sure how to solve the problem and why my leadfield.leadfield has NaN (or even if the problem comes from there).


Thank you in advance for your help!



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20211226/ef2420e4/attachment.htm>

More information about the fieldtrip mailing list