Home > bioelectromagnetism > elec_distance.m

elec_distance

PURPOSE ^

elec_distance - Calculates spherical interelectrode distances (arc length).

SYNOPSIS ^

function [labels, distances] = elec_distance(elec_labels,X,Y,Z,xo,yo,zo)

DESCRIPTION ^

 elec_distance - Calculates spherical interelectrode distances (arc length).

 Usage: [labels, distances] = elec_distance(elec_labels,X,Y,Z,xo,yo,zo)

 Notes:    Arc length method assumes a centroid at (xo,yo,zo) = (0,0,0)
           and input values are in rectangular Cartesian coordinates.
           
           Sphere radius is estimated by the average radius from
           (xo,yo,zo) to any 2 pairs of electrodes.  It will vary
           from one pair to another, but this method works well for
           small theta (eg, nearest neighbours).

           Returns 2 matrices, one for paired electrode labels and 
           another for spherical arc length estimates.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [labels, distances] = elec_distance(elec_labels,X,Y,Z,xo,yo,zo)
0002 
0003 % elec_distance - Calculates spherical interelectrode distances (arc length).
0004 %
0005 % Usage: [labels, distances] = elec_distance(elec_labels,X,Y,Z,xo,yo,zo)
0006 %
0007 % Notes:    Arc length method assumes a centroid at (xo,yo,zo) = (0,0,0)
0008 %           and input values are in rectangular Cartesian coordinates.
0009 %
0010 %           Sphere radius is estimated by the average radius from
0011 %           (xo,yo,zo) to any 2 pairs of electrodes.  It will vary
0012 %           from one pair to another, but this method works well for
0013 %           small theta (eg, nearest neighbours).
0014 %
0015 %           Returns 2 matrices, one for paired electrode labels and
0016 %           another for spherical arc length estimates.
0017 %
0018 
0019 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0020 
0021 % Author:   Darren.Weber_at_radiology.ucsf.edu
0022 % Created:  18/05/00 - linear distance
0023 % Modified: 24/06/01 - spherical arc length (should be OK for small theta
0024 %                      but for large theta, elliptical arc length may be
0025 %                      preferable).
0026 %
0027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0028 
0029     % initialise centroid, unless input parameters defined
0030     if ~exist('xo','var')  xo = 0;   end
0031     if ~exist('yo','var')  yo = 0;   end
0032     if ~exist('zo','var')  zo = 0;   end
0033 
0034     fprintf('%s\n', 'Calculating inter-electrode spherical arc length.');
0035 
0036     labels = cell(1);
0037     distances = [];
0038  
0039     % convert numerical electrode labels to cell strings
0040     if isnumeric(elec_labels) > 0
0041         if size(elec_labels,1) > size(elec_labels,2)
0042             elec_labels = cellstr(strcat(num2str(elec_labels)));
0043         else
0044             elec_labels = cellstr(strcat(num2str(elec_labels')));
0045         end
0046     end
0047     
0048     A = [ (X-xo) (Y-yo) (Z-zo) ];  B = A;              % define electrode vectors A,B, given centroid (xo,yo,zo)
0049     rows = 50;                                         % progress indicator
0050     for a =   1:length(X)
0051         fprintf('.'); if( a == rows ) fprintf('\n'); rows = rows + 50; end  % progress indicator
0052         
0053         Aa = A(a,:);
0054         A_len = sqrt( sum( Aa.^2 ) );                        % length of electrode vector A
0055         
0056         for b = 1:length(X)
0057             
0058             Bb = B(b,:);
0059             B_len = sqrt ( sum(Bb.^2) );                     % length of electrode vector B
0060             
0061             if( Aa == Bb )
0062                 arc_len = 0;                                    % no distance from electrode to itself
0063             else
0064                 r = (A_len + B_len)/2;                          % estimate sphere radius from A_len and B_len
0065                 theta = acos( dot(Aa,Bb) / (A_len * B_len) );   % Angle between A & B, in radians
0066                 arc_len = r * theta;                            % arc length = radius * theta
0067             end
0068             
0069             distances(a, b) = arc_len;
0070             labels(a, b) = strcat(elec_labels(a), ', ', elec_labels(b));
0071         end
0072     end
0073     fprintf('\n');

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