Read MEG data saved on SBI system and convert it to .meg.mat file. ---- Input - proj_root : Project root directory - meg_parm : structure with following field meg_parm.sbi_file : SBI-MEG file meg_parm.dicom_dir : SBI-DICOM dir meg_parm.dicom_file: SBI-DICOM table file (.tbl) meg_parm.analyze_file : ANALYZE file [proj_root '/' meg_parm.meg_file] : Output MEG file ---- Optional input - meg_parm.Pos_chk If 0, sensor position will not be converted to the DICOM coordinate. This option may be useful if you want to get MEG data without subject. - meg_parm.trials Set of trial numbers to read. - meg_parm.time_win = [Tstart Tend] [ms] Time window to read - meg_parm.eeg_name EEG channel to read list of channel index 'or' cell array of channel name defualt : [1 2] : {'AFP1'; 'AFP2'} ---- Output - bexp : MEG data (Channel, Time, Trial) - pick : Right-hand SPM coordinate pick(n, 1:3): position of detector coils, pick(n, 4:6): position of conpensation detector coils, pick(n, 7:9): direction of coils - MEGinfo : struct with MEG acquisition information MEGinfo.Nchannel_org % number of active gradiometers MEGinfo.Nchannel % number of active gardiometers MEGinfo.Nsample % sampling number of measurement MEGinfo.Pretriger % sampling number for pre-trigger MEGinfo.SampleFreq % sampling frequency MEGinfo.Nrepeat_org % repeat number MEGinfo.Nrepeat % repeat number MEGinfo.TrialNumber % valid trial number MEGinfo.Vcenter % origin of sphere model [m] MEGinfo.Vradius % radius of sphere model [m] MEGinfo.MEG_ID % MEG system ID MEGinfo.MRI_ID % MRI system ID MEGinfo.MEGch_name % Active MEG channel name MEGinfo.MEGch_id % Active MEG channel index MEGinfo.EEGch_name % EEG channel name to read - eog : EEG/EOG data Ver 1.0 written by M. Sato 2003-3-15 2004-12-27 Taku Yoshioka 2005-03-20 Modified by TY Ver 2.0 modified by M. Sato 2005-4-8 Center coordinate is SPM right-handed coordinate. DICOM-tbl and analyze files are required. (DICOM MRI is not required !!!) 2005-09-06 O.Y comment modified Ver 2.5 modified by M. Sato 2005-12-22 2007-06-22 (Sako) replace fileparts to vb_get_file_parts Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [bexp, pick, MEGinfo, eog] = ... 0002 make_sbi_meg_data(proj_root,meg_parm) 0003 % Read MEG data saved on SBI system and convert it to .meg.mat file. 0004 % 0005 % ---- Input 0006 % - proj_root : Project root directory 0007 % 0008 % - meg_parm : structure with following field 0009 % meg_parm.sbi_file : SBI-MEG file 0010 % meg_parm.dicom_dir : SBI-DICOM dir 0011 % meg_parm.dicom_file: SBI-DICOM table file (.tbl) 0012 % meg_parm.analyze_file : ANALYZE file 0013 % 0014 % [proj_root '/' meg_parm.meg_file] : Output MEG file 0015 % 0016 % ---- Optional input 0017 % - meg_parm.Pos_chk 0018 % If 0, sensor position will not be converted to the DICOM coordinate. 0019 % This option may be useful if you want to get MEG data without subject. 0020 % - meg_parm.trials 0021 % Set of trial numbers to read. 0022 % - meg_parm.time_win = [Tstart Tend] [ms] 0023 % Time window to read 0024 % - meg_parm.eeg_name 0025 % EEG channel to read 0026 % list of channel index 'or' cell array of channel name 0027 % defualt : [1 2] : {'AFP1'; 'AFP2'} 0028 % 0029 % ---- Output 0030 % - bexp : MEG data (Channel, Time, Trial) 0031 % - pick : Right-hand SPM coordinate 0032 % pick(n, 1:3): position of detector coils, 0033 % pick(n, 4:6): position of conpensation detector coils, 0034 % pick(n, 7:9): direction of coils 0035 % - MEGinfo : struct with MEG acquisition information 0036 % MEGinfo.Nchannel_org % number of active gradiometers 0037 % MEGinfo.Nchannel % number of active gardiometers 0038 % MEGinfo.Nsample % sampling number of measurement 0039 % MEGinfo.Pretriger % sampling number for pre-trigger 0040 % MEGinfo.SampleFreq % sampling frequency 0041 % MEGinfo.Nrepeat_org % repeat number 0042 % MEGinfo.Nrepeat % repeat number 0043 % MEGinfo.TrialNumber % valid trial number 0044 % MEGinfo.Vcenter % origin of sphere model [m] 0045 % MEGinfo.Vradius % radius of sphere model [m] 0046 % MEGinfo.MEG_ID % MEG system ID 0047 % MEGinfo.MRI_ID % MRI system ID 0048 % MEGinfo.MEGch_name % Active MEG channel name 0049 % MEGinfo.MEGch_id % Active MEG channel index 0050 % MEGinfo.EEGch_name % EEG channel name to read 0051 % 0052 % - eog : EEG/EOG data 0053 % 0054 % Ver 1.0 written by M. Sato 2003-3-15 0055 % 2004-12-27 Taku Yoshioka 0056 % 2005-03-20 Modified by TY 0057 % Ver 2.0 modified by M. Sato 2005-4-8 0058 % Center coordinate is SPM right-handed coordinate. 0059 % DICOM-tbl and analyze files are required. 0060 % (DICOM MRI is not required !!!) 0061 % 2005-09-06 O.Y 0062 % comment modified 0063 % Ver 2.5 modified by M. Sato 2005-12-22 0064 % 2007-06-22 (Sako) replace fileparts to vb_get_file_parts 0065 % 0066 % Copyright (C) 2011, ATR All Rights Reserved. 0067 % License : New BSD License(see VBMEG_LICENSE.txt) 0068 0069 global vbmeg_inst; 0070 define = vbmeg_inst.const; 0071 0072 analyze_file = meg_parm.analyze_file; 0073 0074 sbi_meg = meg_parm.sbi_file; 0075 dicom_dir = meg_parm.dicom_dir ; 0076 dicom_file = meg_parm.dicom_file; 0077 meg_file = [proj_root '/' meg_parm.meg_file]; 0078 0079 fprintf('--- Read MEG data: %s\n', sbi_meg); 0080 0081 % Directory & file name of SBI MEG file 0082 % [meg_dir, MEG_ID] = fileparts(sbi_meg); 0083 [meg_dir, MEG_ID] = vb_get_file_parts(sbi_meg); 0084 0085 meg_dir = [meg_dir '/']; 0086 0087 % 0088 % --- Read MEG data 0089 % 0090 [meg_info, pick1, pick2, bexp] ... 0091 = readSBI_meg(meg_dir,MEG_ID,meg_parm); 0092 0093 if meg_parm.Pos_chk, 0094 fprintf('--- MRI-DICOM dir: %s\n', dicom_dir); 0095 0096 % replace SBI-DICOM extension (.tbl) 0097 if ~isempty( findstr(dicom_file, define.DICOM2_EXTENSION) ) 0098 file_extension = define.DICOM2_EXTENSION; % *.tbl.mat 0099 else 0100 file_extension = define.DICOM1_EXTENSION; % *.tbl 0101 end 0102 0103 [Vdim, Vsize] = spm_hread([analyze_file]); 0104 if (isempty(Vdim) | isempty(Vsize)) % modified by dai-kaw (06.03.09) 0105 error(sprintf('can''t find analyze file: %s!!', analyze_file)); 0106 end 0107 0108 % get slice number from DICOM-tbl file 0109 MRI_ID = dicom_file(1:findstr(dicom_file, file_extension)-1); 0110 file_tbl = [MRI_ID define.DICOM1_EXTENSION ]; 0111 temp = readDICOMtbl(dicom_dir, file_tbl); 0112 0113 % DICOM mri-file (last slice) for coordinate transformation 0114 MRIfile = sprintf('%s%s%s.%d.mri', dicom_dir, filesep, MRI_ID, temp.nsl); 0115 0116 % 0117 % --- SBI-DICOM to MRI-Voxel coordinate 0118 % 0119 [pick1,pickv1] = inv_DICOM(MRIfile,0,0,0,1000*pick1(:,1:3),pick1(:,4:6)); 0120 [pick2,pickv2] = inv_DICOM(MRIfile,0,0,0,1000*pick2(:,1:3),pick2(:,4:6)); 0121 0122 % 0123 % --- Right-hand SPM coordinate [mm] 0124 % 0125 pick1 = vb_vox_to_spm_right(pick1, Vdim,Vsize); 0126 pick2 = vb_vox_to_spm_right(pick2, Vdim,Vsize); 0127 pickv1 = vb_vox_to_spm_right(pickv1); 0128 0129 pick(:,1:3) = pick1/1000; 0130 pick(:,4:6) = pick2/1000; 0131 pick(:,7:9) = pickv1; 0132 else 0133 MRI_ID = ''; 0134 pick(:,1:3) = pick1(:,1:3); 0135 pick(:,4:6) = pick2(:,1:3); 0136 pick(:,7:9) = pick1(:,4:6); 0137 end 0138 0139 % Center position of spherical brain model 0140 if isfield(meg_info,'sph0') 0141 Vcenter = meg_info.sph0; 0142 Vradius = meg_info.sphr; 0143 else 0144 Vcenter = [0 0 0]; 0145 Vradius = 0; 0146 end 0147 0148 if meg_parm.Pos_chk, 0149 Vcenter = inv_DICOM(MRIfile,0,0,0,1000*Vcenter(:)'); 0150 Vcenter = vb_vox_to_spm_right(Vcenter, Vdim,Vsize); 0151 Vcenter = Vcenter(:)./1000; 0152 end 0153 0154 % Latest file format (2005-12-22) 0155 MEGinfo.device = 'SBI'; % device type add(2006-3-3) 0156 MEGinfo.Nchannel_org = meg_info.nch; % number of active gradiometers 0157 MEGinfo.Nchannel = meg_info.nch; % number of active gardiometers 0158 MEGinfo.Nsample = meg_info.nsamp; % sampling number of measurement 0159 MEGinfo.Pretriger = meg_info.nprsamp; % sampling number for pre-trigger 0160 MEGinfo.SampleFreq = meg_info.sampf; % sampling frequency 0161 MEGinfo.Nrepeat_org = meg_info.nrept; % repeat number 0162 MEGinfo.Nrepeat = meg_info.nrept; % repeat number 0163 MEGinfo.TrialNumber = [1:MEGinfo.Nrepeat]'; % valid trial number 0164 MEGinfo.MEGch_name = meg_info.ch_name; % Active MEG channel name 0165 MEGinfo.MEGch_id = meg_info.active_ch;% Active MEG channel index 0166 0167 MEGinfo.Vcenter = Vcenter; % origin of sphere model [m] 0168 MEGinfo.Vradius = Vradius; % radius of sphere model [m] 0169 MEGinfo.MEG_ID = MEG_ID; % MEG system ID 0170 MEGinfo.MRI_ID = MRI_ID; % MRI system ID 0171 0172 % 0173 % --- Read EEG data 0174 % 0175 [eeg_info, eog] = readSBI_eeg([meg_dir '/../'],MEG_ID,meg_parm); 0176 0177 if ~isempty(eeg_info), 0178 ch_name = eeg_info.ch_name;% All EEG channel name 0179 0180 % Select EEG channel 0181 if isfield(meg_parm,'eeg_name') 0182 eeg_name = meg_parm.eeg_name;% EEG channel name to read 0183 0184 if iscell(eeg_name) 0185 Neeg = size(eeg_name,1); 0186 ix_ch = zeros(Neeg,1); 0187 0188 for n=1:Neeg 0189 ix_ch(n) = strmatch(eeg_name{n},ch_name); 0190 end 0191 else 0192 ix_ch = eeg_name; 0193 Neeg = length(ix_ch); 0194 eeg_name = cell(Neeg,1); 0195 0196 for n=1:Neeg 0197 eeg_name{n} = ch_name{ix_ch(n)}; 0198 end 0199 end 0200 else 0201 ix_ch = [13:14]; % {'AT3'; 'AT4'} vertical/horizontal eye movement 0202 Neeg = length(ix_ch); 0203 eeg_name = cell(Neeg,1); 0204 0205 for n=1:Neeg 0206 eeg_name{n} = ch_name{ix_ch(n)}; 0207 end 0208 end 0209 0210 if eog==0 0211 eog = []; 0212 else 0213 eog = eog(ix_ch,:,:); 0214 end 0215 else 0216 eeg_name = []; 0217 end 0218 0219 MEGinfo.EEGch_name = eeg_name; % EEG channel name 0220 0221 fprintf('--- Save MEG data [%s]\n',meg_file); 0222 0223 vb_save([meg_file], 'pick','bexp','MEGinfo','eog'); 0224