⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elec_open.m

📁 Matlab下的EEG处理程序库
💻 M
字号:
function [p] = elec_open(p)

% ELEC_OPEN - opens electrode data for the eeg_toolbox
% 
% Useage: [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.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','scan','spherical1','spherical2'
% 'scantri'
% 'brainstorm'
% 'emse','elp'
% 
% See also: ELEC_LOAD, ELEC_LOAD_SCANTRI,
%           ELEC_LOAD_BRAINSTORM, ELEC_EMSE2MATLAB
%

% $Revision: 1.3 $ $Date: 2003/04/07 06:12:02 $

% Licence:  GNU GPL, no express or implied warranties
% History:  02/2002 Darren.Weber@flinders.edu.au
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if ~exist('p','var'), p = eeg_toolbox_defaults; end
if isempty(p), p = eeg_toolbox_defaults; end

[path,name,ext] = fileparts(strcat(p.elec.path,filesep,p.elec.file));
file = fullfile(path,[name ext]);

% Get electrode dataset, depeding on type of coordinates

electype = lower(p.elec.type);

switch electype,
    
case {'cartesian','scan','spherical1','spherical2'},
    
    [elec,type,X,Y,Z,theta,phi,r] = elec_load(file,p.elec.type,0,0,0,p.elec.n);
    % Get electrode centroid
    index = find(type == 99); xo = X(index); yo = Y(index); zo = Z(index);
    p.elec.data.centroid = [xo yo zo];
    
    % Select electrodes only
    index = find(type == 69);
    elec = elec(index);
    x = X(index);
    y = Y(index);
    z = Z(index);
    theta = theta(index);
    phi   = phi(index);
    r     = r(index);
    
    p.elec.data.label = elec;
    p.elec.data.x = x;
    p.elec.data.y = y;
    p.elec.data.z = z;
    p.elec.data.theta = theta;
    p.elec.data.phi   = phi;
    p.elec.data.r     = r;
    
    index = find(type == 110);
    p.elec.data.nasion = [X(index) Y(index) Z(index)];
    index = find(type == 108);
    p.elec.data.lpa    = [X(index) Y(index) Z(index)];
    index = find(type == 114);
    p.elec.data.rpa    = [X(index) Y(index) Z(index)];
    index = find(type == 120);
    p.elec.data.ref    = [X(index) Y(index) Z(index)];
    
case {'emse','elp'},
    
    elp = elec_emse2matlab(file);
    
    % an example elp struct:
	%        version: 3
	%       filetype: 2
	%      minor_rev: 1
	%     sensorType: 4001
	%        sensorN: 125
	%         nasion: [0.0957 0 0]
	%            lpa: [-7.1503e-004 0.0804 0]
	%            rpa: [7.1503e-004 -0.0804 0]
	%              x: [124x1 double]
	%              y: [124x1 double]
	%              z: [124x1 double]
	%            ref: [0.0089 -0.0732 -0.0214]
	%         origin: [-0.0083 0.0043 0.0496]
	%           type: {124x1 cell}
	%           name: {124x1 cell}
    
    % EMSE coordinate orientation is +X anterior and +Y left,
    % whereas eeg_toolbox is         +Y anterior and +X right
    % effectively rotated -90 degrees
    
    p.elec.data.ref(1) = elp.ref(2) * -1;
    p.elec.data.ref(2) = elp.ref(1);
    p.elec.data.ref(3) = elp.ref(3);
    
    p.elec.data.x = elp.y * -1;
    p.elec.data.y = elp.x;
    p.elec.data.z = elp.z;
    
    p.elec.data.centroid(1) = elp.origin(2) * -1;
    p.elec.data.centroid(2) = elp.origin(1);
    p.elec.data.centroid(3) = elp.origin(3);
    
    p.elec.data.nasion  = elp.nasion;
    p.elec.data.lpa     = elp.lpa;
    p.elec.data.rpa     = elp.rpa;
    
    p.elec.data.label   = elp.name;
    
case 'brainstorm',
    
    p = elec_load_brainstorm(p);
    
case 'scantri',
    
    % Neuroscan 3Dspace TRI file
    
    tri = elec_load_scanTRI(file);
    
    p.elec.data.label = tri.label;
    p.elec.data.x = tri.XYZ(:,1) ./ 100;
    p.elec.data.y = tri.XYZ(:,2) ./ 100;
    p.elec.data.z = tri.XYZ(:,3) ./ 100;
    
    p.elec.data.centroid = [0 0 0]; % guessing
    
otherwise,
    
    msg = sprintf('Cannot read file types %s\n',electype);
    error(msg);
    
end



% -- Calculate some extra parameters

x = p.elec.data.x;
y = p.elec.data.y;
z = p.elec.data.z;

xo = p.elec.data.centroid(1);
yo = p.elec.data.centroid(2);
zo = p.elec.data.centroid(3);

if ~isfield(p.elec.data,'theta'),
	[theta,phi,r] = elec_cart2sph(x,y,z,xo,yo,zo);	
	p.elec.data.theta = theta;
	p.elec.data.phi   = phi;
	p.elec.data.r     = r;
end

% Estimate X,Y,Z radii
Xrad = (max(x)-min(x))/2; 
Yrad = (max(y)-min(y))/2; 
Zrad = (max(z)-min(z));
p.elec.data.R = [Xrad Yrad Zrad];

% Estimate ellipse that best fits electrode co-ordinates
[r,Xel,Yel,Zel] = elec_fit_ellipse(x,y,z,xo,yo,zo,100,p.elec.plot);
p.elec.data.Xel = Xel;
p.elec.data.Yel = Yel;
p.elec.data.Zel = Zel;
p.elec.data.Rel = r;

% Estimate sphere that best fits electrode co-ordinates
[r,Xsp,Ysp,Zsp] = elec_proj_sph(x,y,z,xo,yo,zo,1,p.elec.plot);
p.elec.data.Xsp = Xsp;
p.elec.data.Ysp = Ysp;
p.elec.data.Zsp = Zsp;
p.elec.data.Rsp = [r r r];

% Create a refined spherical mesh and the interpolation
% matrices - used in topographic mapping
%p = elec_sph_refine(p);
%p.elec.data.Lsp = mesh_laplacian(p.elec.data.Vsp,p.elec.data.Fsp);
%p.elec.data.Isp = mesh_laplacian_interp(p.elec.data.Lsp, 1:length(p.elec.data.Xsp));

% Define the electrode regions
p.elec.data.regions = elec_regions;


return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -