Home > bioelectromagnetism > elec_3Dspace2brainstorm.m

elec_3Dspace2brainstorm

PURPOSE ^

elec_3dspace2brainstorm - Convert NeuroScan 3Dspace ascii to brainstorm file

SYNOPSIS ^

function [Channel] = elec_3dspace2brainstorm(filename,N,bsfile)

DESCRIPTION ^

 elec_3dspace2brainstorm - Convert NeuroScan 3Dspace ascii to brainstorm file
 
 The ascii file format is that of NeuroScan 3Dspace export files.  Each row
 of the file comprises an electrode label, an electrode type code, and
 the x,y,z coordinates (cm).  Each field is separated by spaces.  See
 ELEC_LOAD for more information.
 
 Useage: Channel = elec_3dspace2brainstorm(filename,[N],[brainstormfile])
 
 where:    file = 'path\filename' with format described in ELEC_LOAD
 
           N is how many electrodes to load (rows of 3Dspace file, 129 default).
 
 Result:   Channel is an array of structures.  The fields are:
           
           Loc     - a 3x2 matrix of electrode coordinates (x,y,z in rows).
                     BrainStorm (x,y,z meters) = 3Dspace (x,y,z cm) / 100.
           Orient  - a corresponding matrix of sensor orientations (MEG); 
                     all zero for EEG.
           Weight  - a vector of relative or absolute weights (eg, amplification);
                     all ones for this routine.
           Type    - a character string, 'EEG' in this case.
           Name    - a charater string indicating the electrode name.
           Comment - a charater string indicating the reference electrode.  Empty
                     for active electrodes and 'EEG REF' for reference electrode.
 
 See brainstorm website at http://neuroimage.usc.edu/, including a
 download pdf file describing the brainstorm database formats.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Channel] = elec_3dspace2brainstorm(filename,N,bsfile)
0002 
0003 % elec_3dspace2brainstorm - Convert NeuroScan 3Dspace ascii to brainstorm file
0004 %
0005 % The ascii file format is that of NeuroScan 3Dspace export files.  Each row
0006 % of the file comprises an electrode label, an electrode type code, and
0007 % the x,y,z coordinates (cm).  Each field is separated by spaces.  See
0008 % ELEC_LOAD for more information.
0009 %
0010 % Useage: Channel = elec_3dspace2brainstorm(filename,[N],[brainstormfile])
0011 %
0012 % where:    file = 'path\filename' with format described in ELEC_LOAD
0013 %
0014 %           N is how many electrodes to load (rows of 3Dspace file, 129 default).
0015 %
0016 % Result:   Channel is an array of structures.  The fields are:
0017 %
0018 %           Loc     - a 3x2 matrix of electrode coordinates (x,y,z in rows).
0019 %                     BrainStorm (x,y,z meters) = 3Dspace (x,y,z cm) / 100.
0020 %           Orient  - a corresponding matrix of sensor orientations (MEG);
0021 %                     all zero for EEG.
0022 %           Weight  - a vector of relative or absolute weights (eg, amplification);
0023 %                     all ones for this routine.
0024 %           Type    - a character string, 'EEG' in this case.
0025 %           Name    - a charater string indicating the electrode name.
0026 %           Comment - a charater string indicating the reference electrode.  Empty
0027 %                     for active electrodes and 'EEG REF' for reference electrode.
0028 %
0029 % See brainstorm website at http://neuroimage.usc.edu/, including a
0030 % download pdf file describing the brainstorm database formats.
0031 %
0032 
0033 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0034 
0035 % Licence:  GNU GPL, no express or implied warranties
0036 % History:  20/05/2002, Darren.Weber_at_radiology.ucsf.edu
0037 %
0038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0039 
0040 if ~exist('N', 'var'), N = 129;
0041 elseif isempty(N),     N = 129;
0042 end
0043 
0044 file = char(filename);
0045 
0046 [elec,type,X,Y,Z] = elec_load(file,[],[],[],[],N);
0047 
0048 tic;
0049 
0050 fprintf('\nELEC_3DSPACE2BRAINSTORM...\n');
0051 fprintf('...Converting to brainstorm structure.\n');
0052 
0053 elecindex = find(type == 69);
0054 Ee = elec(elecindex);
0055 Xe = X(elecindex) ./ 100;   % 3Dspace is cm, BrainStorm is m
0056 Ye = Y(elecindex) ./ 100;
0057 Ze = Z(elecindex) ./ 100;
0058 
0059 reftype = ones(size(type)) * 120;
0060 refindex = find(type == reftype);
0061 Eref = elec(refindex);
0062 Xref = X(refindex) ./ 100;   % 3Dspace is cm, BrainStorm is m
0063 Yref = Y(refindex) ./ 100;
0064 Zref = Z(refindex) ./ 100;
0065 
0066 for i=1:length(elecindex),
0067     Channel(i).Loc = [[Xe(i) Ye(i) Ze(i)]',[Xref Yref Zref]'];
0068     Channel(i).Orient = [];     % used for MEG rather than EEG
0069     Channel(i).Weight = 1;      % Like Amplification
0070     Channel(i).Type = 'EEG';
0071     Channel(i).Name = char(Ee(i));
0072     Channel(i).Comment = '';
0073 end
0074 Channel(i+1).Loc = [[Xref Yref Zref]',[Xref Yref Zref]'];
0075 Channel(i+1).Orient = [];
0076 Channel(i+1).Weight = 1;
0077 Channel(i+1).Type = 'EEG';
0078 Channel(i+1).Name = char(Eref);
0079 Channel(i+1).Comment = 'EEG REF';
0080 
0081 if ~exist('bsfile', 'var'),
0082     bsfile = 'channel';
0083 elseif isempty(bsfile),
0084     bsfile = 'channel';
0085 end
0086 
0087 if findstr('.mat',bsfile),
0088     bsfile = strrep(bsfile,'.mat','');
0089 end
0090 
0091 fprintf('...saving BrainStorm channel data to:\n\t%s.mat\n',bsfile);
0092 save(bsfile, 'Channel');
0093 
0094 
0095 t = toc; fprintf('...done (%6.2f sec).\n\n',t);
0096 
0097 return

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