Home > vbmeg > functions > estimation > bayes > vbmeg_current_reconstruct_z_tr.m

vbmeg_current_reconstruct_z_tr

PURPOSE ^

Current reconstruction using Bayesian inverse filter.

SYNOPSIS ^

function [Zact_ave,Jinfo,bayes_parm,vb_parm,MEGinfo,Jext_ave,Pointlist]= vb_current_reconstruct_z_tr(proj_root,curr_parm);

DESCRIPTION ^

 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.

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [Zact_ave,Jinfo,bayes_parm,vb_parm,MEGinfo,Jext_ave,Pointlist] ...
0002     = vb_current_reconstruct_z_tr(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 %
0115 % Copyright (C) 2011, ATR All Rights Reserved.
0116 % License : New BSD License(see VBMEG_LICENSE.txt)
0117 
0118 if ~isempty(proj_root)
0119   bayesfile = [proj_root filesep curr_parm.bayesfile];
0120 else
0121   bayesfile = curr_parm.bayesfile;
0122 end
0123 
0124 %
0125 % Verbose level setting
0126 % (note: 'verbose_level' is not related to input variable
0127 % 'curr_parm.verbose'. So two configurations relating to message display
0128 % are coexisting in this function.)
0129 %
0130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0131 global vbmeg_inst
0132 verbose_const = vb_define_verbose; 
0133 
0134 if isempty(vbmeg_inst) | ~isfield(vbmeg_inst,'verbose_level'), 
0135   verbose_level = verbose_const.VERBOSE_LEVEL_NOTICE;
0136 else
0137   verbose_level = vbmeg_inst.verbose_level;
0138 end
0139 
0140 %
0141 % load VBMEG estimated result
0142 %
0143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0144 load(bayesfile, 'bayes_parm','Model','vb_parm','Model_ext','Pointlist');
0145 
0146 %
0147 % check parameter of 'curr_parm'
0148 %
0149 % Values of 'curr_parm' fields dominates over
0150 %   those of 'bayes_parm' in bayesfile
0151 %
0152 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0153 [bayes_parm,ix_area,trial_average,tsubsamp,overlap_mode,verbose,dsampf] ...
0154     = check_arg(bayes_parm,curr_parm);
0155             
0156 if ~isempty(proj_root);
0157   bayes_parm_abs = vb_parm_absolute_path(proj_root, bayes_parm);
0158 else
0159   bayes_parm_abs = bayes_parm;
0160 end
0161 
0162 % current file directory
0163 if ~isempty(proj_root)
0164   currfile = fullfile(proj_root, curr_parm.currfile);
0165 else
0166   currfile = [curr_parm.currfile];
0167 end 
0168 
0169 % jactdir is relative path from current file
0170 jactdir   = curr_parm.jactdir;
0171 curr_root  = fileparts(currfile);
0172 jactdir_ab = fullfile(curr_root, jactdir);
0173 
0174 %check directory
0175 if exist(jactdir_ab,'dir') ~= 0
0176   if verbose_level>=verbose_const.VERBOSE_LEVEL_NOTICE, 
0177     msg = [ 'jact_dir : ' jactdir_ab ' exists. Do you over write?'];
0178     btn = questdlg(msg, 'confirm', 'Yes', 'No', 'Yes');
0179     if strcmp(btn, 'No')
0180       error('processing aborted.');
0181       return;
0182     end
0183   else
0184     vb_disp(['jact_dir : ' jactdir_ab ' exists. So files in this ' ...
0185              'directory are overwritten with new ones.'], ...
0186             verbose_const.VERBOSE_LEVEL_WARNING);
0187   end
0188 else
0189   res = mkdir(curr_root, jactdir);
0190   if  res~= 1,  error('mkdir failed.'); end
0191 end
0192 
0193 % Trial indices
0194 if isfield(bayes_parm_abs,'ix_trial'), 
0195   bayes_parm_abs.ix_trial = bayes_parm_abs.ix_trial;
0196 elseif isfield(curr_parm,'ix_trial'), 
0197   bayes_parm_abs.ix_trial = curr_parm.ix_trial;
0198 else
0199   bayes_parm_abs.ix_trial = [];
0200 end
0201 
0202 %
0203 % MEG data preparation
0204 % B      : MEG data
0205 %
0206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0207 [B,Ntrials,Nch,Tsample,Twindow,Tmsec] ...
0208     = vb_megdata_preparation(bayes_parm_abs);
0209 MEGinfo = vb_load_meg_info(bayes_parm_abs.megfile{1});
0210 
0211 %
0212 % Preparation of lead fields
0213 % Gact   : leadfield of focal window
0214 % ix_act : Vertex index corresponding to active current Zact
0215 % ix_act_ex : Vertex index corresponding to active current Jact
0216 % Wact   : Spatial smoothing matrix of focal window
0217 %
0218 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0219 
0220 % Focal window
0221 vb_disp('Lead field matrix of focal window');
0222 
0223 lf_parm.brainfile = bayes_parm_abs.brainfile;
0224 lf_parm.areafile = bayes_parm_abs.areafile;
0225 lf_parm.patch_norm = bayes_parm_abs.patch_norm;
0226 lf_parm.expand_spatial_filter = bayes_parm_abs.expand_spatial_filter;
0227 lf_parm.spatial_smoother = bayes_parm_abs.spatial_smoother;
0228 lf_parm.basisfile = bayes_parm_abs.basisfile;
0229 lf_parm.area_key = bayes_parm_abs.area_key;
0230 lf_parm.reduce = bayes_parm_abs.reduce;
0231 lf_parm.Rfilt = bayes_parm_abs.Rfilt;
0232 lf_parm.remove_area_key = [];
0233 
0234 [Gact, ix_act, ix_act_ex, Wact, Lact] = ...
0235     vb_leadfield_preparation(lf_parm);
0236 
0237 % Extra dipole
0238 if isfield(bayes_parm_abs,'extra') & ~isempty(bayes_parm_abs.extra), 
0239   vb_struct2vars(bayes_parm_abs,{'extra'});
0240   vb_disp('Lead field matrix of extra dipoles');
0241   for n=1:length(extra.basisfile)
0242     tmp = vb_load_basis(extra.basisfile{n});
0243     Gext{n} = tmp';
0244   end
0245 else
0246   Gext = [];
0247 end
0248 
0249 %
0250 % Area index in which current is calculated
0251 %
0252 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0253 if ~isempty(ix_area),
0254   % Select vertex index 'ix_area' within the active current region
0255   [jx_area_ex, ix_area_ex] = vb_index2indexsub(ix_area, ix_act_ex);
0256 else
0257   jx_area_ex = 1:length(ix_act_ex);
0258 end
0259 
0260 Wact   = Wact(jx_area_ex,:);
0261 jx_act = find( sum(Wact, 1) > 0);
0262 Wact   = Wact(:,jx_act);
0263 
0264 % active index of Z-current
0265 ix_act = ix_act(jx_act);
0266 % active index of J-current
0267 ix_act_ex = ix_act_ex(jx_area_ex);
0268 
0269 % # of active vertex
0270 Njact_area = length(jx_act);
0271 
0272 % # of extra dipoles
0273 if ~isempty(Gext), Njext = size(Gext{1},2);
0274 else Njext = 0; end
0275 
0276 %
0277 % Constant
0278 %
0279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0280 Nsession = length(B);     % Number of sessions
0281 Ntotal   = sum(Ntrials); % Total number of trials in all sessions
0282 
0283 %
0284 % Temporal subsampling index
0285 %
0286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0287 sampf = MEGinfo.SampleFreq;
0288 
0289 if ~isempty(dsampf), 
0290   tsubsamp = ceil(1:sampf/dsampf:Tsample);
0291   Jinfo.SampleFreq = dsampf;
0292 elseif isempty(tsubsamp),
0293   tsubsamp = 1:Tsample;
0294   Jinfo.SampleFreq = sampf;
0295 end
0296 
0297 Jinfo.Tmsec = Tmsec(tsubsamp);
0298 [tmp,ix] = min(abs(Tmsec(tsubsamp)));
0299 Jinfo.Pretrigger = ix;
0300 
0301 %
0302 % Temporal smoothing window weight
0303 %
0304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0305 [Tweight,Tindex,Nindex,Nsample] = ...
0306     vb_overlapped_timewindow_weight(Twindow,Tsample,tsubsamp, ...
0307                                     overlap_mode);
0308 
0309 Nwindow   = length(Nindex); % # of time window
0310 Jinfo.Tix = Nindex;
0311 
0312 if overlap_mode == 1,
0313   vb_disp('Non-overlapped concatenation mode'); 
0314 end
0315 
0316 %
0317 % Initialization
0318 %
0319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0320 
0321 % Current averaged over trials
0322 Zact_ave = zeros(Njact_area,Nsample);
0323 Jext_ave = zeros(Njext,Nsample);
0324 
0325 %
0326 % Estimated current variance
0327 %
0328 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0329 a_inv = Model.a;
0330 Cov = Model.Cov;
0331 if ~isempty(Model_ext), e_inv = Model_ext.a;
0332 else e_inv = []; end
0333 
0334 %
0335 % Time window loop
0336 %
0337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0338 Ntrial_all = 0;
0339 
0340 % Current Info
0341 Jinfo.version   = '2.0-0.b.9'; %vbmeg('version');
0342 Jinfo.curr_type = 'Z-current';
0343 
0344 Jinfo.tindex    = tsubsamp;
0345 Jinfo.Lact      = Lact;
0346 Jinfo.Wact      = Wact;
0347 Jinfo.ix_act    = ix_act;
0348 Jinfo.ix_act_ex = ix_act_ex;
0349 Jinfo.NJact     = Njact_area;
0350 
0351 % MEG time window index
0352 Tstart  = bayes_parm.twin_meg(1);
0353 Tend    = bayes_parm.twin_meg(2);
0354 if isempty(tsubsamp)
0355   Jinfo.Tsample = Tstart:Tend;
0356 else
0357   Jinfo.Tsample = tsubsamp + Tstart - 1;
0358 end
0359 
0360 % Session loop
0361 for n=1:Nsession
0362   Ntry = size(B{n},3);
0363   Ntrials(n) = Ntry;
0364     
0365   % Lead field for each session
0366   G     = Gact{n};   % Ga
0367   if ~isempty(Gext), Ge = Gext{n}; else Ge = []; end
0368   Covs = Cov{n};     % Sg
0369   Nch     = size(G,1);
0370     
0371   %%%% Calculate Inverse filter for all time window
0372   for j=1:Nwindow
0373     Nid = Nindex{j};    % index in the total subsampled data
0374     if isempty(Nid), continue; end
0375 
0376     if ~isempty(e_inv), 
0377       [KW{j},KW_ext{j}] ...
0378           = vb_invfilter_z(a_inv(:,j),G,Covs,jx_act,e_inv(:,j),Ge);
0379     else
0380       [KW{j},KW_ext{j}] ...
0381           = vb_invfilter_z(a_inv(:,j),G,Covs,jx_act,[],[]);
0382     end
0383   end % Timewindow loop END
0384     
0385   %%%% Current reconstruction
0386   for m=1:Ntry
0387     Zact = zeros(Njact_area,Nsample);
0388     Jext = zeros(Njext,Nsample);
0389         
0390     for j=1:Nwindow
0391       % Subsampling time index
0392       Tid = Tindex{j};    % subsampled time index
0393       Nid = Nindex{j};    % index in the total subsampled data
0394             
0395       if isempty(Nid), continue; end
0396             
0397       %%%% Time window smoothing
0398       Bt = vb_repmultiply( B{n}(:,Tid,m) , Tweight{j});
0399             
0400       Zact(:,Nid) = Zact(:,Nid) + (KW{j} * Bt);
0401       if ~isempty(KW_ext{j}),
0402         Jext(:,Nid) = Jext(:,Nid) + (KW_ext{j} * Bt);
0403       end
0404     end % Timewindow loop END
0405         
0406     % Trial average current
0407     Zact_ave   = Zact_ave + Zact;
0408     Jext_ave   = Jext_ave + Jext;
0409     Ntrial_all = Ntrial_all + 1;
0410         
0411     fname = sprintf('data_s%04dt%04d',n,m);
0412     vb_fsave([jactdir_ab '/' fname], 'Zact','Jinfo','Jext','Pointlist', ...
0413              'MEGinfo','bayes_parm','vb_parm');
0414     if verbose==1,
0415       fprintf('.')
0416       if rem(m, 20) == 0 % linefeed per 20
0417         fprintf('\n');
0418       end
0419     elseif verbose==2,
0420       fprintf('progress... session:%04d/%04d, trial:%04d/%04d\n',...
0421               n,Nsession,m,Ntry);
0422     end
0423   end % Trial loop END
0424 end % Session loop END
0425 
0426 Zact_ave = Zact_ave/Ntrial_all;
0427 Jext_ave = Jext_ave/Ntrial_all;
0428 
0429 Jinfo.Ntrial   = Ntrials;
0430 Jinfo.Nsession = Nsession;
0431 Jinfo.jactdir  = jactdir;
0432 
0433 % ix_act : Vertex index corresponding to active current Zact
0434 % ix_act_ex : Vertex index corresponding to active current Jact
0435 % Wact   : Spatial smoothing matrix of focal window
0436 % Jact   = Wact * Zact
0437 
0438 % Actual time corresponding to columns of Zact, supporting overlap mode
0439 % and non-overlapped concatenation mode
0440 Tid_all = [];
0441 Nid_all = [];
0442 for j=1:Nwindow
0443   Tid_all = [Tid_all Tindex{j}];
0444   Nid_all = [Nid_all Nindex{j}];
0445 end
0446 
0447 if overlap_mode==false,
0448   ix          = unique(Tid_all);
0449   Jinfo.Tmsec = Tmsec(ix);
0450 else
0451   Jinfo.Tmsec = Tmsec(Tid_all);
0452 end
0453 
0454 %Tstart  = bayes_parm.twin_meg(1);
0455 %Tend    = bayes_parm.twin_meg(2);
0456 %if isempty(tsubsamp)
0457 %  Jinfo.Tsample = Tstart:Tend;
0458 %else
0459 %  Jinfo.Tsample = tsubsamp + Tstart - 1;
0460 %end
0461 
0462 if verbose==1,
0463   fprintf('\n')
0464 end
0465 
0466 return;
0467 
0468 %%%% ---------------
0469 function [bayes_parm,ix_area,trial_average,tsubsamp,overlap_mode,verbose,dsampf]= ...
0470     check_arg(bayes_parm,curr_parm)
0471 
0472 if isfield(curr_parm,'basisfile'), 
0473   bayes_parm.basisfile = curr_parm.basisfile;
0474 end;
0475 if isfield(curr_parm,'megfile'), 
0476   bayes_parm.megfile   = curr_parm.megfile  ;
0477 end;
0478 if isfield(curr_parm,'twin_meg'), 
0479   bayes_parm.twin_meg  = curr_parm.twin_meg ;
0480 end;
0481 if isfield(curr_parm,'Tperiod'), 
0482   bayes_parm.Tperiod   = curr_parm.Tperiod  ;
0483 end;
0484 if isfield(curr_parm,'Tnext'), 
0485   bayes_parm.Tnext     = curr_parm.Tnext    ;
0486 end;
0487 
0488 if ~isfield(curr_parm,'trial_average'), 
0489   trial_average = ON; 
0490 else
0491   trial_average = curr_parm.trial_average; 
0492 end;
0493 
0494 bayes_parm.trial_average = trial_average;
0495 
0496 if ~isfield(curr_parm,'ix_area'),  
0497   ix_area = []; 
0498 else
0499   ix_area = curr_parm.ix_area; 
0500 end;
0501 if ~isfield(curr_parm,'tsubsmpl'), 
0502   tsubsamp = []; 
0503 else
0504   tsubsamp = curr_parm.tsubsmpl; 
0505 end;
0506 if ~isfield(curr_parm,'overlap_mode'),     
0507   overlap_mode = 0; 
0508 else
0509   overlap_mode = curr_parm.overlap_mode; 
0510 end;
0511 if ~isfield(curr_parm,'verbose'),     
0512   verbose = 1; 
0513 else
0514   verbose = curr_parm.verbose; 
0515 end;
0516 
0517 if isfield(curr_parm,'extra'),
0518   if isfield(curr_parm.extra,'basisfile'), 
0519     bayes_parm.extra.basisfile = curr_parm.extra.basisfile;
0520   end;
0521 end;
0522 
0523 if ~isfield(curr_parm,'dsampf'), 
0524   dsampf = [];
0525 else
0526   dsampf = curr_parm.dsampf;
0527 end
0528 
0529 return;

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005