Functions for forward and inverse computation of EEG/MEG data

FieldTrip has a consistent set of low-level functions for forward and inverse computations, i.e. source estimation. The main reason for making the functions consistent is that that facilitates supporting the different methods in the FieldTrip toolbox. Another reason is that this allows other projects to re-use the implemented methods and perhaps also to contribute to FieldTrip.

The low-level functions are combined in the forwinv toolbox, which is released together with FieldTrip but can also be downloaded here as separate toolbox.

Features

The following forward methods are implemented for computing the electric potential (EEG):

  • single sphere
  • multiple concentric spheres with up to 4 shells
  • boundary element model (the “system matrix” should be computed outside of FieldTrip)
  • all forward models supported by the Neuromag meg-calc toolbox


The following forward methods are implemented for computing the magnetic field (MEG):

  • single sphere
  • multiple spheres, one for each sensor
  • realistic single-shell model based on leadfield expansion (Nolte method)
  • all forward models supported by the Neuromag meg-calc toolbox


The inverse methods for computing a source reconstruction can be divided into three categories: dipole fitting (using an overdetermined model with a few sources), dipole scaning (using a metric that can be computed independently on each point of a grid) and distributed source modelling (using an underdetermined distributed source model). The following source reconstruction methods are implemented

  • dipole fitting
    • simultaneous optimisation of position, orientation and strength
    • symmetry constrains and/or fixed position, with free orientation and strength
  • dipole scanning
    • dynamic imaging of coherent sources (DICS)
    • linear constrained minimum variance (LCMV)
    • partial canonical coherence (PCC)
    • multiple signal classification (MUSIC)
    • scanning for residual variance
  • distributed source modelling
    • minimum norm estimation without regularisation (MNE)

Definition of the function-calls (API)

To read in the volume conduction model and the definition of the sensor array (electrodes or gradiometers) from file, one would start with:

[vol]  = read_vol(filename)
[sens] = read_sens(filename)

If desired the volume conduction model and the sensor array can be spatially transformed using a 4×4 homogenous transformation matrix. E.g. the electrodes can be translated and rotated to align them with head coordinate system, or they can be translated and rotated to switch to another coordinate system.

[vol]  = transform_vol(transform, vol)
[sens] = transform_sens(transform, sens)

Prior to all forward and inverse computations, the following function should be called:

[vol, sens] = prepare_vol_sens(vol, sens, ...)

The only function that is subsequently required for computing the potential or field distribution is

[lf] = compute_leadfield(pos, sens, vol, ...)

The functions for the inverse computation of the source activity, i.e. for computing the source reconstruction are

[dipout] = dipole_fit(dip, sens, vol, dat, ...)
[dipout] = beamformer_dics(dip, sens, vol, dat, cov, ...)
[dipout] = beamformer_lcmv(dip, sens, vol, dat, cov, ...)
[dipout] = beamformer_pcc(dip, sens, vol, dat, cov, ...)
[dipout] = music(dip, sens, vol, dat, ...)
[dipout] = minimumnormestimate(dip, sens, vol, dat, ...)
[dipout] = residualvariance(dip, sens, vol, dat, ...)

The input array “pos” contains the dipole position (1×3 or Nx3).

The input structure “dip” contains the initial dipole model or dipole grid that is used for source reconstruction.

The input structure “sens” contains the electrode positions or the gradiometer positions and orientations.

The input structure “vol” contains the geometry and conductivity of the volume conductor model.

Most functions have additional optional input arguments that are specified as key-value pairs.

Example use of the compute_leadfield function

% create a set of electrodes, randomly placed on a sphere
elec = [];
elec.pnt = randn(128,3);
radius = sqrt(sum(elec.pnt.^2,2));
elec.pnt = elec.pnt ./ [radius radius radius];  % scale them to a unit sphere
for i=1:128
   elec.label{i} = sprintf('%03d', i);
end

% create a concentric 3-sphere volume conductor, the radius is the same as for the electrodes
vol = [];
vol.r = [0.88 0.92 1.00]; % radii of spheres
vol.c = [1 1/80 1];       % conductivity
vol.o = [0 0 0];          % center of sphere

% compute the leadfield for a dipole at position [0 0 0.5]
pos = [0 0 0.5];
lf = compute_leadfield(pos, elec, vol);

% compute the potential distribution for a dipole with x-orientation
mom = [1 0 0]';
pot = lf * mom;

% plot the 3-D distribution of the potential over the sphere surface
elec.tri = convhulln(elec.pnt)
figure
patch('faces', elec.tri, 'vertices', elec.pnt, 'FaceVertexCData', pot, 'FaceColor', 'interp')
axis equal; axis vis3d

Recent changes to the code

2010-03-09 10:19  roboos

	* senstype.m: removed double piece of code, which contained a bug (sens -> input)

2010-03-04 13:10  roboos

	* private/lmoutr.mexw64, private/plgndr.mexw64, private/ptriproj.mexw64,
	  private/solid_angle.mexw64: added a number of mex files compiled for windows 64, thanks to
	  Denes Szucs

2010-03-02 16:53  roboos

	* private/lmoutr.m, private/ptriproj.m, private/solid_angle.m: corrected the m-file
	  wrappers, the geometry.c file also has to be compiled and linked into the mex file

2010-02-18 16:19  roboos

	* senstype.m: changed the labels of the Yokogawa MEG channels according to the
	  suggestion by Tillmann Sander-Thoemmes: "use the abbreviated
	  description of the channel type as the label prefix, e.g., the axial
	  gradiometers would have the prefix AG, the reference magnetometers
	  would be RM, etc. These abbreviations are something that Yokogawa
	  users would recognize as the textual descriptions appear in the
	  Yokogawa software and the manual"

2010-02-17 09:11  roboos

	* compute_leadfield.m, prepare_vol_sens.m: added support for computing MEG forward models
	  using OpenMEEG,
	  thanks to the work from Emmanuel Olivi who is currently a PhD student
	  under Maureen Clerc's supervision.

2010-02-08 13:32  roboos

	* ., apply_montage.m, convert_units.m, estimate_units.m, private, private/getsubfield.m,
	  private/hastoolbox.m, private/issubfield.m, private/keyval.m, private/match_str.m,
	  private/progress.m, private/rmsubfield.m, private/setsubfield.m: replaced the symlinks by
	  svn file externals, should also work on windows

2010-01-29 10:12  jansch

	* beamformer_lcmv.m: changed projection of subspace-based filter into pinv

2010-01-07 10:14  roboos

	* private/eeg_leadfield4_prepare.m: eeg_leadfield4_prepare got lost during the cvs->svn
	  conversion, added it again

2010-01-04 16:51  roboos

	* senstype.m: fixed bug due to inconsistency between data.grad and data.hdr.grad after
	  megplanar, senstype would first look at data.hdr.grad and incorrectly judge that it was
	  axial ctf151/ctf275

2010-01-02 14:55  crimic

	* prepare_vol_sens.m: subscript indexes change in interp variable

2009-12-16 12:37  roboos

	* private/elproj.m: ifixed a typo in the documentation (ortHo)

2009-12-09 17:00  roboos

	* senslabel.m, senstype.m: multiple modifications to get better support for the yokogawa
	  system
	  channels are now labeled as {'1', '2', ...}

2009-12-09 12:50  roboos

	* senslabel.m, senstype.m: changed the channel naming of the yokogawa160 system

