A08: DIPFIT

From SCCN
Jump to: navigation, search

Contents

DIPFIT plug-in: Equivalent dipole source localization of independent components

A major obstacle to using EEG data to visualize macroscopic brain dynamics is the under-determined nature of the inverse problem: Given an EEG scalp distribution of activity observed at given scalp electrodes, any number of brain source distributions can be found that would produce it. This is because there are any number of possible brain source area pairs or etc. that, jointly, add (or subtract) nothing to the scalp data. Therefore, solving this 'EEG inverse' problem uniquely requires making additional assumptions about the nature of the source distributions. A computationally tractable approach is to find some number of equivalent current dipoles (like vanishingly small batteries) whose summed projections to the scalp most nearly resemble the observed scalp distribution.

Unfortunately, the problem of finding the locations of more than one simultaneously active equivalent dipoles does not have a unique solution, and "best fit" solutions will differ depending on the observed scalp distribution(s) (or scalp 'map(s)') that are given to the source inversion algorithm. For this reason, approaches to solving the EEG inverse problem have tended to focus on fitting scalp maps in which a single dipolar scalp map is expected to be active, for instance very early peaks in ERP (or magnetic ERF) response averages indexing the first arrival of sensory information in cortex. Others attempt to fit multiple dipoles to longer portions of averaged ERP (or ERF) waveforms based on "prior belief" (i.e., guesses) as to where the sources should be located. This approach has often been criticized for not being based wholly on the observed data and thus subject to bias or ignorance.

Using ICA to un-mix the unaveraged EEG is a radically different approach. ICA identifies temporally independent signal sources in multi-channel EEG data as well as their pattern of projection to the scalp surface. These 'component maps' have been shown to be significantly more dipolar (or "dipole-like") than either the raw EEG or any average ERP at nearly any time point -- even though neither the locations of the electrodes nor the biophysics of volume propagation are taken into account by ICA (Delorme et al., ms. in preparation). Many independent EEG components have scalp maps that nearly perfectly match the projection of a single equivalent brain dipole. This finding is consistent with their presumed generation via partial synchrony of local field potential (LFP) processes within a connected domain or patch of cortex.

Fortunately, the problem of finding the location of a single equivalent dipole generating a given dipolar scalp map is well posed. Note, however, that the location of the equivalent dipole for synchronous LFP activity in a 'cortical patch' will in general not be in the center of the active cortical patch. In particular, if the patch is radially oriented (e.g. on a gyrus, thus aimed toward the supervening scalp surface), the equivalent dipole location tends to be deeper than the cortical source patch.


Component localization in EEGLAB: EEGLAB now includes two plug-ins for localizing equivalent dipole locations of independent component scalp maps: (1) the DIPFIT plug-in calling Matlab routines of Robert Oostenveld (F.C. Donders Centre, Netherlands); and (2) a BESAFIT plug-in linking to older versions of the BESA program (Megis Software GMBH, Germany) running outside of Matlab (see A7). Use of the DIPFIT plug-in is strongly recommended.

DIPFIT is an EEGLAB plug-in based on functions written and contributed by Robert Oostenveld, and ported to EEGLAB by Robert in collaboration with Arnaud Delorme. DIPFIT2, released near the beginning of 2006 with EEGLAB v4.6, can perform source localization by fitting an equivalent current dipole model using a non-linear optimization technique (scherg1990) using a 4-shell spherical model (kavanagh1978) or by using a standardized boundary element head model (oostendorp1989). DIPFIT2 makes use of the FieldTrip toolbox, which is installed by default with EEGLAB.

Advances in DIPFIT2 (first distributed with EEGLAB v4.6-) include:

  • Spherical Head Model: The spherical head model has been better co-registered to the MNI brain. This results in a shift in dipole visualization of about 1 cm downward compare to the same dipoles plotted in DIPFIT1. Spherical dipoles coordinates are also now converted to MNI and to Talairach coordinates, making comparisons possible with other imaging results.
  • Boundary Element Model: Localization within a three-shell boundary element model (BEM) of the MNI standard brain is now possible.
  • Channel Co-registration: A new function has been adding for performing manual or automated alignment of measured dataset channel locations to stored spherical or BEM head model template channel montages.

Dipole fitting with DIPFIT2

