Example c7: MRI Head Model - Signal Fitting and Displaying

The electrical activity of the brain can be measured by placing electrodes on the scalp - a method call electroencephalography (EEG). A generic set of the coordinate positions of the electrodes were provided by the Psychology Department. To calculate a potential field over the skin surface, coordinates of virtual electrodes on the MRI head model are determined. The measured electrode positions have been orthogonally projected onto the outer surface of the model.

The UNEMAP signal eeg.signal is created using the program posdata2sig, to translate the EEG signal data produced by the Psychology Department into a format compatible with CMISS. The ouput for postdat2sig is given as

% posdat2sig
Position file name ? dataview.pos
129 positions
Data file name ? alldiff.dat
300 samples
Sampling frequency ? 1000
Signal file name ? eeg.signal
Created signal file: eeg.signal

where dataview.pos contains the 3-dimensional cartesian co-ordinates of the electrodes and alldiff.dat contains the signal. The input files and all relevant documentation can be obtained from here.

Shown below are the projections of the electrodes onto the torso surface. The red crosses are the measured electrode positions and the blue crosses represent the orthoganol projections on the model surface. The green lines show the error between the two distances. Also shown are the potential fields.

Front View Back View Front View with Field Back View with Field

A movie sequence can been seen in CMGUI by running the comfile view_potential.com. This also calls the comfile animate.com as a looping comfile to generate a sequence of frames for a movie. The electrode projections can be viewed by running the CMGUI comfile view_electrodes.com

The comfile run by this example is as follows:

fem def para;r;head;example                            #define parameters
fem def coor;r;head;example                            #define coordinates 
fem def regi;r;head;example                            #two regions
fem def base;r;head;example
fem def node;r;head;example reg all
fem def elem;r;head;example reg all

# Export surfaces to CMGUI
fem export node;brain_geom geom nodes 1..167      as brain region 2
fem export node;bone_geom  geom nodes 168..334    as bone  region 2
fem export node;skin_geom  geom nodes 335..501    as skin  region 1
fem export elem;brain_geom geom elements 181..360 as brain region 2 
fem export elem;bone_geom  geom elements 361..540 as bone  region 2 
fem export elem;skin_geom  geom elements 721..900 as skin  region 1 

# Align DataCoordinates to
#  suit the MRI head model

fem def data;r;DataView_Coordinates;example
fem change data rotate by 0,180,0 about 0,0,0  #rotate data 180 degrees y-axis
fem change data scale by 10,10,10              #scales the data from cm to mm
fem change data translate by 86,0,22           #translate data

fem def data;w;electrode_positions

# Calculate orthoganal vectors 
#  of electrode projections 
#  onto outer surface of the 
#  MRI skull

fem def data;r;electrode_positions             #define data
fem def xi;c;projections orthog region 1       #calculate xi positions   
fem def xi;w;projections region 1
fem li data errors region 1
fem export data;electrode_positions as electrode_positions offset 1000
fem export data;projections as projections error offset 2000

Additional testing commands:

# start of testing

# Create the surface electrodes
#  and export to CMGUI
fem def data;c from_xi                      region 1
fem def data;w;projected_positions          region 1
fem export data;projected_positions as projected_positions offset 3000
#                                              !outputs the data positions and 
#                                              !error vectors denoted by error

# Update the surface electrodes
# and export to UNEMAP
fem def import;r;import;example

# Command updated by fixcom.sh on Wed Aug 23 17:50:21 NZT 2000
# Old command: fem import signal;$example//eeg signal_output eeg_output extension sig
fem import signal;${example}eeg signal_output eeg_output extension sig

fem def data;r;projected_positions region 1
fem def xi;r;projections region 1
fem update signal infile eeg_output outfile eeg_updated binary
fem def export;r;unemap;example
fem export signal;eeg_updated electrodes signal eeg_updated

# Convert the signals to ASCII
#  for testing
fem conv signal from bin infile eeg_updated outfile eeg_updated

# Fit the signals
fem def fiel;r;head;example region 1           #set up field for fitting process
fem def elem;r;head;example field region 1     #elem fields 
fem def fit;r;head;example signal region 1
fem fit signal binary region 1
fem fit signal region 1

# Export the fitted signals at
#  each node to UNEMAP
fem evaluate electrodes;fitted_node hist fitted from node binary region 1 using fit
fem li sign bin sign fitted_node
fem conv signal from bin infile fitted_node outfile fitted_node
fem def export;r;nodes;example
fem export sig;fitted_node elec signal fitted_node

# Export reconstructed signals 
#  for a comparison
fem def data;r;projected_positions region 1
fem def xi;r;projections region 1
fem evaluate electrodes;fitted_data hist fitted from data binary region 1 using fit
fem li sign bin sign fitted_data
fem conv signal from bin infile fitted_data outfile fitted_data

# Export the nodal signals to
fem def export;r;unemap;example
fem export sig;fitted_data elec signal fitted_data

# Export the nodal potential
#  field to CMGUI
fem export node;potential hist fitted binary node 335..501 as potential region 1 using fit   
fem export elem;potential field elements 721..900 region 1 as potential using fit

Files used by this example are:

Name                         Modified     Size

example_c7.com 01-Jun-2000 1.5k DataView_Coordinates.ipdata 10-Apr-2000 4.6k animate.com 10-May-2000 414 eeg.sig 10-Apr-2000 157k electrode_positions.ipdata 10-Apr-2000 13k head.ipbase 10-Apr-2000 7.8k head.ipcoor 02-Oct-2002 571 head.ipelfd 10-Apr-2000 53k head.ipfiel 10-Apr-2000 69k head.ipfit 13-Apr-2007 1.8k head.ippara 12-Nov-2002 5.9k head.ipregi 10-Apr-2000 93 head.irelem 10-Apr-2000 288k head.irnode 10-Apr-2000 593k import.ipimpo 10-Apr-2000 468 nodes.ipexpo 10-Apr-2000 779 test_output.com 20-Nov-2001 2.3k unemap.ipexpo 10-Apr-2000 711 view_electrodes.com 10-May-2000 1.3k view_potential.com 10-May-2000 1.1k

Download the entire example:

Name                  Modified     Size

examples_c_c7.tar.gz 17-Aug-2014 1.4M

Testing status by version:

StatusTestedReal time (s)
cmSuccessSun Mar 6 00:08:13 201612
cm-debugSuccessSat Mar 5 01:07:13 201659
cmSuccessSun Aug 19 03:46:03 2007166
cm-debugSuccessWed Aug 15 04:36:25 2007814
cm-debug-clear-mallocSuccessSat Aug 18 05:12:45 2007866
cm-debug-clear-malloc7SuccessMon Aug 20 04:46:41 2007816
cm64SuccessSun Aug 19 03:55:36 2007153
cm64-debugSuccessFri Aug 17 05:48:04 2007935
cm64-debug-clear-mallocSuccessThu Apr 1 11:35:45 2004373
cmSuccessWed Mar 4 01:18:57 200918
cm-debugSuccessMon Mar 2 01:47:39 2009226
cm64SuccessWed Mar 4 01:20:20 200926
cm64-debugSuccessTue Mar 3 01:50:58 2009225
cmSuccessSun Mar 6 00:01:23 20165
cm-debugSuccessSat Mar 5 00:05:34 201632

Testing status by file:

Graphical output from this problem is given here.

Html last generated: Sun Mar 6 05:51:18 2016

Input last modified: Sat Aug 16 10:39:22 2014

CMISS Help / Examples / c / c7