2009-12-04 10:00  roboos

	* COPYING, README, beamformer_dics.m, beamformer_lcmv.m, beamformer_pcc.m,
	  compute_leadfield.m, dipole_fit.m, inside_vol.m, minimumnormestimate.m, music.m,
	  prepare_vol_sens.m, private/avgref.m, private/bounding_mesh.m, private/eeg_leadfield1.m,
	  private/eeg_leadfield4.m, private/eeg_leadfieldb.m, private/elproj.m,
	  private/find_innermost_boundary.m, private/find_inside_vol.m,
	  private/find_outermost_boundary.m, private/fitsphere.m, private/fixdipole.m,
	  private/inf_medium_leadfield.m, private/leadsphere_all.m, private/legs.m,
	  private/lmoutr.m, private/lmoutr.mexa64, private/lmoutr.mexglx, private/lmoutr.mexmac,
	  private/lmoutr.mexmaci, private/lmoutr.mexw32, private/magnetic_dipole.m,
	  private/meg_forward.m, private/meg_ini.m, private/meg_leadfield1.m,
	  private/meg_leadfield1.mexa64, private/meg_leadfield1.mexglx,
	  private/meg_leadfield1.mexmac, private/meg_leadfield1.mexmaci,
	  private/meg_leadfield1.mexw32, private/normals.m, private/plgndr.m, private/plgndr.mexa64,
	  private/plgndr.mexglx, private/plgndr.mexmac, private/plgndr.mexmaci,
	  private/plgndr.mexw32, private/project_elec.m, private/ptriproj.m,
	  private/ptriproj.mexa64, private/ptriproj.mexglx, private/ptriproj.mexmac,
	  private/ptriproj.mexmaci, private/ptriproj.mexw32, private/solid_angle.m,
	  private/solid_angle.mexa64, private/solid_angle.mexglx, private/solid_angle.mexmac,
	  private/solid_angle.mexmaci, private/solid_angle.mexw32, private/sphfit.m,
	  private/transfer_elec.m, private/triangle4pt.m, residualvariance.m, senslabel.m,
	  senstype.m, sourcedepth.m, transform_headshape.m, transform_sens.m, transform_vol.m,
	  voltype.m: set the executable property to OFF on many files that should not be executable
	  (m-files, mex-files, readme, etc.)

2009-12-02 16:20  roboos

	* private/lmoutr.m: added matlab code for auto-compilation

2009-12-02 16:15  roboos

	* private/ptriproj.m, private/solid_angle.m: added matlab code for auto-compilation

2009-11-30 11:28  roboos

	* private/avgref.m, private/bounding_mesh.m, private/eeg_leadfield1.m,
	  private/eeg_leadfield4.m, private/eeg_leadfieldb.m, private/elproj.m,
	  private/find_innermost_boundary.m, private/find_outermost_boundary.m,
	  private/meg_leadfield1.m: changed all occurences of tabs into 4 spaces

2009-11-30 08:53  roboos

	* apply_montage.m, beamformer_dics.m, beamformer_lcmv.m, beamformer_pcc.m,
	  compute_leadfield.m, convert_units.m, dipole_fit.m, estimate_units.m, inside_vol.m,
	  minimumnormestimate.m, music.m, prepare_vol_sens.m, private/avgref.m,
	  private/bounding_mesh.m, private/eeg_leadfield1.m, private/eeg_leadfield4.m,
	  private/eeg_leadfieldb.m, private/elproj.m, private/find_innermost_boundary.m,
	  private/find_inside_vol.m, private/find_outermost_boundary.m, private/fitsphere.m,
	  private/fixdipole.m, private/getsubfield.m, private/hastoolbox.m,
	  private/inf_medium_leadfield.m, private/issubfield.m, private/keyval.m,
	  private/leadsphere_all.m, private/legs.m, private/lmoutr.m, private/magnetic_dipole.m,
	  private/match_str.m, private/meg_forward.m, private/meg_ini.m, private/meg_leadfield1.m,
	  private/normals.m, private/plgndr.m, private/progress.m, private/project_elec.m,
	  private/ptriproj.m, private/rmsubfield.m, private/setsubfield.m, private/solid_angle.m,
	  private/sphfit.m, private/transfer_elec.m, private/triangle4pt.m, residualvariance.m,
	  senslabel.m, senstype.m, sourcedepth.m, transform_headshape.m, transform_sens.m,
	  transform_vol.m, voltype.m: changed svn property for keywords Log and Rev

