Home > bioelectromagnetism > elec_open.m

elec_open

PURPOSE ^

elec_open - opens electrode data for the eeg_toolbox

SYNOPSIS ^

function [p] = elec_open(p)

DESCRIPTION ^

 elec_open - opens electrode data for the eeg_toolbox
 
 Usage: [p] = elec_open( p )
 
 p is the eeg_toolbox struct (see eeg_toolbox_defaults).
 If p is omitted, the function uses the defaults.
 
 This function requires the fields:
 
 p.elec.path  - the directory location of the file to load
 p.elec.file  - the name of the file to load
 p.elec.type  - the file format type
 p.elec.n     - how many electrodes to read
 p.elec.plot  - boolean, 1 = plot, 2 = no plot
 
 The return values are in p.elec.data.  The metric of the
 electrode coordinates returned is meters.
 
 Recognised file format types are:
 
 'cartesian','spherical1','spherical2'
 'scan3ddasc'
 'scantri'
 'brainstorm'
 'emse','elp'
 
 See also: elec_load, elec_load_scan_3ddasc, elec_load_scan_tri,
           elec_load_brainstorm, emse_read_elp

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [p] = elec_open(p)
0002 
0003 % elec_open - opens electrode data for the eeg_toolbox
0004 %
0005 % Usage: [p] = elec_open( p )
0006 %
0007 % p is the eeg_toolbox struct (see eeg_toolbox_defaults).
0008 % If p is omitted, the function uses the defaults.
0009 %
0010 % This function requires the fields:
0011 %
0012 % p.elec.path  - the directory location of the file to load
0013 % p.elec.file  - the name of the file to load
0014 % p.elec.type  - the file format type
0015 % p.elec.n     - how many electrodes to read
0016 % p.elec.plot  - boolean, 1 = plot, 2 = no plot
0017 %
0018 % The return values are in p.elec.data.  The metric of the
0019 % electrode coordinates returned is meters.
0020 %
0021 % Recognised file format types are:
0022 %
0023 % 'cartesian','spherical1','spherical2'
0024 % 'scan3ddasc'
0025 % 'scantri'
0026 % 'brainstorm'
0027 % 'emse','elp'
0028 %
0029 % See also: elec_load, elec_load_scan_3ddasc, elec_load_scan_tri,
0030 %           elec_load_brainstorm, emse_read_elp
0031 %
0032 
0033 % $Revision: 1.4 $ $Date: 2005/07/12 22:09:44 $
0034 
0035 % Licence:  GNU GPL, no express or implied warranties
0036 % History:  02/2002 Darren.Weber_at_radiology.ucsf.edu
0037 %
0038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0039 
0040 if ~exist('p','var'),[p] = eeg_toolbox_defaults; end
0041 if isempty(p),[p] = eeg_toolbox_defaults; end
0042 
0043 eegversion = '$Revision: 1.4 $';
0044 fprintf('ELEC_OPEN [v %s]\n',eegversion(11:15));
0045 
0046 [path,name,ext] = fileparts(strcat(p.elec.path,filesep,p.elec.file));
0047 file = fullfile(path,[name ext]);
0048 
0049 % Get electrode dataset, depeding on type of coordinates
0050 
0051 electype = lower(p.elec.type);
0052 
0053 switch electype,
0054   
0055   case {'cartesian','spherical1','spherical2'},
0056     
0057     [elec,type,X,Y,Z,theta,phi,r] = elec_load(file,p.elec.type,0,0,0,p.elec.n);
0058     % Get electrode centroid
0059     index = find(type == 99); 
0060     xo = X(index); 
0061     yo = Y(index); 
0062     zo = Z(index);
0063     p.elec.data.centroid = [xo yo zo];
0064     
0065     % Select electrodes only
0066     index = find(type == 69);
0067     elec = elec(index);
0068     x = X(index);
0069     y = Y(index);
0070     z = Z(index);
0071     theta = theta(index);
0072     phi   = phi(index);
0073     r     = r(index);
0074     
0075     p.elec.data.label = elec;
0076     p.elec.data.x = x;
0077     p.elec.data.y = y;
0078     p.elec.data.z = z;
0079     p.elec.data.theta = theta;
0080     p.elec.data.phi   = phi;
0081     p.elec.data.r     = r;
0082     
0083     index = find(type == 110);
0084     p.elec.data.nasion = [X(index) Y(index) Z(index)];
0085     index = find(type == 108);
0086     p.elec.data.lpa    = [X(index) Y(index) Z(index)];
0087     index = find(type == 114);
0088     p.elec.data.rpa    = [X(index) Y(index) Z(index)];
0089     index = find(type == 120);
0090     p.elec.data.ref    = [X(index) Y(index) Z(index)];
0091     
0092     
0093     
0094   case {'emse','elp'},
0095     
0096     elp = emse_read_elp(file);
0097     
0098     % an example elp struct:
0099     %        version: 3
0100     %       filetype: 2
0101     %      minor_rev: 1
0102     %     sensorType: 4001
0103     %        sensorN: 125
0104     %         nasion: [0.0957 0 0]
0105     %            lpa: [-7.1503e-004 0.0804 0]
0106     %            rpa: [7.1503e-004 -0.0804 0]
0107     %              x: [124x1 double]
0108     %              y: [124x1 double]
0109     %              z: [124x1 double]
0110     %            ref: [0.0089 -0.0732 -0.0214]
0111     %         origin: [-0.0083 0.0043 0.0496]
0112     %           type: {124x1 cell}
0113     %           name: {124x1 cell}
0114     
0115     % EMSE coordinate orientation is +X anterior and +Y left,
0116     % whereas eeg_toolbox is         +Y anterior and +X right
0117     % effectively rotated -90 degrees
0118     
0119     p.elec.data.ref(1) = elp.ref(2) * -1;
0120     p.elec.data.ref(2) = elp.ref(1);
0121     p.elec.data.ref(3) = elp.ref(3);
0122     
0123     p.elec.data.x = elp.y * -1;
0124     p.elec.data.y = elp.x;
0125     p.elec.data.z = elp.z;
0126     
0127     p.elec.data.centroid(1) = elp.origin(2) * -1;
0128     p.elec.data.centroid(2) = elp.origin(1);
0129     p.elec.data.centroid(3) = elp.origin(3);
0130     
0131     p.elec.data.nasion  = elp.nasion;
0132     p.elec.data.lpa     = elp.lpa;
0133     p.elec.data.rpa     = elp.rpa;
0134     
0135     p.elec.data.label   = elp.name;
0136     
0137     
0138   case 'brainstorm',
0139     
0140    [p] = elec_load_brainstorm(p);
0141     
0142     
0143   case 'scan3ddasc',
0144     
0145     scan3dd = elec_load_scan_3ddasc(file);
0146     
0147     fprintf('...converting electrode XYZ from cm to meters.\n');
0148     
0149     p.elec.data.x = scan3dd.x ./ 100;
0150     p.elec.data.y = scan3dd.y ./ 100;
0151     p.elec.data.z = scan3dd.z ./ 100;
0152     
0153     p.elec.data.nasion  = scan3dd.nasion ./ 100;
0154     p.elec.data.lpa     = scan3dd.lpa ./ 100;
0155     p.elec.data.rpa     = scan3dd.rpa ./ 100;
0156     
0157     p.elec.data.label   = scan3dd.label;
0158     
0159     p.elec.data.ref = scan3dd.ref ./ 100;
0160     
0161     p.elec.data.centroid = scan3dd.origin ./ 100;
0162     
0163     
0164   case 'scantri',
0165     
0166     % Neuroscan 3Dspace TRI file
0167     
0168     tri = elec_load_scan_tri(file);
0169     
0170     p.elec.data.label = tri.label;
0171     
0172     fprintf('...converting electrode XYZ from cm to meters.\n');
0173     p.elec.data.x = tri.XYZ(:,1) ./ 100;
0174     p.elec.data.y = tri.XYZ(:,2) ./ 100;
0175     p.elec.data.z = tri.XYZ(:,3) ./ 100;
0176     
0177     fprintf('...guessing origin is at (0,0,0).\n');
0178     p.elec.data.centroid = [0 0 0];
0179     
0180     
0181   otherwise,
0182     
0183     msg = sprintf('...cannot read file types %s\n',electype);
0184     error(msg);
0185     
0186 end
0187 
0188 
0189 
0190 % -- Calculate some extra parameters
0191 
0192 x = p.elec.data.x;
0193 y = p.elec.data.y;
0194 z = p.elec.data.z;
0195 
0196 xo = p.elec.data.centroid(1);
0197 yo = p.elec.data.centroid(2);
0198 zo = p.elec.data.centroid(3);
0199 
0200 if ~isfield(p.elec.data,'theta'),
0201   [theta,phi,r] = elec_cart2sph(x,y,z,xo,yo,zo);    
0202   p.elec.data.theta = theta;
0203   p.elec.data.phi   = phi;
0204   p.elec.data.r     = r;
0205 end
0206 
0207 % Estimate X,Y,Z radii
0208 Xrad = (max(x)-min(x))/2; 
0209 Yrad = (max(y)-min(y))/2; 
0210 Zrad = (max(z)-min(z));
0211 p.elec.data.R = [Xrad Yrad Zrad];
0212 
0213 % Estimate ellipse that best fits electrode co-ordinates
0214 [r,Xel,Yel,Zel] = elec_ellipse_fit(x,y,z,xo,yo,zo,100,p.elec.plot);
0215 p.elec.data.Xel = Xel;
0216 p.elec.data.Yel = Yel;
0217 p.elec.data.Zel = Zel;
0218 p.elec.data.Rel = r;
0219 
0220 % Estimate sphere that best fits electrode co-ordinates
0221 [r,Xsp,Ysp,Zsp] = elec_sphere_project(x,y,z,xo,yo,zo,1,p.elec.plot);
0222 p.elec.data.Xsp = Xsp;
0223 p.elec.data.Ysp = Ysp;
0224 p.elec.data.Zsp = Zsp;
0225 p.elec.data.Rsp = [r r r];
0226 
0227 % Create a refined spherical mesh and the interpolation
0228 % matrices - used in topographic mapping
0229 %p = elec_sph_refine(p);
0230 %p.elec.data.Lsp = mesh_laplacian(p.elec.data.Vsp,p.elec.data.Fsp);
0231 %p.elec.data.Isp = mesh_laplacian_interp(p.elec.data.Lsp, 1:length(p.elec.data.Xsp));
0232 
0233 % Define the electrode regions
0234 p.elec.data.regions = elec_regions;
0235 
0236 return

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