[FieldTrip] Source Reconstruction - Leadfield has NaNs

Anke Ninija Karabanov anke at nexs.ku.dk
Wed Dec 29 23:37:48 CET 2021

I will be out of offie from December 21st to 4th of January and will be checking my email only infrequently during this time. I will respond to your email when I return.


On 26 Dec 2021, at 17.45, Tibor Auer via fieldtrip <fieldtrip at science.ru.nl> wrote:

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.
tibor.auer at gmail.com

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!

fieldtrip mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20211229/39b51a01/attachment.htm>

More information about the fieldtrip mailing list