2009-11-30 08:49  roboos

	* apply_montage.m, beamformer_dics.m, beamformer_lcmv.m, beamformer_pcc.m,
	  compute_leadfield.m, convert_units.m, dipole_fit.m, estimate_units.m, inside_vol.m,
	  minimumnormestimate.m, music.m, prepare_vol_sens.m, private/avgref.m,
	  private/bounding_mesh.m, private/eeg_leadfield1.m, private/eeg_leadfield4.m,
	  private/eeg_leadfieldb.m, private/elproj.m, private/find_innermost_boundary.m,
	  private/find_inside_vol.m, private/find_outermost_boundary.m, private/fitsphere.m,
	  private/fixdipole.m, private/getsubfield.m, private/hastoolbox.m,
	  private/inf_medium_leadfield.m, private/issubfield.m, private/keyval.m,
	  private/leadsphere_all.m, private/legs.m, private/lmoutr.m, private/magnetic_dipole.m,
	  private/match_str.m, private/meg_forward.m, private/meg_ini.m, private/meg_leadfield1.m,
	  private/normals.m, private/plgndr.m, private/progress.m, private/project_elec.m,
	  private/ptriproj.m, private/rmsubfield.m, private/setsubfield.m, private/solid_angle.m,
	  private/sphfit.m, private/transfer_elec.m, private/triangle4pt.m, residualvariance.m,
	  senslabel.m, senstype.m, sourcedepth.m, transform_headshape.m, transform_sens.m,
	  transform_vol.m, voltype.m: changed svn property eol-style to native to ensure consistent
	  end-of-line behaviour on windows and linux

2009-11-25 09:00  crimic

	* compute_leadfield.m: added condition for openmeeg in reducerank snippet

2009-11-20 08:57  roboos

	* senstype.m: fixed detection of number of coils, thanks to Till

2009-11-17 14:41  crimic

	* private/eeg_leadfieldb.m: openmeeg leadfield managed now outside (in compute_leadfield.m)

2009-11-17 14:39  crimic

	* compute_leadfield.m: updated help

2009-11-17 14:38  crimic

	* compute_leadfield.m: small fix

2009-11-17 14:36  crimic

	* compute_leadfield.m: added separeted option for openmeeg

2009-11-17 10:51  crimic

	* private/eeg_leadfieldb.m: leadfield supports openmeeg

2009-11-17 10:19  crimic

	* prepare_vol_sens.m: fixed bug

2009-11-17 10:13  crimic

	* prepare_vol_sens.m: compatibility with openmeeg managed, now performs electrodes
	  interpolation of head matrix here

2009-11-11 16:05  crimic

	* private/eeg_leadfieldb.m: adapted to new arguments format for openmeeg

2009-11-11 13:59  crimic

	* prepare_vol_sens.m: adapted to work with openmeeg

2009-11-10 16:49  vlalit

	* senstype.m: Added one more criterion to fix a crash that occurs when the inputs are cell
	  arrays of <4 labels.

2009-11-10 09:03  roboos

	* senstype.m: fixed bug in the name of internal variable

2009-11-09 19:39  roboos

	* senstype.m, voltype.m: limit the max number of merged meg/eeg/ecog objects to 3, so that
	  multiple channel labels are still supported in senstype

2009-11-09 15:15  roboos

	* senstype.m, voltype.m: recognise combined EEG and MEG inputs

