0001 function [eeg_light_info] = vb_eeg_make_light_info(bdf_spec)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 [bdf_file, digit_file, face_file, Vcenter] = inner_read_bdf_spec(bdf_spec);
0033
0034
0035
0036
0037 [header, RecordTime, Nch, SampleRate, ChannelLabel_hardware] = ...
0038 inner_get_local_var_bdf_file(bdf_file);
0039
0040 [SensorPosition, CoordType, ChannelLabel_standard] ...
0041 = inner_get_info_digit_file(digit_file);
0042 [Vcenter] = inner_get_info_face_file(face_file)
0043
0044
0045 eeg_light_info.measurement = 'EEG';
0046 eeg_light_info.version = 'LIGHT'
0047 eeg_light_info.header = header;
0048 eeg_light_info.device = 'BIOSEMI';
0049 eeg_light_info.ChannelLabel_hardware = ChannelLabel_hardware;
0050 eeg_light_info.Nchannel = Nch;
0051 eeg_light_info.SampleFrequency = SampleRate;
0052 eeg_light_info.RecordTime = RecordTime;
0053 eeg_light_info.Nsample = RecordTime * SampleRate;
0054 eeg_light_info.ChannelLabel_standard = ChannelLabel_standard;
0055 eeg_light_info = vb_eeginfo_set_sensor_position(eeg_light_info, SensorPosition);
0056 eeg_light_info.CoordType = CoordType;
0057 eeg_light_info.Vcenter = Vcenter;
0058
0059 return;
0060
0061
0062
0063
0064
0065
0066
0067 function [bdf_file, digit_file, face_file, Vcenter] = ...
0068 inner_read_bdf_spec(bdf_spec)
0069
0070 vb_define_device;
0071
0072 func_ = mfilename;
0073
0074
0075
0076
0077 if ~isfield(bdf_spec, 'bdf_file') || isempty(bdf_spec.bdf_file)
0078 error('(%s)bdf_file is a required parameter of bdf_spec', func_);
0079 end
0080
0081 bdf_file = bdf_spec.bdf_file;
0082
0083 if exist(bdf_file, 'file') ~= 2
0084 error('(%s)cannot read bdf_file : %s', func_, bdf_file);
0085 end
0086
0087
0088
0089
0090 if ~isfield(bdf_spec, 'digit_file') || isempty(bdf_spec.digit_file)
0091 error('(%s)digit_file is a required parameter of bdf_spec', func_);
0092 end
0093
0094 digit_file = bdf_spec.digit_file;
0095
0096 if exist(digit_file, 'file') ~= 2
0097 error('(%s)cannot read digit_file : %s', func_, digit_file);
0098 end
0099
0100
0101
0102
0103 Vcenter = [];
0104 face_file = [];
0105 if ~isfield(bdf_spec, 'face_file') || isempty(bdf_spec.face_file)
0106 Vcenter = [0 0 0];
0107 else
0108 face_file = bdf_spec.face_file;
0109
0110 if exist(digit_file, 'file') ~= 2
0111 warning('(%s)cannot read digit_file : %s', func_, digit_file);
0112 Vcenter = [0 0 0];
0113 end
0114 end
0115
0116
0117
0118
0119
0120 function [header, RecordTime, Nch, SampleRate, ChannelLabel_hardware] = ...
0121 inner_get_local_var_bdf_file(bdf_file)
0122
0123 [DAT,H1] = vb_openbdf(bdf_file);
0124
0125
0126 header = DAT.Head;
0127 RecordTime = DAT.Head.NRec;
0128 Nch = DAT.Head.NS;
0129 SampleRate = max(DAT.Head.SampleRate);
0130
0131 ChannelLabel_hardware = cell(1,Nch);
0132
0133
0134 for ch = 1:Nch
0135 ChannelLabel_hardware{ch} = deblank(DAT.Head.Label(ch,:));
0136 end
0137
0138
0139
0140
0141
0142 function [SensorPosition, CoordType, ChannelLabel] ...
0143 = inner_get_info_digit_file(digit_file)
0144
0145 eeg_sensor = [];
0146 SensorPosition = [];
0147 CoordType = [];
0148 ChannelLabel = [];
0149
0150 load(digit_file, 'eeg_sensor');
0151
0152 if isempty(eeg_sensor)
0153 error('invalid digit_file:%s - cannot find eeg_sensor field', digit_file);
0154 end;
0155 if ~isfield(eeg_sensor, 'mri')
0156 error('invalid digit_file:%s - cannot find ''mri'' field', digit_file);
0157 end
0158 if ~isfield(eeg_sensor, 'name')
0159 error('invalid digit_file:%s - cannot find ''name'' field', digit_file);
0160 end
0161 if ~isfield(eeg_sensor, 'coord_type_mri')
0162 error('invalid digit_file:%s - cannot find ''coord_type_mri'' field', digit_file);
0163 end
0164
0165 SensorPosition = eeg_sensor.mri;
0166 CoordType = eeg_sensor.coord_type_mri;
0167
0168
0169 ChannelLabel = vb_util_arrange_list(eeg_sensor.name);
0170 return;
0171
0172
0173
0174
0175
0176 function [Vcenter] = inner_get_info_face_file(face_file)
0177 subject = [];
0178 load(face_file, 'subject');
0179 if isempty(subject)
0180 error('invalid face_file:%s - cannot find subject field', face_file);
0181 end
0182 if ~isfield(subject, 'spherical_head')
0183 error('invalid face_file:%s - cannot find spherical_head field', face_file);
0184 end
0185
0186 if ~isfield(subject.spherical_head, 'Vcenter')
0187 error('invalid face_file:%s - cannot find Vcenter field', face_file);
0188 end
0189
0190 Vcenter = subject.spherical_head.Vcenter;
0191 return;
0192
0193
0194
0195