Current reconstruction using Bayesian inverse filter. [syntax] [Zact,Jinfo,bayes_parm,vb_parm,MEGinfo] ... = vbmeg_current_reconstruct_z_tr(proj_root,curr_parm) [input] proj_root: <<string>> VBMEG project root directory. curr_parm: <<struct>> Parameters for current estimation. --- fields of curr_parm bayesfile : <<string>> Model parameter file (.bayes.mat). currfile : <<string>> Cortical current file (.curr.mat), created by this function. jactdir : <<string>> Directory for saving trial current files. Relative path from cortical current file. trial_average: <optional> <<bool>> If true, = [ON] : average current over all sessions = OFF : current for each session ix_area : <optional> Vertex indices to calculate estimated current. If 'ix_area' is empty or not given, cortical currents in the active region are calculated. tsubsmpl : <optional> <bosolete> Specify subsampled time index. If 'tsubsmpl' is empty or not given, time subsampling is not done. dsampf : <optional> <<int>> Specify frequency of downsampling. This value must be smaller than the original sampling frequency of M/EEG data. overlap_mode : <optional> <<int>> = 0 : current is averaged over overlapped time window = 1 : current is not averaged for overlapped window current time series of each time windows are concatenated sequentially for spectral analysis ix_trial : <optional> Trial indices for which currents are reconstructed. verbose : <<bool>> Verbose flag. --- [note] If following field is given, these values are used instead of bayes_parm field in result file: --- curr_parm.basisfile curr_parm.megfile curr_parm.twin_meg curr_parm.Tperiod curr_parm.Tnext --- [output] Zact : active current Zact(n,t,:) is the current at the vertex 'ix_act(n)' & the time 't' Zact(Nact,Nsample) for trial_average = ON Zact(Nact,Nsample,Ntrials) for trial_average = OFF Nact : # of active region, Nsample : # of time sample, Ntrials : # of trials in all session] Jinfo: <<struct>> Information of cortical current. --- fields of Jinfo version : <<string>> Version of cortical current file. curr_type : <<string>> 'Z-current'. It can be 'J-current' for VBMEG version 0.8 or older. Wact : <<float matrix>> Smoothing Gaussian filter, mapping from Z-current to J-current. ix_act : <<int vector>>: Vertex indices of Z-current. ix_act_ex : <<int vector>>: Vertex indices of J-current. Lact : <<int>> Number of current direction at one vertex. Tsample : <<int vector>> Time sample indices of the original MEG data. length(Tsample) == size(Zact,2) == size(Jact,2). Tmsec : <<float vector>> Time in msec. SampleFreq: <<float>> Sample frequency of cortical current, not original M/EEG signal [Hz]. Pretrigger: <<int>> Time points of the length of the pretrigger period of cortical current data. It is neither actual time nor time points of the original M/EEG signal. Ntrial : <<int>> Number of trials of estimated current. patch_norm: <<bool>> Cortical current is patch size normalized (Am/m^2) or not (Am). Tix : <<L x 1 cell>> Time sample indices of each time window. Zact(:,Tix{n},:) is the set of Z-current within the n-th time window. --- [history] 2006-09-03 M. Sato * Non-overlapped concatenation mode is added for spectral analysis 2008-08-25 Taku Yoshioka Extra dipole support 2008-09-30 Taku Yoshioka Minor change for variables in Jinfo 2008-10-23 Taku Yoshioka Bug fix for current estimation without extra dipoles 2009-04-02 Taku Yoshioka Parameter name changed within this code for readability (just replacing 'resultfile' to bayesfile) 2010-03-01 M. Sato Bug fix for Wact index and fieldname(tsubsamp->tsubsmpl) 2010-05-26 Taku Yoshioka Message display changed 2010-12-06 taku-y [enhancement] curr_parm.dsampf supported. [minor] Following fields of Jinfo set in this function: SampleFreq Pretrigger Tmsec [trivial] Jinfo.version = vb_version. 2010-12-07 taku-y [trivial] Jinfo.version = vbmeg('version'); 2011-05-11 takiu-y [debug] Jinfo.Tmsec corrected. 2011-06-28 taku-y [minor] Jinfo.Tix added. 2012-02-15 taku-y [debug] Jinfo.SampleFreq could be empty in a certain case. This bug was fixed. 2017-03-16 rhayashi spatial_smoother is added. 2017-12-8 rhayashi [debug] The specified basis_file and eegfile are not used properly. Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [Zact_ave,Jinfo,bayes_parm,vb_parm,MEGinfo,Jext_ave,Pointlist] ... 0002 = vb_current_reconstruct_z_tr_meeg(proj_root,curr_parm); 0003 % Current reconstruction using Bayesian inverse filter. 0004 % 0005 % [syntax] 0006 % [Zact,Jinfo,bayes_parm,vb_parm,MEGinfo] ... 0007 % = vbmeg_current_reconstruct_z_tr(proj_root,curr_parm) 0008 % 0009 % [input] 0010 % proj_root: <<string>> VBMEG project root directory. 0011 % curr_parm: <<struct>> Parameters for current estimation. 0012 % --- fields of curr_parm 0013 % bayesfile : <<string>> Model parameter file (.bayes.mat). 0014 % currfile : <<string>> Cortical current file (.curr.mat), created 0015 % by this function. 0016 % jactdir : <<string>> Directory for saving trial current 0017 % files. Relative path from cortical current file. 0018 % trial_average: <optional> <<bool>> If true, 0019 % = [ON] : average current over all sessions 0020 % = OFF : current for each session 0021 % ix_area : <optional> Vertex indices to calculate estimated 0022 % current. If 'ix_area' is empty or not given, cortical 0023 % currents in the active region are calculated. 0024 % tsubsmpl : <optional> <bosolete> Specify subsampled time 0025 % index. If 'tsubsmpl' is empty or not given, time 0026 % subsampling is not done. 0027 % dsampf : <optional> <<int>> Specify frequency of 0028 % downsampling. This value must be smaller than the 0029 % original sampling frequency of M/EEG data. 0030 % overlap_mode : <optional> <<int>> 0031 % = 0 : current is averaged over overlapped time window 0032 % = 1 : current is not averaged for overlapped window 0033 % current time series of each time windows 0034 % are concatenated sequentially for spectral analysis 0035 % ix_trial : <optional> Trial indices for which currents are 0036 % reconstructed. 0037 % verbose : <<bool>> Verbose flag. 0038 % --- 0039 % 0040 % [note] If following field is given, these values are used instead of 0041 % bayes_parm field in result file: 0042 % --- 0043 % curr_parm.basisfile 0044 % curr_parm.megfile 0045 % curr_parm.twin_meg 0046 % curr_parm.Tperiod 0047 % curr_parm.Tnext 0048 % --- 0049 % 0050 % [output] 0051 % Zact : active current 0052 % 0053 % Zact(n,t,:) is the current at the vertex 'ix_act(n)' & the time 't' 0054 % Zact(Nact,Nsample) for trial_average = ON 0055 % Zact(Nact,Nsample,Ntrials) for trial_average = OFF 0056 % Nact : # of active region, 0057 % Nsample : # of time sample, 0058 % Ntrials : # of trials in all session] 0059 % Jinfo: <<struct>> Information of cortical current. 0060 % --- fields of Jinfo 0061 % version : <<string>> Version of cortical current file. 0062 % curr_type : <<string>> 'Z-current'. It can be 'J-current' for VBMEG 0063 % version 0.8 or older. 0064 % Wact : <<float matrix>> Smoothing Gaussian filter, mapping from 0065 % Z-current to J-current. 0066 % ix_act : <<int vector>>: Vertex indices of Z-current. 0067 % ix_act_ex : <<int vector>>: Vertex indices of J-current. 0068 % Lact : <<int>> Number of current direction at one vertex. 0069 % Tsample : <<int vector>> Time sample indices of the original MEG 0070 % data. length(Tsample) == size(Zact,2) == size(Jact,2). 0071 % Tmsec : <<float vector>> Time in msec. 0072 % SampleFreq: <<float>> Sample frequency of cortical current, not 0073 % original M/EEG signal [Hz]. 0074 % Pretrigger: <<int>> Time points of the length of the pretrigger 0075 % period of cortical current data. It is neither actual time 0076 % nor time points of the original M/EEG signal. 0077 % Ntrial : <<int>> Number of trials of estimated current. 0078 % patch_norm: <<bool>> Cortical current is patch size normalized 0079 % (Am/m^2) or not (Am). 0080 % Tix : <<L x 1 cell>> Time sample indices of each time window. 0081 % Zact(:,Tix{n},:) is the set of Z-current within the n-th 0082 % time window. 0083 % --- 0084 % 0085 % [history] 0086 % 2006-09-03 M. Sato 0087 % * Non-overlapped concatenation mode is added for spectral analysis 0088 % 2008-08-25 Taku Yoshioka 0089 % Extra dipole support 0090 % 2008-09-30 Taku Yoshioka 0091 % Minor change for variables in Jinfo 0092 % 2008-10-23 Taku Yoshioka 0093 % Bug fix for current estimation without extra dipoles 0094 % 2009-04-02 Taku Yoshioka 0095 % Parameter name changed within this code for readability 0096 % (just replacing 'resultfile' to bayesfile) 0097 % 2010-03-01 M. Sato 0098 % Bug fix for Wact index and fieldname(tsubsamp->tsubsmpl) 0099 % 2010-05-26 Taku Yoshioka 0100 % Message display changed 0101 % 2010-12-06 taku-y 0102 % [enhancement] curr_parm.dsampf supported. 0103 % [minor] Following fields of Jinfo set in this function: 0104 % SampleFreq 0105 % Pretrigger 0106 % Tmsec 0107 % [trivial] Jinfo.version = vb_version. 0108 % 2010-12-07 taku-y 0109 % [trivial] Jinfo.version = vbmeg('version'); 0110 % 2011-05-11 takiu-y 0111 % [debug] Jinfo.Tmsec corrected. 0112 % 2011-06-28 taku-y 0113 % [minor] Jinfo.Tix added. 0114 % 2012-02-15 taku-y 0115 % [debug] Jinfo.SampleFreq could be empty in a certain case. This bug 0116 % was fixed. 0117 % 2017-03-16 rhayashi 0118 % spatial_smoother is added. 0119 % 2017-12-8 rhayashi 0120 % [debug] The specified basis_file and eegfile are not used properly. 0121 % 0122 % Copyright (C) 2011, ATR All Rights Reserved. 0123 % License : New BSD License(see VBMEG_LICENSE.txt) 0124 0125 if ~isempty(proj_root) 0126 bayesfile = fullfile(proj_root, curr_parm.bayesfile); 0127 else 0128 bayesfile = curr_parm.bayesfile; 0129 end 0130 0131 % 0132 % Verbose level setting 0133 % (note: 'verbose_level' is not related to input variable 0134 % 'curr_parm.verbose'. So two configurations relating to message display 0135 % are coexisting in this function.) 0136 % 0137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0138 global vbmeg_inst 0139 verbose_const = vb_define_verbose; 0140 0141 if isempty(vbmeg_inst) | ~isfield(vbmeg_inst,'verbose_level'), 0142 verbose_level = verbose_const.VERBOSE_LEVEL_NOTICE; 0143 else 0144 verbose_level = vbmeg_inst.verbose_level; 0145 end 0146 0147 % 0148 % load VBMEG estimated result 0149 % 0150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0151 load(bayesfile, 'bayes_parm','Model','vb_parm','Model_ext','Pointlist'); 0152 0153 % 0154 % check parameter of 'curr_parm' 0155 % 0156 % Values of 'curr_parm' fields dominates over 0157 % those of 'bayes_parm' in bayesfile 0158 % 0159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0160 [bayes_parm,ix_area,trial_average,tsubsamp,overlap_mode,verbose,dsampf] ... 0161 = check_arg(bayes_parm,curr_parm); 0162 0163 if ~isempty(proj_root) 0164 bayes_parm_abs = vb_parm_absolute_path(proj_root, bayes_parm); 0165 else 0166 bayes_parm_abs = bayes_parm; 0167 end 0168 0169 % current file directory 0170 if ~isempty(proj_root) 0171 currfile = fullfile(proj_root, curr_parm.currfile); 0172 else 0173 currfile = [curr_parm.currfile]; 0174 end 0175 0176 % jactdir is relative path from current file 0177 jactdir = curr_parm.jactdir; 0178 curr_root = fileparts(currfile); 0179 jactdir_ab = fullfile(curr_root, jactdir); 0180 0181 %check directory 0182 if exist(jactdir_ab,'dir') ~= 0 0183 if verbose_level>=verbose_const.VERBOSE_LEVEL_NOTICE, 0184 msg = [ 'jact_dir : ' jactdir_ab ' exists. Do you over write?']; 0185 btn = questdlg(msg, 'confirm', 'Yes', 'No', 'Yes'); 0186 if strcmp(btn, 'No') 0187 error('processing aborted.'); 0188 return; 0189 end 0190 else 0191 vb_disp(['jact_dir : ' jactdir_ab ' exists. So files in this ' ... 0192 'directory are overwritten with new ones.'], ... 0193 verbose_const.VERBOSE_LEVEL_WARNING); 0194 end 0195 else 0196 res = mkdir(curr_root, jactdir); 0197 if res~= 1, error('mkdir failed.'); end 0198 end 0199 0200 % Trial indices 0201 if isfield(bayes_parm_abs,'ix_trial'), 0202 bayes_parm_abs.ix_trial = bayes_parm_abs.ix_trial; 0203 elseif isfield(curr_parm,'ix_trial'), 0204 bayes_parm_abs.ix_trial = curr_parm.ix_trial; 0205 else 0206 bayes_parm_abs.ix_trial = []; 0207 end 0208 0209 % 0210 % MEG data preparation 0211 % B : MEG data 0212 % 0213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0214 [B0,Ntrials,Nch,Tsample,Twindow,Tmsec] ... 0215 = vb_megdata_preparation(bayes_parm_abs); 0216 MEGinfo = vb_load_meg_info(bayes_parm_abs.megfile{1}); 0217 0218 % EEG data 0219 for n = 1:length(bayes_parm_abs.eegfile) 0220 bayes_parm_abs.eegfile{n} = fullfile(proj_root, bayes_parm_abs.eegfile{n}); 0221 end 0222 tmp_parm = bayes_parm_abs; 0223 tmp_parm.megfile = tmp_parm.eegfile; 0224 E = vb_megdata_preparation(tmp_parm); 0225 0226 for n = 1:length(B0) 0227 B{n} = [B0{n}./Model.bsnorm_meg; E{n}./Model.bsnorm_eeg]; 0228 end 0229 0230 % 0231 % Preparation of lead fields 0232 % Gact : leadfield of focal window 0233 % ix_act : Vertex index corresponding to active current Zact 0234 % ix_act_ex : Vertex index corresponding to active current Jact 0235 % Wact : Spatial smoothing matrix of focal window 0236 % 0237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0238 0239 % Focal window 0240 vb_disp('Lead field matrix of focal window'); 0241 0242 %MEG 0243 lf_parm.basisfile = fullfile(proj_root, bayes_parm_abs.basisfile_meg); 0244 0245 lf_parm.brainfile = bayes_parm_abs.brainfile; 0246 lf_parm.areafile = bayes_parm_abs.areafile; 0247 lf_parm.patch_norm = bayes_parm_abs.patch_norm; 0248 lf_parm.expand_spatial_filter = bayes_parm_abs.expand_spatial_filter; 0249 lf_parm.spatial_smoother = bayes_parm_abs.spatial_smoother; 0250 lf_parm.area_key = bayes_parm_abs.area_key; 0251 lf_parm.reduce = bayes_parm_abs.reduce; 0252 lf_parm.Rfilt = bayes_parm_abs.Rfilt; 0253 lf_parm.remove_area_key = []; 0254 0255 [Gact_b, ix_act, ix_act_ex, Wact, Lact] = vb_leadfield_preparation(lf_parm); 0256 0257 %EEG 0258 lf_parm.basisfile = [proj_root filesep bayes_parm_abs.basisfile_eeg]; 0259 Gact_e = vb_leadfield_preparation(lf_parm); 0260 0261 for n = 1:length(Gact_b) 0262 Gact{n} = [Gact_b{n}./Model.bsnorm_meg; Gact_e{n}./Model.bsnorm_eeg]; 0263 end 0264 0265 0266 % Extra dipole 0267 if isfield(bayes_parm_abs,'extra') & ~isempty(bayes_parm_abs.extra), 0268 vb_struct2vars(bayes_parm_abs,{'extra'}); 0269 vb_disp('Lead field matrix of extra dipoles \n'); 0270 for n=1:length(extra.basisfile) 0271 tmp = vb_load_basis(extra.basisfile{n}); 0272 Gext{n} = tmp'; 0273 end 0274 else 0275 Gext = []; 0276 end 0277 0278 % 0279 % Area index in which current is calculated 0280 % 0281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0282 if ~isempty(ix_area), 0283 % Select vertex index 'ix_area' within the active current region 0284 [jx_area_ex, ix_area_ex] = vb_index2indexsub(ix_area, ix_act_ex); 0285 else 0286 jx_area_ex = 1:length(ix_act_ex); 0287 end 0288 0289 Wact = Wact(jx_area_ex,:); 0290 jx_act = find( sum(Wact, 1) > 0); 0291 Wact = Wact(:,jx_act); 0292 0293 % active index of Z-current 0294 ix_act = ix_act(jx_act); 0295 % active index of J-current 0296 ix_act_ex = ix_act_ex(jx_area_ex); 0297 0298 % # of active vertex 0299 Njact_area = length(jx_act); 0300 0301 % # of extra dipoles 0302 if ~isempty(Gext), Njext = size(Gext{1},2); 0303 else Njext = 0; end 0304 0305 % 0306 % Constant 0307 % 0308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0309 Nsession = length(B); % Number of sessions 0310 %Ntotal = sum(Ntrials); % Total number of trials in all sessions 0311 0312 % 0313 % Temporal subsampling index 0314 % 0315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0316 sampf = MEGinfo.SampleFreq; 0317 0318 if ~isempty(dsampf), 0319 tsubsamp = ceil(1:sampf/dsampf:Tsample); 0320 Jinfo.SampleFreq = dsampf; 0321 else 0322 if isempty(tsubsamp), tsubsamp = 1:Tsample; end 0323 Jinfo.SampleFreq = sampf; 0324 end 0325 0326 Jinfo.Tmsec = Tmsec(tsubsamp); 0327 [tmp,ix] = min(abs(Tmsec(tsubsamp))); 0328 Jinfo.Pretrigger = ix; 0329 0330 % 0331 % Temporal smoothing window weight 0332 % 0333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0334 [Tweight,Tindex,Nindex,Nsample] = ... 0335 vb_overlapped_timewindow_weight(Twindow,Tsample,tsubsamp, ... 0336 overlap_mode); 0337 0338 Nwindow = length(Nindex); % # of time window 0339 Jinfo.Tix = Nindex; 0340 0341 if overlap_mode == 1, 0342 vb_disp('Non-overlapped concatenation mode\n'); 0343 end 0344 0345 % 0346 % Initialization 0347 % 0348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0349 0350 % Current averaged over trials 0351 Zact_ave = zeros(Njact_area,Nsample); 0352 Jext_ave = zeros(Njext,Nsample); 0353 0354 % 0355 % Estimated current variance 0356 % 0357 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0358 a_inv = Model.a; 0359 Cov = Model.Cov; 0360 if ~isempty(Model_ext), e_inv = Model_ext.a; 0361 else e_inv = []; end 0362 0363 % 0364 % Time window loop 0365 % 0366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0367 Ntrial_all = 0; 0368 0369 % Current Info 0370 Jinfo.version = '2.0-0.b.9'; %vbmeg('version'); 0371 Jinfo.curr_type = 'Z-current'; 0372 0373 Jinfo.tindex = tsubsamp; 0374 Jinfo.Lact = Lact; 0375 Jinfo.Wact = Wact; 0376 Jinfo.ix_act = ix_act; 0377 Jinfo.ix_act_ex = ix_act_ex; 0378 Jinfo.NJact = Njact_area; 0379 0380 % MEG time window index 0381 Tstart = bayes_parm.twin_meg(1); 0382 Tend = bayes_parm.twin_meg(2); 0383 if isempty(tsubsamp) 0384 Jinfo.Tsample = Tstart:Tend; 0385 else 0386 Jinfo.Tsample = tsubsamp + Tstart - 1; 0387 end 0388 0389 % Session loop 0390 for n=1:Nsession 0391 Ntry = size(B{n},3); 0392 Ntrials(n) = Ntry; 0393 0394 % Lead field for each session 0395 G = Gact{n}; % Ga 0396 if ~isempty(Gext), Ge = Gext{n}; else Ge = []; end 0397 Covs = Cov{n}; % Sg 0398 Nch = size(G,1); 0399 0400 %%%% Calculate Inverse filter for all time window 0401 for j=1:Nwindow 0402 Nid = Nindex{j}; % index in the total subsampled data 0403 if isempty(Nid), continue; end 0404 0405 if ~isempty(e_inv), 0406 [KW{j},KW_ext{j}] ... 0407 = vb_invfilter_z(a_inv(:,j),G,Covs,jx_act,e_inv(:,j),Ge); 0408 else 0409 [KW{j},KW_ext{j}] ... 0410 = vb_invfilter_z(a_inv(:,j),G,Covs,jx_act,[],[]); 0411 end 0412 end % Timewindow loop END 0413 0414 %%%% Current reconstruction 0415 for m=1:Ntry 0416 Zact = zeros(Njact_area,Nsample); 0417 Jext = zeros(Njext,Nsample); 0418 0419 for j=1:Nwindow 0420 % Subsampling time index 0421 Tid = Tindex{j}; % subsampled time index 0422 Nid = Nindex{j}; % index in the total subsampled data 0423 0424 if isempty(Nid), continue; end 0425 0426 %%%% Time window smoothing 0427 Bt = vb_repmultiply( B{n}(:,Tid,m) , Tweight{j}); 0428 0429 Zact(:,Nid) = Zact(:,Nid) + (KW{j} * Bt); 0430 if ~isempty(KW_ext{j}), 0431 Jext(:,Nid) = Jext(:,Nid) + (KW_ext{j} * Bt); 0432 end 0433 end % Timewindow loop END 0434 0435 % Trial average current 0436 Zact_ave = Zact_ave + Zact; 0437 Jext_ave = Jext_ave + Jext; 0438 Ntrial_all = Ntrial_all + 1; 0439 0440 fname = sprintf('data_s%04dt%04d',n,m); 0441 vb_fsave([jactdir_ab '/' fname], 'Zact','Jinfo','Jext','Pointlist', ... 0442 'MEGinfo','bayes_parm','vb_parm'); 0443 if verbose==1, 0444 fprintf('.') 0445 if rem(m, 20) == 0 % linefeed per 20 0446 fprintf('\n'); 0447 end 0448 elseif verbose==2, 0449 fprintf('progress... session:%04d/%04d, trial:%04d/%04d\n',... 0450 n,Nsession,m,Ntry); 0451 end 0452 end % Trial loop END 0453 end % Session loop END 0454 0455 Zact_ave = Zact_ave/Ntrial_all; 0456 Jext_ave = Jext_ave/Ntrial_all; 0457 0458 Jinfo.Ntrial = Ntrials; 0459 Jinfo.Nsession = Nsession; 0460 Jinfo.jactdir = jactdir; 0461 0462 % ix_act : Vertex index corresponding to active current Zact 0463 % ix_act_ex : Vertex index corresponding to active current Jact 0464 % Wact : Spatial smoothing matrix of focal window 0465 % Jact = Wact * Zact 0466 0467 % Actual time corresponding to columns of Zact, supporting overlap mode 0468 % and non-overlapped concatenation mode 0469 Tid_all = []; 0470 Nid_all = []; 0471 for j=1:Nwindow 0472 Tid_all = [Tid_all Tindex{j}]; 0473 Nid_all = [Nid_all Nindex{j}]; 0474 end 0475 0476 if overlap_mode==false, 0477 ix = unique(Tid_all); 0478 Jinfo.Tmsec = Tmsec(ix); 0479 else 0480 Jinfo.Tmsec = Tmsec(Tid_all); 0481 end 0482 0483 %Tstart = bayes_parm.twin_meg(1); 0484 %Tend = bayes_parm.twin_meg(2); 0485 %if isempty(tsubsamp) 0486 % Jinfo.Tsample = Tstart:Tend; 0487 %else 0488 % Jinfo.Tsample = tsubsamp + Tstart - 1; 0489 %end 0490 0491 if verbose==1, 0492 fprintf('\n') 0493 end 0494 0495 return; 0496 0497 %%%% --------------- 0498 function [bayes_parm,ix_area,trial_average,tsubsamp,overlap_mode,verbose,dsampf]= ... 0499 check_arg(bayes_parm,curr_parm) 0500 0501 if isfield(curr_parm,'basisfile'), 0502 bayes_parm.basisfile = curr_parm.basisfile; 0503 end; 0504 if isfield(curr_parm,'megfile'), 0505 bayes_parm.megfile = curr_parm.megfile ; 0506 end; 0507 if isfield(curr_parm,'eegfile'), 0508 bayes_parm.eegfile = curr_parm.eegfile ; 0509 end; 0510 if isfield(curr_parm,'twin_meg'), 0511 bayes_parm.twin_meg = curr_parm.twin_meg ; 0512 end; 0513 if isfield(curr_parm,'Tperiod'), 0514 bayes_parm.Tperiod = curr_parm.Tperiod ; 0515 end; 0516 if isfield(curr_parm,'Tnext'), 0517 bayes_parm.Tnext = curr_parm.Tnext ; 0518 end; 0519 0520 if ~isfield(curr_parm,'trial_average'), 0521 trial_average = ON; 0522 else 0523 trial_average = curr_parm.trial_average; 0524 end; 0525 0526 bayes_parm.trial_average = trial_average; 0527 0528 if ~isfield(curr_parm,'ix_area'), 0529 ix_area = []; 0530 else 0531 ix_area = curr_parm.ix_area; 0532 end; 0533 if ~isfield(curr_parm,'tsubsmpl'), 0534 tsubsamp = []; 0535 else 0536 tsubsamp = curr_parm.tsubsmpl; 0537 end; 0538 if ~isfield(curr_parm,'overlap_mode'), 0539 overlap_mode = 0; 0540 else 0541 overlap_mode = curr_parm.overlap_mode; 0542 end; 0543 if ~isfield(curr_parm,'verbose'), 0544 verbose = 1; 0545 else 0546 verbose = curr_parm.verbose; 0547 end; 0548 0549 if isfield(curr_parm,'extra'), 0550 if isfield(curr_parm.extra,'basisfile'), 0551 bayes_parm.extra.basisfile = curr_parm.extra.basisfile; 0552 end; 0553 end; 0554 0555 if ~isfield(curr_parm,'dsampf'), 0556 dsampf = []; 0557 else 0558 dsampf = curr_parm.dsampf; 0559 end 0560 0561 return;