problems while calculating leadfield

Nathan Weisz nathanweisz at MAC.COM
Mon Dec 15 14:25:39 CET 2008

hi robert,

thanks for your help.

i tried the singleshell option, but calculating the leadfield still
makes problems.

here some code:

cfg.headshape=hs; %hs nx3 in cm


This seems to work fine:

K>> vol

vol =

      bnd: [1x1 struct]
     type: 'nolte'

K>> vol.bnd.pnt(1:3,:)

ans =

    -3.2750   -4.6410   -0.8710
    -3.2750   -4.6410   -0.8710
    -0.8710   -5.8870   -0.9760

K>> vol.bnd.tri(1:3,:)

ans =

          935         843         936
          912        1007         911
         1803        1802        1692

However when I attempt to calculate the leadfield:



I get following error:

using headmodel specified in the configuration
using gradiometers specified in the configuration
computing surface normals
Warning: Divide by zero.
 > In normals at 60
   In prepare_headmodel at 323
   In prepare_leadfield at 223
   In newcat_calcgrid at 39
Warning: Matrix is singular, close to singular or badly scaled.
          Results may be inaccurate. RCOND = NaN.
 > In meg_ini>getcoeffs at 94
   In meg_ini at 36
   In prepare_headmodel at 329
   In prepare_leadfield at 223
   In newcat_calcgrid at 39
creating dipole grid based on user specified 3D grid
2256 dipoles inside, 33045 dipoles outside brain
computing leadfield
computing leadfield 1/2256
??? Error using ==> svd
Input to SVD must not contain NaN or Inf.

Error in ==> compute_leadfield at 484
   [u, s, v] = svd(lf);

Error in ==> prepare_leadfield at 242
   grid.leadfield{dipindx} = compute_leadfield(grid.pos(dipindx,:),
sens, vol, 'reducerank',
   cfg.reducerank, 'normalize', cfg.normalize, 'normalizeparam',

Is there something special in the function call I have to consider
when calculating leadfields using singleshell?


On 15.12.2008, at 13:39, Robert Oostenveld wrote:

> Hi Nathan
> Each MEG channel consists of two coils, one with a weight of +1 and
> the other with a weight of -1. For a synthetic 3rd order gradiometer
> system, also the reference coils are weighted and part of the signal
> picked up at the reference channels is subtracted from the normal
> MEG channels. That means that the reference coils also get a weight
> in the output of a MEG channel.
> For setting up the volume conduction model in case of a multi-sphere
> model, for each _coil_ the corresponding sphere has to be
> determined. For the bottom and top coil (with the +1 and -1 weight)
> the two spheres are the same and correspond to the sphere fitted to
> the scalp under that channel. In case of the 3rd order synthetic
> gradiometer data, the reference coils also have a (small) weight,
> which means that also for those coils a "local" sphere has to be
> identified. At the moment assigning local spheres to the reference
> coils is not yet supported in the code.
> Probably the best would be to use the local spheres for the 2 meg
> coils and to use a single sphere that is fitted to the complete
> headshape (i.e. the "single sphere") for the reference coils. It
> requires some work though to get the bookkeeping of all coils and
> all spheres correct.
> A better solution (and the one we use here at the FCDC) might be to
> use prepare_singleshell instead of prepare_localspheres. The
> singleshell volume conduction model also approximates the geometry
> with a realistic shape, but is better for the lower part of the
> brain. In short, there are no disadvantages(*) in the singleshell
> model compared to the localspheres model, but only advantages.
> best regards,
> Robert
> *) expect perhaps that it is computationally slightly slower, and
> that the localspheres can also be constructed with a polhemus
> measured head surface, whereas the singleshell requires a segmented
> anatomical MRI.
> On 13 Dec 2008, at 18:15, Nathan Weisz wrote:
>> i have a problem while performing prepare_leadfield.
>> the data is some old CTF data i collected ~2 years ago. i
>> calculated a multisphere model in fieldtrip using
>> prepare_localspheres. this step works (i.e. i get a vol structure
>> that looks ok in my opinion). however when continuing with
>> prepare_leadfield the the program crashes.
>> here's the code:
>> cfg=[];
>> cfg.grid.xgrid='auto';
>> cfg.grid.ygrid='auto';
>> cfg.grid.zgrid='auto';
>> cfg.vol=vol;
>> cfg.grad=dataCLeConI.grad;
>> cfg.inwardshift=0;
>> cfg.grid.resolution=1;
>> cfg.reducerank=2;
>> lf=prepare_leadfield(cfg);
>> i get this error message:
>> ??? Error using ==> prepare_headmodel at 301
>> synthetic gradients not supported during volume conductor setup
>> Error in ==> prepare_leadfield at 223
>> [vol, sens, cfg] = prepare_headmodel(cfg, data);
>> Error in ==> newcat_calcgrid at 52
>> lf=prepare_leadfield(cfg);
>> i messed around with different headmodels just to see how
>> prepare_leadfield behaves:
>> *when the headmodel is a single sphere (cfg.singlesphere='yes')
>> prepare_leadfield works fine
>> *when using the nolte headmodel (via prepare_singleshell),
>> prepare_leadfield does not crash, but the leadfields contain only
>> NaN ... is that perhaps related to the issue above?
>> again, any help is greatly appreciated.
> ----------------------------------
> The aim of this list is to facilitate the discussion between users
> of the FieldTrip  toolbox, to share experiences and to discuss new
> ideas for MEG and EEG analysis. See also
>  and

The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also and

More information about the fieldtrip mailing list