You are on page 1of 49

Biomedical Electromagnetic

Field Modeling and Source


Localization Using the Finite
Element Method

Paul Schimpf, PhD


Copyright 2006
Eastern Washington University
Computer Science Department
pschimpf@centurytel.net
estimated completion time:
4.0-5.0 hrs
Table of Contents
 Tutorial Objectives
 Background Information
– Biomedical Applications of Electromagnetic Fields
– Volume Conduction and the Poisson Equation
– The Finite Element Method
 Forward Modeling
– Defining the Domain
– Defining Boundary Conditions
– Specifying Current Sources
– Solving and Visualizing Output
– Exercises 2 and 3
 Inverse Modeling
– Introduction to Inverse Modeling
– A Simple Inverse Algorithm
– Exercises 4 and 5
© 2006-07 P. Schimpf 2
Biomedical Tutorial Objectives
1. Understand the basic steps in developing a
forward model from medical imagery
Define a head model from classified medical images (provided)
Simulate and visualize the electroencephalogram (EEG) for
different source configurations:

2. Understand the principle of superposition


Verify that the field due to two sources is the sum of the fields due
to the individual sources

3. Understand the basic issues of inverse problems


nonlinear dependence on source position requires
characterization of each possible source, resulting in a highly
underdetermined problem
assumptions or a-priori information may be applied to make the
problem tractable

© 2006-07 P. Schimpf 3
Biomedical Applications
 Cardiology
– optimal electrode design to minimize burning from edge
effects
– implanted defibrillation: where should the electrodes be
placed to optimize efficacy?
– diagnosis: are there regions on the heart that are not
generating a neural signal (infarct)?

 Neurology
– what neural regions are involved in performing task X?
– locating the foci of seizure activity
– detecting silent seizures
– brain to computer interfacing

 Impedance Imaging
– visualizing changes in electrical impedance, which
correlates to tissue structure
© 2006-07 P. Schimpf 4
Volume Conduction
 Both artificial and biologic sources introduce
current into the tissue
– in most biomedical applications, inductive and capacitive effects
are negligible, and the conduction is purely resistive
– voltage and current are thus governed by the Poisson equation:

  V    (1)
– in two dimensions, with isotropic conductivity, this expands to:

  2V  2V 
  2  2     ( 2)
 x y 
– V, σ, and  are all functions of position (x,y)
– V is voltage (V), σ is conductivity (Siemens/m), and ρ represents
current source density (A/m2 in two dimensions)
© 2006-07 P. Schimpf 5
The Finite Element Method

 Given the conductivity and the sources, our goal


is an approximate solution for the voltage
 We create a piecewise approximation to V using a
collection of local basis functions, Ni
n
V x, y   U x, y    ai N i x, y  (3)
i 1

– the Ni are called local basis functions because each


approximates the solution over a subregion called an element
– the simplest element shape in two dimensions is a triangle
– polynomial functions of (x,y) are usually used for the Ni
– for this tutorial, we will use linear functions:

Ni x, y   a1  a2 x  a3 y ( 4)
© 2006-07 P. Schimpf 6
The Finite Element Method
 The end result of using linear basis functions is
a faceted approximation to the true solution
– the approx. improves as the elements are made smaller
– we should use small elements where the voltage is rapidly
changing
– an adaptive mesh solver shrinks the elements in such
regions automatically

– this example illustrates a possible piecewise linear solution


over a two-dimensional domain using triangular elements,
each having 3 degrees-of-freedom (a1, a2, a3)
© 2006-07 P. Schimpf 7
Moving to 3D
 In 3 Dimensions, the problem definition requires
only an extra term for the added dimension (z):

  V    (1)

  2V  2V  2V 
  2  2  2     ( 2)
 x y z 
– V, σ, and  are now functions of (x,y,z), and  represents volume
current source density (A/m3)
– note that equation (1) remains unchanged, which is one of the
advantages of the Divergence () and Gradient () operators

 We also need 3D elements, and corresponding


basis functions (polynomials in x, y, z)

© 2006-07 P. Schimpf 8
Moving to 3D
 Note that our linear basis in 2D had 3 degrees
