biomedical electromagnetic field modeling and source localization using the finite element method...

49
Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University Computer Science Department [email protected] estimated completion time: 4.0-5.0 hrs

Post on 19-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

Biomedical Electromagnetic Field Modeling and Source

Localization Using the Finite Element Method

Paul Schimpf, PhD

Copyright 2006

Eastern Washington UniversityComputer Science [email protected]

estimated completion time: 4.0-5.0 hrs

Page 2: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 2

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

Page 3: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 3

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 problemsnonlinear 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

Page 4: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 4

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

Page 5: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 5

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:

– in two dimensions, with isotropic conductivity, this expands to:

– 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)

V

2

2

2

2

y

V

x

V

)1(

)2(

Page 6: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 6

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

– 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:

n

iii yxNayxUyxV

1

,,,

yaxaayxN i 321,

)3(

)4(

Page 7: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 7

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)

Page 8: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 8

Moving to 3D

In 3 Dimensions, the problem definition requires only an extra term for the added dimension (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)

V

2

2

2

2

2

2

z

V

y

V

x

V

)1(

)2(

Page 9: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 9

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:

zayaxaazyxN i 4321,,

n

iii zyxNazyxUzyxV

1

,,,,,, )3(

)4(

Page 10: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 10

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:

– 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

xyzaxzayzaxyazayaxaazyxN i 87654321,, )4(

Page 11: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 11Classified Domain An element "mesh"

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.

Page 12: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 12

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) =

– the details of this transformation are beyond our scope

U

0,,;,,

dzyxNazyxR jj n1 2, , ,

Ka f

)5(

)6(

)7(

Page 13: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 13

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 structure:

(you may also find it convenient to put a copy of plotsamples.m in all 3 directories)

Page 14: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 14

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

Page 15: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 15

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

Page 16: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 16

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

Page 17: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 17

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 moretissue colors used here)

press the Close button you should now see

a colored image ofthe domain

select File / Save

Page 18: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 18

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

Page 19: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 19

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

Page 20: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 20

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

Page 21: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 21

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 toestablish a voltage reference,but since the entire voxel represents our knowledge of the location of the referencepoint, check all the vertices

Page 22: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 22

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

Page 23: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 23

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

Page 24: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 24

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 eachside, times a 3.2 mm separation(the voxel size in the z dimension)

Press OK and select Edit / Source

– the resulting dialog box listsall defined sources

Press OK and select File / Save

Page 25: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 25

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%

Page 26: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 26

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

Page 27: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 27

Iterative Solvers

Recall that the finite element method produces a linear system of equations from the mesh:

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)

Ka f )7(

Page 28: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 28

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:

– 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)

– 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

1931

2513

21

21

aa

aa

3/19

3/25

1*2

2*1

aa

aa

Page 29: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 29

Iterative Solvers

Evolution of a1 and a2

Optional Exercise– try this method for this rearrangement of the same problem:

a1 a21 1

8 6

6.3 3.7

7.1 4.2

6.9 4.0

7.0 4.0

7.0 4.0

3/19

3/25

1*2

2*1

aa

aa

2513

1931

21

21

aa

aa

1*2

2*1

325

319

aa

aa

Page 30: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 30

Iterative Solvers

This control allows the user tochoose from two iterativesolver 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

Page 31: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 31

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

Page 32: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 32

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 dataas the mesh is colored, which is done to conserve memory.

– press OK

– take a look at the mesh onthe same range of slices

– note how the elements aresmaller near the currentsource

– most of the other elementsare 4x4x4 pixels from theinitial attempt to representinternal conductivity boundaries

Page 33: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 33

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

Page 34: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 34

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 localtissues (looking at slice 34 here)

Page 35: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 35

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

Page 36: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 36

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

Page 37: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 37

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

Page 38: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 38

Exercise 2

Posterior Cingulate Cortex

Resultant EEG:

Page 39: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 39

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)

=?

+

Page 40: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 40

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

mnnmmm

n

n

v

v

v

s

s

s

lll

lll

lll

2

1

3

2

1

32,1,

,22,21,2

,12,11,1

nm 3 13 n 1m

"Lead-field" matrix

source strengths

EEG

Page 41: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 41

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

mnnmmmmm

n

n

v

v

v

s

s

s

lllll

lllll

lllll

2

1

3

2

1

3,4,3,2,1,

3,24,23,22,21,2

3,14,13,12,11,1

site 1x dipole

site 1y dipole

site 1z dipole

site 2x dipole

site nz dipole

Page 42: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 42

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

Page 43: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 43

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

Page 44: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 44

Overdetermined Pseudoinverse

The least squares strategy is to minimize the norm of the residual:

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

vLLLs

vLsLL

vLsLLRs

vvvLssLLsvsLvsLR

Tii

Tii

Tiii

Ti

Tiii

Tii

TTi

Tiii

Ti

Ti

iiT

iii

1

2

2

2

2

022

2

Page 45: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 45

Single Source Search

Algorithm [i, o, rr] = SingleSourceSearch(L, v) Inputs: matrix L: the lead-field for the model vector v: the measurement vectorOutputs: 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 % IMPORTANTsmallestR2 = infinityfor 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 endifendforrr = sqrt(smallestR2) / sqrt(v'*v)

Page 46: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 46

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)?

Page 47: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 47

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?

Page 48: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 48

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.

Page 49: Biomedical Electromagnetic Field Modeling and Source Localization Using the Finite Element Method Paul Schimpf, PhD Copyright 2006 Eastern Washington University

© 2006-07 P. Schimpf 49

Acknowledgement

This tutorial was developed under National Science Foundation Division of Undergraduate Education Grant Number 0536197