The scalp maps of many ICA components are compatible with their generation in separate domains of partial synchrony in cortex. Because local connections in cortex have a much higher density than longer range connections, it is reasonable to assume that synchronous coupling of neuronal activity, as isolated by ICA, usually occurs within a single brain area. Some ICA component scalp maps do highly resemble the projection of a single equivalent dipole (or in some cases a bilaterally symmetric pair of dipoles). Residual scalp map variance of the best-fitting single- or two-dipole component models is often surprisingly low (see below), given the relative inaccuracy of the (spherical) head model used to compute it. Such ICA components may thus represent projection of activity from one (or two symmetric) patch(es) of cortex.

To fit dipole models to ICA components in an EEGLAB dataset, you first need to perform ICA decomposition and then select the components to be fitted. To use DIPFIT to fit independent component maps for an EEGLAB dataset, you must first build or load the dataset, import a channel location file (see the EEGLAB tutorial on Importing a Channel Location File) and compute an ICA decomposition of your data (see Performing Independent Component Analysis of EEG data).

To follow the dipole fitting example used in this tutorial, download a 69-channel sample dataset for DIPFIT and BESA dipole localization here: eeglab_dipole.set (>1 MB). This sample dataset contains a channel location file and pre-computed ICA weights. Note: to save space, this dataset has been reduced to only a single trial, after performing ICA on about 800 similar trials; You should not try to apply ICA to this dataset, but should instead use the pre-processed ICA weight matrix to test dipole localization. Load the dataset into EEGLAB using menu item File > Load Existing Dataset.

Next, you must select which component to fit. Independent component (IC) 5 of the sample dataset decomposition is a typical lateral posterior alpha rhythm process. To plot component scalp map, use menu item Plot > Component maps > In 2-D, enter 5 for the component number and option 'electrodes', 'pointlabels' to obtain the plot below. Note that the channel location file for this subject has been scanned using the Polhemus system, so the electrode locations are not exactly symmetrical.

A21component maps.gif


There are three steps required to create equivalent dipole models for independent components:

  • Setting model and preferences: This involves choosing the model (spherical or boundary element) and excluding some channels from the fitting procedure (e.g., eye channels).
  • Grid scanning: This involves scanning possible positions in a coarse 3-D grid to determine an acceptable starting point for fitting equivalent dipoles to each component.
  • Non-linear interactive fitting: This involves running an optimization algorithm to find the best position for each equivalent dipole.

Below we describe these three steps in detail. Note that the grid scanning and non-linear optimization may also be performed automatically for a group of selected components. This is described later in this chapter.

Setting up DIPFIT model and preferences

Before running DIPFIT, we must select some input parameters. Select the EEGLAB menu item Tools > Locate dipoles using DIPFIT > Head model and settings to modify DIPFIT settings. This will pop up the window below:

Pop dipfit settings.gif


The top edit box, Model (click to select), specifies the type of head model -- spherical or boundary element (BEM). By default, the spherical head model uses four spherical surfaces (skin, skull, CSF, cortex) to model the brain. The BEM model is composed of three 3-D surfaces (skin, skull, cortex) extracted from the MNI (Montreal Neurological Institute) caconical template brain also used in SPM (see here for details, the brain used is referred to as "collin27"). In many case, the BEM model is more realistic than the four concentric spheres model, and will return more accurate results. However the BEM model is a numerical model and sometimes leads to incorrect solutions due to numerical instabilities, whereas the spherical model is an analytical model. Furthermore, the spherical model returns results that are comparable with the BESA tool (below). For this example, select Boundary element model.

Clicking on the model name updates the fields below. The entry Model file contains the head model parameters (surface information, conductances, etc...). These are Matlab files and may be edited. See the FieldTrip documentation for more information on the head model files. The entry Output coordinates contains the format of the output dipole coordinates. Note that all dipoles are always plotted in MNI/Talairach coordinates. These parameters should only be updated for custom brain models.

The entry MRI contains the name of the MRI image to plot dipoles within. You may enter a custom or individual subject MR image file, assuming this file has first been normalized to the MNI brain. See a tutorial page on How to normalize an MR brain image to the MNI brain template using SPM2. Note that the SPM2 software directory must be in your Matlab path to use the resulting file in DIPFIT.