of freedom (DOFs)
– DOFs are the parameters that fit the linear basis functions
to the voltage (a1, a2, a3)
– the number of DOFs for a linear basis is the same as the
number of vertices (or nodes) of the simplest element shape
(a triangle in 2D)

 The simplest element shape in 3D is a


tetrahedra
– which would then have 4 DOFs:
n
V x, y, z   U x, y, z    ai N i x, y, z  (3)
i 1

Ni x, y, z   a1  a2 x  a3 y  a4 z ( 4)
© 2006-07 P. Schimpf 9
Image Based Elements
 When modeling a biological domain, it is
convenient to define elements as collections of
medical image pixels
– pixels are classified according to tissue type, and each
tissue type is assumed to have a particular conductivity
– in 3D, we use a set of images, and pixels become voxels
– the pixels are usually square, but the space between images
is often not the same as the pixel size, thus our elements
will be brick-shaped (rectangular parallelipiped)
– such elements have 8 nodes, and thus 8 DOFs:

Ni x, y, z   a1  a2 x  a3 y  a4 z  a5 xy  a6 yz  a7 xz  a8 xyz ( 4)
– this is more DOFs than a linear basis, but not enough to
provide a full quadratic basis (Can you determine what the
missing quadratic terms are? Can you see the cubic term?)
– it is thus called a super-linear element
© 2006-07 P. Schimpf 10
Image Based Elements
 pixels/voxels in the medical images are classified
according to tissue type, and each tissue type is
assumed to have a particular conductivity
 element boundaries are defined as collections of voxels
 Typical FE programs draw the mesh as a wire-frame of
the elements. In this case it is convenient to just color
the groups of pixels that comprise an element, and
ensure that neighboring elements use different colors.

Classified Domain An element "mesh"


© 2006-07 P. Schimpf 11
The Galerkin Method
 Transforms the problem into a linear system of
equations in terms of the ai by:
– substituting the approximation U (3) into the Poisson
equation (2)
– formulating the residual, which is the difference between the
right and left hand sides of the Poisson equation
– and requiring that the average weighted residual be zero
– averaging here means integrating the weighted residual over
the entire domain:
Residual R(x,y,z;a) =     U  (5)

 Rx, y, z; a N x, y, z d  0



j
j  1, 2, , n (6)

Ka  f (7 )
– the details of this transformation are beyond our scope
© 2006-07 P. Schimpf 12
Forward Modeling
– Define a head model from classified medical images (provided)
– Simulate the electroencephalogram (EEG) for 3 different source
configurations:
1) a single dipolar source in the prefrontal cortex
2) a single dipolar source in the cingulate cortex
3) both of the above sources simultaneously
– Verify the 3rd solution is the sum of the first two
– We'll cover the simulation of the first source configuration here -
the other two are similar
– Suggested directory AnyDi
structure:
HeEx
adMo
eEx
rci
e
d
*.cls
exe sin rci
ima ege
xe so .ma
rci lu
tutoeria
xe l.rs
rci
(you nta
eegpts.sl
fro may also find it l
lf.ma convenient to put a copy of
cingul
t
roi.ma
bo plotsamples.m
th.tx t in all 3
plo co
tsadirectories)
mpa mp
© 2006-07 P. Schimpf 13
Define the Domain
 Use a text editor to view the file image.map
– this is a list of the correspondence between image files and z coordinates
– note that it specifies model images in a subdirectory called HeadModel
 Run GalerWin and select Edit /
Domain Definition
– press the Import button, browse to
your tutorial directory, and select the
file image.map
– notice that the image dimensions (128
x 128) are deduced from the file size
 You must define the dimensions
of the pixels in whatever units you
prefer to work with
– let's work with meters
– the pixel dimensions in these images
are 2 mm x 2 mm and the spacing
between images is 3.2 mm
– enter the appropriate values (in
meters) and press the OK button
© 2006-07 P. Schimpf 14
Define the Domain
 You should now see a grayscale