2009-10-27 16:01  roboos

	* beamformer_dics.m, beamformer_lcmv.m, beamformer_pcc.m, compute_leadfield.m, dipole_fit.m,
	  inside_vol.m, minimumnormestimate.m, music.m, prepare_vol_sens.m, private/avgref.m,
	  private/bounding_mesh.m, private/eeg_leadfield1.m, private/eeg_leadfield4.m,
	  private/eeg_leadfieldb.m, private/elproj.m, private/find_innermost_boundary.m,
	  private/find_inside_vol.m, private/find_outermost_boundary.m, private/fitsphere.m,
	  private/fixdipole.m, private/inf_medium_leadfield.m, private/lmoutr.m,
	  private/magnetic_dipole.m, private/meg_leadfield1.m, private/normals.m, private/plgndr.m,
	  private/project_elec.m, private/ptriproj.m, private/solid_angle.m,
	  private/transfer_elec.m, private/triangle4pt.m, residualvariance.m, senslabel.m,
	  senstype.m, sourcedepth.m, transform_headshape.m, transform_sens.m, transform_vol.m,
	  voltype.m: removed the old cvs log comments from each of the fieldtrip source code files
	  subversion (a.k.a. svn) does not make use of the special $Log$ keyword, which means that
	  the log messages do not reflect the latest changes
	  you can use 'svn log <filename.m>' or 'svn -v log | less' to get the same detailled
	  information as used to be in the cvs log

2009-10-26 18:13  crimic

	* voltype.m: adde bem openmeeg option

2009-10-23 07:32  roboos

	* README: updated readme and copyrights

2009-10-23 07:06  roboos

	* senstype.m: small change in detection of type of input: more robust for
	  raw/freq/timelock/comp

2009-10-22 10:14  jansch

	* senstype.m: made more robust for data-structures, not depending on a hdr-field

2009-10-21 10:25  roboos

	* ., COPYING, README, apply_montage.m, beamformer_dics.m, beamformer_lcmv.m,
	  beamformer_pcc.m, compute_leadfield.m, convert_units.m, dipole_fit.m, estimate_units.m,
	  inside_vol.m, minimumnormestimate.m, music.m, prepare_vol_sens.m, private,
	  private/avgref.m, private/bounding_mesh.m, private/eeg_leadfield1.m,
	  private/eeg_leadfield4.m, private/eeg_leadfieldb.m, private/elproj.m,
	  private/find_innermost_boundary.m, private/find_inside_vol.m,
	  private/find_outermost_boundary.m, private/fitsphere.m, private/fixdipole.m,
	  private/geometry.c, private/geometry.h, private/getsubfield.m, private/hastoolbox.m,
	  private/inf_medium_leadfield.m, private/issubfield.m, private/keyval.m,
	  private/leadsphere_all.m, private/legs.m, private/lmoutr.c, private/lmoutr.m,
	  private/lmoutr.mexa64, private/lmoutr.mexglx, private/lmoutr.mexmac,
	  private/lmoutr.mexmaci, private/lmoutr.mexw32, private/magnetic_dipole.m,
	  private/match_str.m, private/meg_forward.m, private/meg_ini.m, private/meg_leadfield1.c,
	  private/meg_leadfield1.m, private/meg_leadfield1.mexa64, private/meg_leadfield1.mexglx,
	  private/meg_leadfield1.mexmac, private/meg_leadfield1.mexmaci,
	  private/meg_leadfield1.mexw32, private/normals.m, private/plgndr.c, private/plgndr.m,
	  private/plgndr.mexa64, private/plgndr.mexglx, private/plgndr.mexmac,
	  private/plgndr.mexmaci, private/plgndr.mexw32, private/progress.m, private/project_elec.m,
	  private/ptriproj.c, private/ptriproj.m, private/ptriproj.mexa64, private/ptriproj.mexglx,
	  private/ptriproj.mexmac, private/ptriproj.mexmaci, private/ptriproj.mexw32,
	  private/rmsubfield.m, private/setsubfield.m, private/solid_angle.c, private/solid_angle.m,
	  private/solid_angle.mexa64, private/solid_angle.mexglx, private/solid_angle.mexmac,
	  private/solid_angle.mexmaci, private/solid_angle.mexw32, private/sphfit.m,
	  private/transfer_elec.m, private/triangle4pt.m, residualvariance.m, senslabel.m,
	  senstype.m, sourcedepth.m, transform_headshape.m, transform_sens.m, transform_vol.m,
	  voltype.m: initial import

Appendix: related documentation

The literature references to the implemented methods are given here.

development/forwinv.txt · Last modified: 2009/03/03 22:00 (external edit)
Back to top
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0