The entry Template channel .loc file contains the name of the template channel location file associated with the head model. This information is critical, as your dataset channel location file may be different from the template. If so, a co-registration transform is required to align your channel locations using the template locations associated with the model. Before we move on to co-registration, note the last edit box Omit channels for dipole fit. By pressing List, a list of channels appears that allows users to exclude eye channels (or other, possibly non-head channels) from the dipole fitting procedure.

Channel co-registration is the most important part and critical part of the DIPFIT setting procedure. If your channel locations are not aligned with the surface of the selected head model, the coordinates of the dipoles returned by DIPFIT will be meaningless.

Solution 1 (required for fitting the sample data): If all your electrode locations are within the International 10-20 System, the easiest way to align your channels to the head model is to simply use the standard channel coordinates associated with the head model. Here, no co-registration is required. To do this, press the No coreg checkbox and close the DIPFIT settings window (by pressing OK). Then go to the channel editing window (select menu item Edit > Channel location). The resulting channel editor window is shown below:

Dipfit pop chanedit.jpg


Press the Look up locs to look up your channel locations (by matching the channel labels) in the template channel location file.
Pop chanedit lookup.gif
If you had wanted to use the template channel locations for the spherical model, you would have selected the first option in the pop-up menu Use BESA file for four-shell DIPFIT spherical model. If you want to use the template channel locations for the BEM model, scroll down the pop-up menu and click on the button labeled Use MNI coordinate file for the BEM DIPFIT model, then press OK. At this point you may perform coarse grid scanning and non-linear fine fitting as explained in the next section.

Solution 2: If you are using channel locations and/or labels not in the International 10-20 System -- for example, scanned electrode positions, or some commercial high-density electrode cap file -- you will need to align or co-register your electrode locations with the selected head model. DIPPLOT does not actually allow you to align your electrode locations to the head model itself, but rather allows you to align your electrode locations to matching template electrode locations associated with the head model.

To try this, click on Manual coreg. in the DIPFIT settings window. The following instruction window will first appear:

Coregister warning.gif


If you have selected the spherical head model and pressed OK, the following co-registration window will appear. Here, the electrode locations are plotted on the sphere that represents the head. Note the schematic nose on the lower right; this will rotate with the head sphere. Each small red or green sphere indicates an electrode location, with fiducial locations (conventionally, the nasion and ear canal centers) drawn as bigger and darker spheres (more visible in the second image below).

Coregister.gif


If you have selected the BEM model, the following window will appear:

Coregister2.gif


Use the Warp button to align and scale your electrode locations file so that it becomes best aligned with the template electrode file associated with the head model.

If you have no channels with labels that are common to the labels in the template montage, a channel correspondence window will pop up:

Pop chancoresp.gif


The channel labels from your dataset electrode structure are shown in the right column, while the left column shows channel labels from the template channel file associated with the head model. Arrows in both columns indicate electrodes with the same labels in the other column. If your channels labels do not correspond to the International 10-20 System labels used in the template montage, press the Pair channels button and choose the nearest channel to each of your dataset channels in the template montage. See here and Oostenveld 2001 for more information about 10-20 channel locations.

When you press OK, the function will perform the optimal linear 3-D warp (translation, rotation, and scaling) to align your channel montage to the template montage associated with the head model. The warping procedure uses the Fieldtrip toolbox which is installed by default with EEGLAB. The result will be shown in the channel montage window (see below). You may press the Labels on button to toggle display of the channel labels for your channel structure (green) or the template channel file associated with the head model (red). You may also restrict the display to subsets of channels using the Electrodes buttons.

Fine tuning: To finely tune the alignment manually, repeatedly edit the values in the edit boxes. Here:

  • Yaw means rotation in the horizontal plane around the z axis.
  • Pitch and Roll are rotations around the x and y axes.
The resulting co-registration window should look something like this:
Coregister3.gif

Note about fiducials: Your channel structure may contain standard fiducial locations (nasion and pre-auricular points). If you import a channel file with fiducial locations into the channel editor, in EEGLAB v4.6- give them the standard 'fiducial' channel type FID and they will be stored in the channel information structure, EEG.chaninfo. This will also be done automatically if your fiducials have the standard names, Nz (nasion), LPA (left pre-auricular point), and RPA (right pre-auricular point ). Note that fiducial locations are stored outside the standard channel location structure, EEG.chanlocs, for compatibility with other EEGLAB plotting functions.

Thereafter, fiducial locations will appear in the channel co-registration window (above) and may be used (in place of location-matched scalp channels) to align your electrode montage to the template locations associated with the head model. Use the Align fiducials button to do this. Press OK to update the DIPFIT settings window. This will display the resulting talairach transformation matrix, a vector comprised of nine fields named [shiftx shifty shiftz pitch roll yaw scalex scaley scalez]. Then press OK in the DIPFIT settings window and proceed to localization.

Initial fitting - Scanning on a coarse-grained grid

Before you perform interactive dipole fitting, first allow DIPFIT to scan for the best-fitting dipole locations on a coarse 3-D grid covering the whole brain. The solutions of this grid search are not very accurate yet, but they are acceptable as starting locations for the non-linear optimalization. Starting from these best grid locations will speed up finding the final best-fitting solution. (The next section, A4.4, explains the fine tuning using the non-linear optimization). The tutorial instructions below are valid for both the spherical head model and the boundary element model. To scan dipoles on a coarse grid, select menu item Tools > Locate dipoles using DIPFIT > Coarse fit (grid scan). If you use the sample dataset, the window below will pop up:

Pop dipfit batch.gif

The first edit box Component(s) allows you to select a subset of components to fit. Note: selecting only a few components does not increase the speed of the computation, since the forward model still has to be computed at each location on the grid. The Grid in X-direction,Grid in Y-direction, and Grid in Z-direction edit boxes allow you to specify the size and spacing of the coarse grid. By default, DIPFIT uses 10 steps equally spaced between -radius and +radius of the sphere that best matches the electrode positions. Since equivalent dipoles are not likely to be in the lower hemisphere of the model head, by default DIPFIT only scans through positive Z values. The last edit box, Rejection threshold RV(%), allows you to set a threshold on the maximum residual variance that is accepted. Using this threshold, components that do not resemble a dipolar field distribution will not be assigned a dipole location.

Press OK and a bar will pop up to show the progress of the coarse grid scanning. Note: during dipole localization, the electrode positions are projected to the skin surface of the spherical or BEM head model, though the electrode positions as saved in the dataset itself are not altered. DIPFIT starts the grid scan by first excluding all 3-D grid locations that are outside the head. It then computes the forward model (dipole-to-electrode projections) at each remaining grid location and compares it with all component topographies. The progress of this process is shown in the text window. When the process is completed, select menu item Tools > Locate dipoles using DIPFIT > Plot component dipoles to call the window below:

Pop dipplot2.gif
Simply press OK, to produce the figure below:

Dipplot gridsearch.gif

Here, all the dipoles plotted had a residual variance (vis a vis their component maps) below 40% (as we specified in the coarse grid search interactive window). Note that some components end up having the same x, y and z coordinates because of the coarseness of the grid. You may view individual components by pressing the Plot one button. The component index and its residual variance are then indicated in the top-left corner (see the 'dipplot()' visualization tutorial below for further details).

Interactive fine-grained fitting

To scan dipoles interactively, call menu item Tools > Locate dipoles using DIPFIT > Fine fit (iterative). The following windows pop up. Enter a component index (here, 3) in the Component to fit edit box.

Pop dipfit nonlinear.gif

Prior to fitting the component, press the Plot map button to show the component scalp map. The following window pops up.

A24comp3.gif

This component, showing a clear left-right symmetric activity, cannot be accurately modeled using a single dipole. To fit this component using two dipoles constrained to be located symmetrically across the (corpus callosum) midline, set both dipole 1 and 2 to 'active' and 'fit' (by checking the relevant checkboxes in the pop window). Then press the Fit selected dipole position(s) button. If fitting fails, enter different starting positions (e.g., [-10 -68 17] for first dipole and [10 -68 17] for the second dipole and refit). When fitting is done, note the low residual variance for the two-dipole model on the top right corner of the interactive interface (0.53 %). Then, press the Plot dipole(s) button. The following plot pops up (see the'dipplot()' visualization tutorial below).

Diplot image2.gif