rendering of the first slice
– each pixel is a byte code representing a
particular tissue type, and the solver
defaults to simply interpreting that byte
value as a gray scale – we'll change that
shortly
– these images are pretty small, so select
View / Zoom 400%
– select View / Current Z Slice, enter 25, and
press OK
– move the mouse around in the window
and notice the updates of the voxel
coordinates and tissue class number in
the status bar
 select File / Save
– and save this project as Exercise1to3 \ Exercise1.gal
– you can now load that file to continue your work at a later time
– the .gal project files save the definitions of the problem, but not solutions
© 2006-07 P. Schimpf 15
Editing Material Properties
 Select Edit / Material Properties
– this is where we assign a conductivity
and a color to each tissue class
– try selecting some material numbers –
you'll see that the assigned material color
defaults to grayscale
– the conductivity is in the units you
choose, but should be consistent with the
other units – we'll use Siemens / m
– use a text editor to view the file tutorial.rst
– for historical reasons, the import and
export of conductivities uses the inverse,
which is resistivity, with units (in this
case) of -m
– press Import and select the file tutorial.rst
– you should now see some conductivities and tissue descriptions in the
window, but the colors are still grayscale
– to edit a tissue description, double-click the tissue in the scroll window
– we'll assign some colors to these tissues next
© 2006-07 P. Schimpf 16
Editing Material Properties
 Select tissue #90, Scalp, and move the color scrollbars to
