eeg_write_brainstorm - Write EEG data into brainstorm format Useage: eeg_write_brainstorm(fileprefix, data) file - the path + filename, eg "c:\subj_data.mat" It is actually a fileprefix, as the _data.mat are appended by this function (they are mandatory) data - a matlab structure with brainstorm data fields. There are 2 essential fields (others are initialised): F a matrix of voltage values (in Volts) with electrodes in rows and data points in columns. Time Time is a row vector with time points (in sec) for each column of the voltage data. This script does not convert the voltage data from uV to Volts or the Time from msec to sec. Also, it assumes that the associated Channel struct for this EEG data has the last Channel.Type = 'EEG REF' so the ChannelFlag array output from this function contains a -1 at index = size(data.F,1) + 1. Comment: See the brainstorm website for more info, at http://neuroimage.usc.edu/.
0001 function eeg_write_brainstorm(fileprefix,data) 0002 0003 % eeg_write_brainstorm - Write EEG data into brainstorm format 0004 % 0005 % Useage: eeg_write_brainstorm(fileprefix, data) 0006 % 0007 % file - the path + filename, eg "c:\subj_data.mat" 0008 % It is actually a fileprefix, as the _data.mat are 0009 % appended by this function (they are mandatory) 0010 % 0011 % data - a matlab structure with brainstorm data fields. 0012 % There are 2 essential fields (others are initialised): 0013 % 0014 % F a matrix of voltage values (in Volts) with 0015 % electrodes in rows and data points in columns. 0016 % Time Time is a row vector with time points (in sec) 0017 % for each column of the voltage data. 0018 % 0019 % This script does not convert the voltage data from uV to Volts 0020 % or the Time from msec to sec. Also, it assumes that the associated 0021 % Channel struct for this EEG data has the last Channel.Type = 'EEG REF' 0022 % so the ChannelFlag array output from this function contains a -1 at 0023 % index = size(data.F,1) + 1. 0024 % 0025 % Comment: See the brainstorm website for more info, at 0026 % http://neuroimage.usc.edu/. 0027 % 0028 0029 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $ 0030 0031 % Licence: GNU GPL, no express or implied warranties 0032 % Author: 07/2001, Darren.Weber_at_radiology.ucsf.edu 0033 % 10/2002, Darren.Weber_at_radiology.ucsf.edu 0034 % modified warnings and channelflag 0035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0036 0037 fprintf('EEG_WRITE_BRAINSTORM...\n'); tic; 0038 0039 if isfield(data,'F'), 0040 F = data.F; 0041 else 0042 msg = strcat('data structure must contain an ''F'' field.\n',... 0043 'F is a matrix of voltage values (in Volts)\n',... 0044 'with electrodes in rows and data points in columns.\n'); 0045 error(sprintf(msg)); 0046 end 0047 if isfield(data,'Time'), 0048 Time = data.Time; 0049 else 0050 msg = strcat('data structure must contain a ''Time'' field.\n',... 0051 'Time is a row vector with time points (in sec)\n',... 0052 'for each column of the voltage data.\n'); 0053 error(sprintf(msg)); 0054 end 0055 if isfield(data,'ChannelFlag'), 0056 ChannelFlag = data.ChannelFlag; 0057 else 0058 % msg = strcat('data structure can contain a ''ChannelFlag'' field.\n',... 0059 % 'ChannelFlag is a row vector indicating the status\n',... 0060 % 'of the electrodes (-1 is dead, 0 is ignored, 1 is good).\n',... 0061 % 'Creating this vector = ones(1,size(data.F,1)).\n'); 0062 % fprintf(msg); 0063 0064 ChannelFlag = [ones(1,size(F,1)), -1]; 0065 fprintf('...assume data Nchannels + 1 is ref, so ChannelFlag(Nchannels + 1) = -1\n'); 0066 end 0067 if isfield(data,'NoiseCov'), 0068 NoiseCov = data.NoiseCov; 0069 else 0070 % msg = strcat('data structure can contain a ''NoiseCov'' field.\n',... 0071 % 'This is a square matrix the size of the electrodes\n',... 0072 % 'Creating this vector = ones(size(data.F,1)).\n'); 0073 % fprintf(msg); 0074 NoiseCov = []; 0075 end 0076 if isfield(data,'SourceCov'), 0077 SourceCov = data.SourceCov; 0078 else 0079 % msg = strcat('data structure can contain a ''SourceCov'' field.\n',... 0080 % 'This is a square matrix the size of ImageGridLoc(?)\n',... 0081 % 'Creating this matrix = [].\n'); 0082 % fprintf(msg); 0083 SourceCov = []; 0084 end 0085 if isfield(data,'Project'), 0086 Projector = data.Project; 0087 else 0088 % msg = strcat('data structure can contain a ''Project'' field.\n',... 0089 % 'Not sure what it is, but it is created for the ascii\n',... 0090 % 'tutorial data. Creating this matrix = [].\n'); 0091 % fprintf(msg); 0092 Project = []; 0093 end 0094 if isfield(data,'Projector'), 0095 Projector = data.Projector; 0096 else 0097 % msg = strcat('data structure can contain a ''Projector'' field.\n',... 0098 % 'This is a matrix of size length of electrodes by rank,\n',... 0099 % 'not necessarily orthogonal due to Good-Channel selections.\n',... 0100 % 'Orthogonalized as ''U'', then the data are to be projected away\n',... 0101 % 'from the projector as F'' = F - U*(U^t * F).\n',... 0102 % 'Creating this matrix = [].\n'); 0103 % fprintf(msg); 0104 Projector = []; 0105 end 0106 if isfield(data,'Comment'), 0107 Comment = data.Comment; 0108 else 0109 % msg = strcat('data structure can contain a ''Comment'' field.\n',... 0110 % 'This is a character string describing the data.\n',... 0111 % 'Creating this field = file.\n'); 0112 % fprintf(msg); 0113 Comment = fileprefix; 0114 end 0115 if isfield(data,'Device'), 0116 Device = data.Device; 0117 else 0118 % msg = strcat('data structure can contain a ''Device'' field.\n',... 0119 % 'This is a character string describing the device\n',... 0120 % 'used to acquire the data (eg, SYNAMPS)\n',... 0121 % 'Creating an empty field.\n'); 0122 % fprintf(msg); 0123 Device = 'Neuromag_Planar_122'; % the only supported device! 0124 end 0125 0126 [path,file,ext] = fileparts(fileprefix); 0127 ext = '_data.mat'; 0128 0129 file = fullfile(path,[file ext]); 0130 0131 save(file,'F','Time','ChannelFlag','NoiseCov','SourceCov',... 0132 'Project','Projector','Comment','Device'); 0133 0134 fprintf('...wrote brainstorm data to:\n\t%s\n', file); 0135 0136 t = toc; fprintf('...done (%6.2f sec).\n\n',t); 0137 0138 return