Note that the polarity of components is not fixed (but their orientation is): the product of the component scalp map value and the component activitation value (i.e., the back-projected contribution of the component to the scalp data) is in the original data units (e.g., microvolts), but the polarities of the scalp map and of the activation values are undetermined. For example, you may multiply both the scalp map and the component activity by -1 while preserving the component back-projection to the scalp (since the two negative factors cancel out). As a result, you may choose to flip the visualized dipole orientations (use the pop-up window for fitting, then press the Flip in|out button and then the Plot dipole(s) button to re-plot the dipoles with indicated orientations reversed.

Important note: when you are done, press the OK button in the interactive interface for dipole fitting. Do not press Cancel or close the window -- if you do, all the dipole locations that you have computed using this interface will be lost! Also, this DIPFIT menu is the only one that does not generate EEGLAB history. The first menu item, Tools > Locate dipoles using DIPFIT > Autofit component, uses the same method for dipole fitting but also generates an EEGLAB history command that can be re-used in batch scripts.

Automated dipole fitting

Automated dipole fitting performs the grid search and the non-linear fitting on several component without human intervention. You still need to select the model in the DIPFIT settings interactive window though. To find a best-fitting equivalent dipole for the component above, select the EEGLAB menu item Tools > Locate dipoles using DIPFIT > Autofit (coarse fit, fine fit, plot) to automatically fit selected ICA components. Set the Component indices to 5, enter 100 in the rejection threshold edit box so the iterative solution is computed regardless of the residual variance for the coarse fit, and check the Plot resulting dipoles checkbox to plot component dipoles at the end of fitting. Then, press OK.

Pop multifit.gif

The function starts by scanning a 3-D grid to determine acceptable starting positions for each component. Then it uses the non-linear optimization algorithm to find the exact dipole position for each component. At the end of the procedure, the following window pops up.

Dipplot multifit2.gif

The residual variance RV: 2.75% is shown below the component number Comp: 5 on the right top corner indicates that the component being plotted is component 5 and that the residual variance is 2.75%. The dipplot.m function above allows you to rotate the head model in 3-D with the mouse, plot MRI slices closest to the equivalent dipole, etc... (See the 'dipplot()' visualization tutorial below for more details.)

Visualizing dipole models

Use menu item Tools > Locate dipoles using DIPFIT > Plot component dipoles and select component number 3 and 5 to produce the plot shown below (assuming you performed the fit for both components 3 and 5 as described above). Select all options except the Summary mode and enter 'view', [51 18] in the Additional dipplot() options text box to set the initial 3-D view; the function will print the component indices.

Pop dipplot.gif

A plot pops-up. After 3D rotation it may look like the following plot.

A25 dipole image.gif

Press the Plot one button. You may scroll through the components by pressing the Next/Prev buttons. Note that the closest MRI slices to the dipole being currently plotted are shown. Note also that if you do not select the option Plot closest MRI slices in the graphic interface, and then press the Tight view button in the dipplot window, you will be able to see the closest MRI slices at the location of the plotted dipole as shown below. Try moving the 3-D perspective of the tight view plot with the mouse, and/or selecting the three cardinal viewing angles (sagittal, coronal, top) using the lower left control buttons.

Dipole tight.gif

Note that it is not yet possible to toggle the dipole "stems" or "projection lines" on and off from within the graphic interface. You need to use the EEGLAB menu again, unselecting the relevant checkboxes. Also, it is not yet possible to use the subject's own anatomical MRI as background (it will be possible in the future upon completion of a EEG/MRI co-registration function as described below).

Finally, again call menu item Tools > Locate dipoles using DIPFIT > Plot component dipoles. Select Summary mode and press OK.

Dipole summary.gif

For comparison, using the spherical model, the location of the dipoles would have been as shown in the following picture. Notice the similarity of the talairach coordinates for the two models. Notice also that the BEM model does not overestimate dipole depth compare to the spherical model (which is usually the case when the BEM model mesh is too coarse). The MRI used to plot the spherical result is the average MNI brain (over about 150 subjects) whereas the MRI used to plot the BEM is the average MNI brain of a single subject (which was used to generate the model leadfield matrix).

Dipole summary2.gif

The entry Background image contains the name of the MRI in which to plot dipoles. You may enter a custom MRI file assuming this file has been normalized to the MNI brain (see How to normalize an MR brain image to the MNI brain template using SPM2. Note that the SPM2 package directory in your network must be in your Matlab path to be able to use the resulting file in EEGLAB. This is true both for the spherical head model (co-registered to the MNI brain) and the BEM model (based on the MNI brain).

Note: Co-registration of the MNI average MR image with landmark electrode positions for the spherical model. To plot dipole locations in the average MR image (as in the dipplot.m plots above), we co-registered the MNI average brain MRI with landmark electrode positions. For the average MRI image, we used a publicly available average brain image (average of 152 T1-weighted stereotaxic volumes made available by the ICBM project) from the MNI database (Montreal Neurological Institute (MNI), Quebec). Co-registration of the MNI brain and the standard EEG landmarks was accomplished automatically using fiducials and the Cz (vertex) electrode position, then slightly adjusted manually. The co-registration differs slightly from that used in DIPFIT1; dipoles are localized about 10 mm deeper than in DIPFIT1. Other coordinates (x,y) are nearly identical. We believe the co-registration in DIPFIT2 to be more accurate than in DIPFIT1.

You may also see the co-registered model head sphere plotted over the MNI brain in the dipplot.m window by pressing the Mesh on button in the BEM model below (here in 'tight view').

Dipole mesh.gif

Or, for the spherical model below (in summary mode). Note that the sphere model is stretched in the visualization to the ellipsoid that best matches the shape of the headsurface of the average MRI.

Dipole mesh3.gif


Plotting dipole locations on scalp maps

Select menu item Plot > Component maps > In 2-D, enter 1:20 in the component index edit box. Note: The sample dataset structure contains pre-computed component dipoles. If you are processing another dataset, first select menu item Tools > Locate dipoles using DIPFIT > Autofit components to fit ICA components from 1 to 20 automatically as described in section A1.1. above. Check the Plot dipole checkbox (see below) and press OK. Note: You may also enter additional dipole fitting options in the last edit box; press the Help button for details.

Pop topoplot gui.gif

The following plot will pop up.

A26topoplot dipole.gif

Using DIPFIT to fit independent MEG components

Dipfit (v2.1) now supports source localization for MEG data acquired using CTF (Vancouver, CA) systems. Note that a custom head model needs to be used for MEG source localization since it is not possible to do accurate source localization on a template head model from MEG data. The main reason for this limitation is that, first, MEG sensor positions do not follow any positioning standard. Each system may have its own arrangement. Furthermore, unlike in EEG the sensors are not placed on an elastic cap that automatically fits to the head of the subject. The MEG sensor coils are located within a fixed helmet in which the majority of subjects' heads fit loosely. The position of a given sensor relative to a cortical structure could be quite different from subject to subject, and even across different recordings from the same subject. For this reason, the sensor's location is always reported relative to the center and the orientation of the subject's head during the recording, which is never exactly the same across recordings. Consequently, a head model needs to be created for each recording using the CTF MRIViewer and localSphere programs (see the CTF documentation). Then, in EEGLAB, call menu item Tools > Locate dipoles using DIPFIT > Head model and settings, and select the tab CTF in the upper pop-window. Set up the DIPFIT model and preferences as follows:

  • Select CTF as model.
  • The model file is the file default.hdm created by CTF localSphere, located in the xxx.ds folder.
  • The MRI head image should be the xxx.mri file used by MRIViewer to extract the cortical surface.
  • The channel file should be the xxx.res4 file within the xxx.ds folder. This file also contains gradiometer-specific information, including sensor orientation, that is not in the EEG structure.


Dipole settings meg.gif


As for EEG data, you first need to scan a relavely coarse grid, to find an appropriate starting position for each dipole, by calling menu item Tools > Locate dipoles using DIPFIT > Coarse fit (grid scan). Note that CTF head models are in cm. Consequently, the grid used for gridsearch needs to be specified in cm (this is done automatically by pop_dipfit_gridsearch). Then as in EEG dipole fitting, use menu item Tools > Locate dipoles using DIPFIT > Fine fit (iterative) to optimize dipole positions nonlinearly.


Dipole grid meg.gif


Finally, you may plot dipoles on the subject MRI using menu item Tools > Locate dipoles using DIPFIT > Plot component dipoles as shown below. The corresponding scalp map is also shown on the right. Because of co-registration issues, it is not possible to plot the dipole positions on the scalp map as in EEG). It is strongly advisable to normalize dipole lengths.


Dipole plot meg.gif


You can also run dipfit2.1 for MEG data without a subject MR image if you have extracted the subject head surface from another source, like a head model acquired using a Polhemus 3-D location system. However, it would then not be possible to visualise the dipole within EEGLAB. Any comparison between or drawing of dipoles for different subjects requires a thourough understanding of the MEG coordinate system, since that is being used to express the dipole position. The default is in individual subjects' head coordinates, and given that head sizes differ between subject, the position of dipoles cannot be directly compared over subjects. It is therefore advisable to coregister and spatially normalize your subjects' MRIs to a common template (such as the MNI template) and to apply the same coregistration and normalization to the dipole positions before comparing them. These operations need to be executed outside EEGLAB. A test set is available here. Simply load the test file and follow the instruction above. Thanks to Nicolas Robitaille for his efforts to make this new feature work, in documenting it, and providing test data.

Using DIPFIT to fit EEG or ERP scalp maps

Though the implementation of the DIPFIT plug-in has not been expressly designed to fit dipoles to raw ERP or EEG scalp maps, EEGLAB provides a command line function allowing DIPFIT to do so. Fitting can only be performed at selected time points, not throughout a time window. First, you must specify the DIPFIT settings on the selected dataset (see section A4.2. Setting up DIPFIT model and preferences). Then, to fit a time point at 100 ms in an average ERP waveform (for example) from the main tutorial data set (eeglab_data_epochs_ica.set), use the following Matlab commands.

% Find the 100-ms latency data frame 
latency = 0.100; 
pt100 = round((latency-EEG.xmin)*EEG.srate);
 
% Find the best-fitting dipole for the ERP scalp map at this timepoint 
erp = mean(EEG.data(:,:,:), 3); 
EEG = pop_dipfit_settings(EEG); <font color="black">''% Follow GUI instructions to perform co-registration 
[ dipole model TMPEEG] = dipfit_erpeeg(erp(:,pt100), EEG.chanlocs, 'settings', EEG.dipfit, 'threshold', 100);
 
% Show dipole information (spherical or MNI coordinate based on the model selected) dipole
 
% plot the dipole in 3-D 
pop_dipplot(TMPEEG, 1, 'normlen', 'on'); 
 
% Plot the dipole plus the scalp map 
figure; pop_topoplot(TMPEEG,0,1, [ 'ERP 100ms, fit with a single dipole (RV ' num2str(dipole.rv*100,2) '%)'], 0, 1);

Click here to download the script above.

DIPFIT structure and functions

Like other EEGLAB functions, DIPFIT functions are standalone and may also be called from the command line. Note that whenever you call the DIPFIT menu from EEGLAB, a text command is stored in the EEGLAB history as for any other EEGLAB command. Type h on the Matlab command line to view the command history.

DIPFIT creates a EEG.dipfit sub-structure within the main EEG dataset structure. This structure has several fields:

EEG.dipfit.chansel Array of selected channel indices to fit (for instance ECG or EYE channels might be excluded).
EEG.dipfit.current Index of the component currently being fitted.
EEG.dipfit.hdmfile Model file name. Contains informatin about the geometry and the conductivity of the head. This is a standard Matlab file and may be edited as such; for the default spherical model the conductivities and radii are the same as in BESA.
EEG.dipfit.mrifile Contains the MRI file used for plotting dipole locations.
EEG.dipfit.chanfile Contains the template channel location file associated with the current head model. This is used for electrode co-registration.
EEG.dipfit.coordformat Contains the coordinate format in the model structure. This is "spherical" for the spherical model or "MNI" for the BEM model.
EEG.dipfit.coord_transform Contains the talairach transformation matrix to align the user dataset channel location structure (EEG.chanlocs) with the selected head model. This is a length-9 vector [shiftx shifty shiftz pitch roll yaw scalex scaley scalez]. Type >> help traditional in Matlab for more information.
EEG.dipfit.model A structure array containing dipole information.
EEG.dipfit.model.posxyz Contains the 3-D position of the dipole(s). If a two-dipole model is used for a given component, each row of this array contains the location of one dipole.
EEG.dipfit.model.momxyz Contains 3-D moment of the dipole(s). If a two-dipole model is used for a given component, each row of this array contains the moment of one dipole.
EEG.dipfit.model.rv Gives the relative residual variance between the dipole potential distribution and th ecomponent potential distribution, ranging from 0 to 1.
EEG.dipfit.model.active Remembers which dipole was active when the component model was last fitted.
EEG.dipfit.model.select Remembers which dipole was selected when the component model was last fitted.
The main DIPFIT functions are:

pop_dipfit_settings.m

Specify DIPFIT parameters, i.e. head model details.

pop_dipfit_gridsearch.m

Perform initial coarse DIPFIT grid scan to find an acceptable starting positions for further fine fitting.

pop_dipfit_nonlinear.m

Perform fine model fitting via an interactive interface using non-linear optimization. Note: This function cannot be called from the command line. For automated processing, use the function below.

pop_multifit.m

Command the DIPFIT modeling process from a single function. This function allows the user to set parameters, initialize locations on a coarse grid, then perform non-linear optimization as in the separate functions above. This function can be used to automate batch fitting of components from one or more subjects.
Auxiliary DIPFIT functions used by the functions above:

dipfitdefs.m

defines a set of default values used in DIPFIT.

dipfit_gridsearch.m

same as pop_dipfit_batch.m but does not use a pop-up window and assumes that the input data is an EEG dataset structure.

dipfit_nonlinear.m

same as pop_dipfit_manual.m but does not use a pop-up window and assumes that the input data is an EEG dataset structure.

Note: There is no auxiliary "dipfit_settings" function, since selecting DIPFIT settings mostly involves copying default values to EEG.dipfit fields.

DIPFIT validation study using the spherical head model

We (AD) checked the results of fitting equivalent dipoles with DIPFIT (spherical model) against results of BESA(3.0) for independent components of data recorded in a working memory task in our laboratory. There were 72 channels, of which 69 were used for dipole fitting. In particular, we excluded tow EOG channels and the reference channel. We performed ICA on data from three subjects and fit all 69 resulting components with single dipoles using BESA (see the BESAFIT plug-in Appendix) and DIPFIT. We then compared only those dipoles whose residual variance was less than 15% (see plot below).

Comparedipfitbesa.gif


Distances between equivalent dipole locations returned by DIPFIT1 and BESA(3.0) were less than 3 mm (left panel) Note: The outliers were infrequent failures to converge by either algorithm. Dipole angle differences were below 2 degrees (middle panel). Residual variances (mismatch between the component scalp map and the model pole projection) were near equal (right panel). A few dipoles were localized with residual variance below 15% by DIPFIT but not by BESA (4 of 213 components); a few others with residual variance below 15% by BESA but not by DIPFIT (8 of 213 components). Optimization nonlinearities may account for these small differences between the two algorithms, as the solution models used in the two programs are theoretically identical.

The main advantage of using DIPFIT over BESA for localization of equivalent dipoles for independent component scalp maps is that it is integrated into Matlab and EEGLAB, and can be used in batch processing scripts (see Matlab code and structures & functions above). BESA has additional capabilities not relevant to DIPFIT. Succeeding versions of BESA did not allow a batch processing option.

Literature references

M. Scherg, "Fundamentals of dipole source potential analysis". In: "Auditory evoked magnetic fields and electric potentials" (eds. F. Grandori, M. Hoke and G.L. Romani). Advances in Audiology, Vol. 6. Karger, Basel, pp 40-69, 1990.

R. Kavanagh, T. M. Darcey, D. Lehmann, and D. H. Fender. "Evaluation of methods for three-dimensional localization of electric sources in the human brain." IEEE Trans Biomed Eng, 25:421-429, 1978.

T.F. Oostendorp and A. van Oosterom, "Source parameter estimation in inhomogeneous volume conductors of arbitrary shape", IEEE Trans Biomed Eng. 36:382-91, 1989.

R. Oostenveld and P. Praamstra. The five percent electrode system for high-resolution EEG and ERP measurements. Clin Neurophysiol, 112:713-719, 2001.