give it the color black. Color the EEG electrodes (#91)
red, the Reference electrode (#94) green, and cortex
voxels (#93) magenta.
 feel free to color other
tissues as well, but this
is purely for visual
asthetics and does not
effect the model solution
(see next slide for more
tissue colors used here)
 press the Close button
 you should now see
a colored image of
the domain
 select File / Save

© 2006-07 P. Schimpf 17
Suggested Tissue Colors
tissue # name Color Red Green Blue
40 blood red 255 0 0
45 hard bone gray 128 128 128
50 soft bone light gray 196 196 196
55 gray matter lavender 204 128 204
60 white matter olive 196 228 128
65 cerebellum brown 196 128 64
70 CSF cyan 0 204 204
75 eye lt lavender 228 196 196
80 fat yellow 255 228 112
85 muscle blue 32 32 180
93 cortex magenta 255 0 255
95 soft tissue lt green 128 204 128
209 air white 255 255 255

© 2006-07 P. Schimpf 18
Material Properties
 Some things to note:
– "eeg electrodes" have been given their own tissue number
(91) so that they can be viewed on the image
• this also makes it convenient to sample the field solution at
those points, but it is not necessary to define a tissue class
at sample points
• note that their conductivity is the same as "scalp" (90)
– one particular electrode has class 94 "reference electrode"
• we'll define a 0 voltage boundary condition here later
• again, this is not necessary, but it makes the reference
electrode easy to see in the image set
– a subset of the gray matter voxels (#55) have been
classified as "cortex" (#93), which you've colored magenta
• note that the conductivities are the same
• these "cortex" voxels mark possible source sites when we
discuss inverse problems later on
© 2006-07 P. Schimpf 19
Defining Boundary Conditions
 Boundary Conditions (BCs) come in two types:
– Fixed or Dirichlet: represent fixed voltages at any site in the domain
• used to simulate voltage sources or reference points
• in this case, we need only specify a 0 voltage at the location of the
reference electrode
• note that these can be internal, even though they are called "boundary
conditions" – fixing the voltage at internal points in the domain
essentially removes that region from the model, creating an internal
boundary
– Natural, or Neumann: specify values for the normal component of
current density at boundary points (A/m2 in 3D)
• they are satisfied only approximately in the eventual solution
• Neumann BCs are rare in this application (we'll have none), except that
any boundary point that has NO boundary condition explicitly specified
automatically gets a 0 normal current boundary condition. This says
that current does not escape from the modeled domain.
• with some pre-calculation, non-zero Natural BCs take the same form
as Fixed BCs – with this S/W that is the only way to enter them
© 2006-07 P. Schimpf 20
Defining Boundary Conditions
 On slice 25, right-click the green pixel and select Set
Boundary Conditions
– Fixed BCs are actually applied at nodes of the mesh, and nodes
occur at the vertices of elements
– Because you've selected a voxel, the pop-up allows you to enter
BCs at any of the vertices of that voxel. The terminology asks that
you think of your screen view as looking down onto the top of the
modeled object (this may be disorienting, but calling the first image
"top" instead of "left" makes sense with axial medical images,
which are more common for
modeling than the saggital
images used here)
– One BC would be sufficient to
establish a voltage reference,
but since the entire voxel
represents our knowledge of
the location of the reference
point, check all the vertices

© 2006-07 P. Schimpf 21
Defining Boundary Conditions
 Press OK and select Edit / Boundary Conditions
– this screen lists all fixed boundary conditions
– it also allows you to specify fixed boundary conditions in two
other ways:
• Over a range of coordinates, in which case the boundary
condition is applied to all nodes falling within the box defined by
those two coordinates
• Over a material class, in
which case the boundary
conditions is applied to all
nodes falling on a voxel of
the specified class
– note that we could have
specified these 8 reference
BCs on this screen using
the coordinate range:
(116, 60, 25) to (117, 61, 26)
– or using Material class 94
© 2006-07 P. Schimpf 22
Specifying Current Sources

 The right-hand side of the


Poisson equation
represents current sources
– neuronal source activity is
generally modeled as a dipolar
source: a current source close
to a current sink
– we will simulate this by placing
identical, but opposite, current
sources on adjacent nodes

 right-click on a cortex
voxel (class 93) in the
frontal cortex and select
Set Sources

© 2006-07 P. Schimpf 23
Specifying Current Sources
 This pop-up is similar to the pop-up for boundary
conditions
– you can specify a total current for each node
– specify 625 uA at each of the "top" nodes, and -625 uA at each of
the "bottom" nodes
– this simulates a dipolar source centered in the voxel, oriented in
the z direction (ear to ear), with a moment of 8 uA-m
– this is 2.5 mA total for each
side, times a 3.2 mm separation
(the voxel size in the z
dimension)

 Press OK and select Edit /


Source
– the resulting dialog box lists
all defined sources

 Press OK and select File / Save


© 2006-07 P. Schimpf 24
Solving
 Select Edit / Adaptation Controls
– this screen allows you to specify parameters that effect the way
the mesh is (automatically) adapted
– we'll take a look at a coarsely
adapted mesh and at a finely
adapted mesh
– set the initial mesh settings to
specify element sizes of 32 down
to 4 voxels
– turn "an exact match ... to external
border" off
– next to "Solve Equations using",
press Params and select Both
solution methods (discussed next)
– set the "Repeat, at most"
loop counter to 5
– set the error estimate condition for
termination to 5%
© 2006-07 P. Schimpf 25
Solving
 The program will first build an initial mesh
– It starts by populating the domain with the larger element size
– It will then automatically refine elements in an attempt to make
each as homogeneous (containing a single conductivity region)
as possible, but will not refine elements beyond the minimum
specified size
 It then applies the specified BCs, generates a
linear system of equations from the mesh, and
solves using the specified iterative solvers
 It then iterates on refining the mesh in areas that
have high flux, re-solving each new mesh
– in this case, the "flux" is current density, which is proportional
to voltage gradient
– this terminates when the average estimated error in flux falls
below the specified threshold
– many FE solvers do not have an adaptive meshing ability – it is
generally up to the user to refine the mesh
© 2006-07 P. Schimpf 26
Iterative Solvers
 Recall that the finite element method produces a
linear system of equations from the mesh:
Ka  f (7 )
 The matrix K generated by FE meshes are large
and sparse
– the vector a that we are solving for contains the DOFs for the
basis functions associated with the elements of the mesh
– there as thus as many rows (and columns) as there are nodes
in the mesh
– there will be a non-zero entry in matrix K only where the two
nodes associated with that row and column are connected
through the edge of an element
– for example, if the mesh is uniform (each element is 1 voxel),
each node will connect to at most 26 other nodes, and there
will thus be at most 27 non-zero entries on any given row of K
(including the diagonal entry)
© 2006-07 P. Schimpf 27
Iterative Solvers
 You may be familiar with deterministic solution
methods such as Gaussian elimination
 When the matrices are sparse, it is more efficient
to use an iterative approach
– example of a simple iterative approach called relaxation:
3a1  1a2  25
1a1  3a2  19
– start with an arbitrary initial guess a1=1 and a2=1
– refine this guess iteratively with using the following equations
(derived from the system of equations above)
a1*  25  a2  / 3
a2*  19  a1  / 3
– where * indicates the next estimate
– repeat until the estimates don't change much or the difference
between the right and left-hand sides is below some threshold
© 2006-07 P. Schimpf 28
Iterative Solvers
a1*  25  a2  / 3
 Evolution of a1 and a2 a2*  19  a1  / 3
a1 a2
1 1
8 6
6.3 3.7
7.1 4.2
6.9 4.0
7.0 4.0
7.0 4.0

 Optional Exercise
1a1  3a2  19 a1*  19  3a2
– try this method for this
rearrangement of the 3a1  1a2  25 a2*  25  3a1
same problem:
© 2006-07 P. Schimpf 29
Iterative Solvers
 This control allows the user to
choose from two iterative
solver algorithms
– Many FE programs wouldn't allow
such choices. They were included
here because this code was developed for research work.
– Select "Both" and leave the other parameters at defaults
 SOR = Successive Over-relaxation
– this algorithm is similar to the relaxation approach in the
preceding example, with some refinements
– updates are used as soon as available (i.e. a2* in the
preceding example would use a1* instead of a1)
– the RHS calculations are multiplied by a “relaxation factor”
to speed convergence
 JCG = Jacobi Conjugate Gradient
– this is an advanced iterative algorithm that is beyond the
scope of this tutorial
© 2006-07 P. Schimpf 30
Solving
 Select Action / Solve
– a pop-up window shows status of the solution in progress,
including the number of elements & nodes in the mesh
 Press Dismiss and select View / Field Solution
– look at the solution on z slices 15-35
– notice how the energy of the sources
"piles up" at the skull boundary

© 2006-07 P. Schimpf 31
Looking at the Mesh

 Select View / Element Mesh


– You'll get a warning that viewing the element mesh will
overwrite the solution. This is
because the voltage solution
is overwritten with color data
as the mesh is colored, which
is done to conserve memory.
– press OK
– take a look at the mesh on
the same range of slices
– note how the elements are
smaller near the current
source
– most of the other elements
are 4x4x4 pixels from the
initial attempt to represent
internal conductivity boundaries

© 2006-07 P. Schimpf 32
Forcing a Uniform Mesh
 Select Edit / Adaptation Controls
– In order to test the principle of superposition, we'll now solve
two more problems: a different dipole source followed by both
dipole sources
– we'll then compare the solution
for both to the sum of the
individual solutions
– the comparison will come out
best if we ensure the mesh for
all three problems is the same
– the easiest way to do this is to
force a uniform mesh of single
voxel elements
– modify the adaptation controls
as shown here:
– Elements from size 1 downto 1
– Exact match of border on
– Repeat at most 0 times
© 2006-07 P. Schimpf 33
Solve Again
 Select Action / Solve
 Press Dismiss and select View / Field Solution
– look at the solution on z slices 15-35
– notice the sharper resolution of energy piling up against
both the skull and other local
tissues (looking at slice 34 here)

© 2006-07 P. Schimpf 34
Extracting EEG Samples
 Select Edit / Solution Points
– press Import and select the file
eegpts.sln
– we could also enter the class for
EEG electrodes (91) in the box
titled "Solutions for a specific
material class"
– eegpts.sln defines the same
samples in the order we'll need
for inverse work later on

 Press OK and select


Action / Show Solution
at Listed Points
– press Save to File and save
in a file named frontal.txt
– use a text editor to view
that file
© 2006-07 P. Schimpf 35
Plotting EEG Samples
 One common way to get a quick idea of the voltage
distribution on the scalp is to view a contour plot of
the EEG samples as seen from above
– we'll do that by ignoring the y dimension of the sample locations

 Run matlab and change


(cd) to your tutorial
directory
– execute the command:
plotsamples('frontal.txt') ;
– note that the left / right
orientation of the source is
visible in the scalp EEG
– take a look at the file
plotsamples.m in the matlab
editor to see how it works

© 2006-07 P. Schimpf 36
Exercises 2 and 3

 The next 2 exercises are similar to the simulation


just completed
 Exercise 2: simulate an 8uA-m dipolar source
located in the posterior cingulate cortex
– oriented in the anterior / posterior (x) direction
– see next slide, and use the same slice as before (z=25)
– don't forget to remove the existing sources first
– don't forget that the voxel dimension in x is different than z
– plot the EEG in Matlab

 Exercise 3: simulate the prefrontal and posterior


cingulate sources at the same time
– plot the EEG in Matlab
– use Matlab to verify that the resulting EEG is the sum of the
two EEGs taken separately
© 2006-07 P. Schimpf 37
Exercise 2

 Posterior Cingulate Cortex


 Resultant EEG:

© 2006-07 P. Schimpf 38
Exercise 3

?
= +

both frontal (z) cingulate (x)


 Put your matlab code that compares the
simulation of both to the sum of the two
simulated separately into a file called compare.m
 Some of the values returned by the call to
plotsamples() can help you verify that this is the
case (to within some level of error)
© 2006-07 P. Schimpf 39
Intro to Inverse Modeling
 Given incomplete knowledge of the field (EEG)
– determine the location, orientation & strength of the sources
 First, model the EEG due to each possible unit source
(location and orientation) as a column in a matrix
– Principle of Superposition: the EEG obtained from multiple sources
is the same as the sum of the EEGs obtained from each source
separately
source strengths
"Lead-field" matrix EEG

 l1,1 l1, 2  l1,n   s1   v1 


l l l    
 2,1 2, 2 2 , n   s2   v2 

        
    
lm,1 lm, 2 lm3n   s3n  vm 
m  3n 3n 1 m 1
© 2006-07 P. Schimpf 40
Some things to note
 m = number of EEG measurements
 n = number of possible source sites in the brain
– this can be a restricted number of sites using a-priori information
– here it is restricted to sites near the cortical surface
 each site has a dipolar source, with an orientation
– an arbitrary dipole orientation is represented by 3 dipoles, each
oriented in one of the 3 ordinal directions of the model (summing
the effects of the dipoles is just like summing vectors)
– thus the columns of the matrix come in triplets for each brain site
site 1 site 1 site 1 site 2 site n
x dipole y dipole z dipole x dipole z dipole

 l1,1 l1, 2 l1,3 l1, 4  l1,3n   s1   v1 


l  l2,3n   s2   v2 
 2,1 l2, 2 l2 , 3 l2 , 4
  
            
    
lm,1 lm, 2 lm , 3 lm , 4  lm,3n   s3n  vm 
© 2006-07 P. Schimpf 41
Inverse Modeling Challenges

 There are a large number of possible sources


– at a ~2.5 mm resolution roughly tens of thousands of possible
sources, and each of 3 ordinal orientations must be simulated
 Problem 1: yikes, that's a lot of forward solutions
– fortunately, there is a way around this using the Principle of
Reciprocity
– the theory is beyond our scope, but it allows us to build the lead-
field matrix one row at a time, instead of one column at a time,
using one forward simulation for each EEG measurement site,
instead of 3 times each source site
 Problem 2: there are many more columns
(unknown sources) than rows (EEG measurements)
– so this problem is extremely underdetermined
– which means there are, in principle, an infinite number of source
arrangements that can produce a given EEG measurement

© 2006-07 P. Schimpf 42
A Simple Inverse Algorithm
 One solution to Problem 2 is to assume that there
are fewer sources than measurements
– i.e., many of the entries in the s vector will be zero
– this leads to a useful solution in many applications
 The simplest extreme – assume 1 source
– iterate through each triplet of columns in the lead-field, find the
best fit of those 3 columns to the EEG measurement, which gives
the best fitting orientation of that particular source site, and
calculate the residual
– the column triplet giving the smallest residual represents the best
fitting single source
– at each iteration, we now have an overdetermined problem to
solve, because there are 3 columns (the 3 ordinal orientations of a
particular source) and m rows (the number of EEG measurements)
– we shouldn't expect to find an exact solution (residual=0), unless
there truly is only a single source, on our grid spacing, the model
is perfect, and there is no noise present
© 2006-07 P. Schimpf 43
Overdetermined Pseudoinverse
 The least squares strategy is to minimize the
norm of the residual:
  Li si  v  Li si  v 
2 T
Ri 2
 siT LTi Li si  2 siT LTi v  vT v

 2 LTi Li si  2 LTi v  0
2
Ri
s 2

 LTi Li si  LTi v
 si  Li Li  Li v
T 1 T

 si is then the best fitting set of amplitudes for


subset i of the set of possible sources
– best in terms of minimizing the residual norm
– in this case each subset i is the three ordinal source
orientations at a particular location
– Ri can be calculated from si and the smallest Ri represents
our best fit for a single source
© 2006-07 P. Schimpf 44
Single Source Search
Algorithm [i, o, rr] = SingleSourceSearch(L, v)
Inputs: matrix L: the lead-field for the model
vector v: the measurement vector
Outputs: integer i: index of the 1st of 3 consecutive columns
that represent the best fitting source
vector o: 3x1 source vector representing the best linear
combination of those columns
scalar rr: relative residual of the fit
remove the average value from v % IMPORTANT
smallestR2 = infinity
for each set of 3 consecutive columns in L
miniL = L(those 3 columns)
s = inv(miniL'*miniL)*miniL'*v
R2 = (miniL*s-v)'*(miniL*s-v)
if R2 is less than smallestR2 then
smallestR2 = R2
i = those 3 columns
o = s
endif
endfor
rr = sqrt(smallestR2) / sqrt(v'*v)
© 2006-07 P. Schimpf 45
Exercise 4
 Implement the single source search algorithm
in matlab
– store it in a file called singlesourcesearch.m
 write a matlab script (solution.m) that inverts
the simulated EEG of the frontal cortex source
– use your code above along with the lead-field in lf.mat
– the matrix in roi.mat gives the (x,y,z) voxel coordinates of
each column triplet in lf.mat
– IOW, roi(:,1) contains the coordinates of lf(:,1:3) and roi(:,2)
contains the coordinates of lf(:,4:6), etc.
– use the roi matrix to determine the location of the best
fitting source
– your script should display the location, orientation, and
relative residual of the best fitting source
– how well does the inverted location and orientation
compare to the actual location and orientation (you can use
GalerWin to look at the inverted coordinate)?
© 2006-07 P. Schimpf 46
Exercise 5
 Now add an inversion of the simulated EEG of
both sources
 In this case your assumption is wrong
– you're finding the best fitting single source
– but there are actually two
 You should get a location somewhere between
the two
 The residual of the fit should be higher than the
residual obtained in Exercise 4
– because there is no single source that fits well when there are
actually two sources
 For discussion: can you think of a modification
to the algorithm that would give you a better
inverse?
© 2006-07 P. Schimpf 47
Project Educational Objectives
The educational goal of this tutorial is to provide
undergraduate engineering students with understanding of
bioelectric fields and the use of finite element (FE) methods,
along with an ability to apply FE to bioelectric problems. The
educational goal is accomplished through four educational
objectives based upon Bloom’s Taxonomy and ABET
Criteria 3 as follows:
1. Engineering Topics (Comprehension: 3a, 3k). Understand
the fundamental basis of engineering topics through the use
of finite element models.
2. FE Theory (Comprehension; 3a). Understand the
fundamental basis of FE Theory.
3. FE Modeling Practice (Application; 3a, 3e, 3k). Be able to
implement a suitable finite element model using FE
software.
4. FE Solution Interpretation and Verification (Comprehension
and Evaluation; 3a, 3e) Be able to interpret and evaluate
finite element solution quality.
© 2006-07 P. Schimpf 48
Acknowledgement

 This tutorial was developed under


National Science Foundation Division of
Undergraduate Education Grant Number
0536197

© 2006-07 P. Schimpf 49

You might also like