Home > bioelectromagnetism > eeg_interp_sph_spline.m

eeg_interp_sph_spline

PURPOSE ^

eeg_interp_sph_spline - Spherical Spline Interpolation of Potential

SYNOPSIS ^

function [FV,C] = eeg_interp_sph_spline(Zi,Ei)

DESCRIPTION ^

 eeg_interp_sph_spline - Spherical Spline Interpolation of Potential

 Useage: [FV,C] = eeg_interp_sph_spline(Zi,Ei)

 where:    Zi is Nelec x 1, an EEG/ERP measurement at time t
           Ei is Nelec x 3, [X Y Z] electrode positions.
           The origin of Ei is assumed (0,0,0).

 FV => interpolated spherical surface (see sphere_tri)

 FV.faces    => triangulation of FV.vertices 
 FV.vertices => cartesian coordinates (Nx3)
 FV.Cdata    => spherical spline potential at FV.vertices
 
 C => interpolation coefficients of Ei (includes co = C(1))
 
 Notes:    This function calculates the spherical spline of 
           Perrin et al (1989).  Electroenceph. & Clin. 
             Neurophysiology, 72: 184-187. Corrigenda (1990),
             Electroenceph. & Clin. Neurophysiology, 76: 565.
             (see comments in the .m file for details).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [FV,C] = eeg_interp_sph_spline(Zi,Ei)
0002 
0003 % eeg_interp_sph_spline - Spherical Spline Interpolation of Potential
0004 %
0005 % Useage: [FV,C] = eeg_interp_sph_spline(Zi,Ei)
0006 %
0007 % where:    Zi is Nelec x 1, an EEG/ERP measurement at time t
0008 %           Ei is Nelec x 3, [X Y Z] electrode positions.
0009 %           The origin of Ei is assumed (0,0,0).
0010 %
0011 % FV => interpolated spherical surface (see sphere_tri)
0012 %
0013 % FV.faces    => triangulation of FV.vertices
0014 % FV.vertices => cartesian coordinates (Nx3)
0015 % FV.Cdata    => spherical spline potential at FV.vertices
0016 %
0017 % C => interpolation coefficients of Ei (includes co = C(1))
0018 %
0019 % Notes:    This function calculates the spherical spline of
0020 %           Perrin et al (1989).  Electroenceph. & Clin.
0021 %             Neurophysiology, 72: 184-187. Corrigenda (1990),
0022 %             Electroenceph. & Clin. Neurophysiology, 76: 565.
0023 %             (see comments in the .m file for details).
0024 
0025 % $Revision: 1.2 $ $Date: 2005/07/13 06:03:50 $
0026 
0027 % Licence:  GNU GPL, no implied or express warranties
0028 % History:  08/2001 Darren.Weber_at_radiology.ucsf.edu, with
0029 %                   mathematical advice from
0030 %                   Dr. Murk Bottema (Flinders University of SA)
0031 %           10/2003 Darren.Weber_at_radiology.ucsf.edu, with
0032 %                   mathematical advice and LegendreP function from
0033 %                   Dr. Tom.Ferree_at_radiology.ucsf.edu
0034 %                   revised, tested & initial verification complete
0035 %
0036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0037 
0038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0039 % Check for correct size & orientation of Ei & Zi
0040 [e1,e2] = size(Ei);
0041 [v1,v2] = size(Zi);
0042 if e1 < e2, Ei = Ei'; [e1,e2] = size(Ei); end
0043 if v1 < v2, Zi = Zi'; [v1,v2] = size(Zi); end
0044 if ~and(isequal(e1,v1),and(isequal(e2,3),isequal(v2,1)))
0045   error('...Ei must be Nx3 & Zi must be Nx1');
0046 end
0047 nElectrodes = e1; % The number of electrodes
0048 clear e1 e2 v1 v2;
0049 
0050 
0051 % -------------------------------------------------------------------------
0052 % estimate spherical radius of the electrodes and
0053 % obtain spherical projections of Ei
0054 [r,x,y,z] = elec_sphere_project(Ei(:,1),Ei(:,2),Ei(:,3));
0055 %Ei = [ x y z ]; clear x y z;
0056 
0057 % create spherical interpolation surface
0058 FV = sphere_tri('ico',4,r);
0059 
0060 % -------------------------------------------------------------------------
0061 % Calculate the cosines, if Ei is Nx3, COS is NxN matrix
0062 % We use (Ei,Ei) here because it gives the cosines between
0063 % each electrode and every other electrode.  This is required
0064 % here because we solve a linear system of equations below
0065 % that will find the interpolated value at a given electrode
0066 % location, which must be equal to the measured
0067 % potential at that location.
0068 EiCOS = elec_cosines(Ei,Ei);
0069 
0070 % create zeros on the diagonal elements
0071 % [not sure why this works, but it does.]
0072 for i = 1:length(EiCOS), EiCOS(i,i) = 0; end
0073 
0074 % -------------------------------------------------------------------------
0075 % Calculate g(x), nElectrodes x nElectrodes
0076 Gx = eeg_interp_sph_spline_g(EiCOS);
0077 
0078 % -------------------------------------------------------------------------
0079 % calculate the spherical interpolation coefficients
0080 C = eeg_interp_sph_spline_c(Zi,Gx); clear Gx
0081 
0082 % -------------------------------------------------------------------------
0083 % cosines between electrodes and interpolation points
0084 FvCOS = elec_cosines(Ei,FV.vertices);
0085 
0086 % Calculate g(x), nElectrodes x NinterpolationPoints
0087 Gx = eeg_interp_sph_spline_g(FvCOS);
0088 
0089 eegversion = '$Revision: 1.2 $';
0090 fprintf('EEG_INTERP_SPH_SPLINE [v %s]\n',eegversion(11:15)); tic
0091 
0092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0093 % Now that Ci is solved, we can obtain interpolated potentials at Ej (Eq. 1)
0094 % U(Ej) = c(0) + ( for i=1:n, sum = (sum + (c(i) * g(cos(Ei,Ej)))) )
0095 % U(Ej) = c(0) + sum( Ci * g(x) )
0096 
0097 % Solve Eq 1. (where FV.Cdata = U)
0098 Co = C(1);
0099 Ci = C(2:end);
0100 FV.Cdata = Co + ( Ci' * Gx );
0101 
0102 t=toc; fprintf('...done (%6.2f sec)\n',t);
0103 
0104 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003