Home > 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 = [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 = [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. \nSo files in this ' ...
0185              'directory are overwritten with new ones.\n'], ...
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 \n');
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.basisfile = bayes_parm_abs.basisfile;
0228 lf_parm.area_key = bayes_parm_abs.area_key;
0229 lf_parm.reduce = bayes_parm_abs.reduce;
0230 lf_parm.Rfilt = bayes_parm_abs.Rfilt;
0231 lf_parm.remove_area_key = [];
0232 
0233 [Gact, ix_act, ix_act_ex, Wact, Lact] = ...
0234     vb_leadfield_preparation(lf_parm);
0235 
0236 % Extra dipole
0237 if isfield(bayes_parm_abs,'extra') & ~isempty(bayes_parm_abs.extra), 
0238   vb_struct2vars(bayes_parm_abs,{'extra'});
0239   vb_disp('Lead field matrix of extra dipoles \n');
0240   for n=1:length(extra.basisfile)
0241     tmp = vb_load_basis(extra.basisfile{n});
0242     Gext{n} = tmp';
0243   end
0244 else
0245   Gext = [];
0246 end
0247 
0248 %
0249 % Area index in which current is calculated
0250 %
0251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0252 if ~isempty(ix_area),
0253   % Select vertex index 'ix_area' within the active current region
0254   [jx_area_ex, ix_area_ex] = vb_index2indexsub(ix_area, ix_act_ex);
0255 else
0256   jx_area_ex = 1:length(ix_act_ex);
0257 end
0258 
0259 Wact   = Wact(jx_area_ex,:);
0260 jx_act = find( sum(Wact, 1) > 0);
0261 Wact   = Wact(:,jx_act);
0262 
0263 % active index of Z-current
0264 ix_act = ix_act(jx_act);
0265 % active index of J-current
0266 ix_act_ex = ix_act_ex(jx_area_ex);
0267 
0268 % # of active vertex
0269 Njact_area = length(jx_act);
0270 
0271 % # of extra dipoles
0272 if ~isempty(Gext), Njext = size(Gext{1},2);
0273 else Njext = 0; end
0274 
0275 %
0276 % Constant
0277 %
0278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0279 Nsession = length(B);     % Number of sessions
0280 Ntotal   = sum(Ntrials); % Total number of trials in all sessions
0281 
0282 %
0283 % Temporal subsampling index
0284 %
0285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0286 sampf = MEGinfo.SampleFreq;
0287 
0288 if ~isempty(dsampf), 
0289   tsubsamp = ceil(1:sampf/dsampf:Tsample);
0290   Jinfo.SampleFreq = dsampf;
0291 elseif isempty(tsubsamp),
0292   tsubsamp = 1:Tsample;
0293   Jinfo.SampleFreq = sampf;
0294 end
0295 
0296 Jinfo.Tmsec = Tmsec(tsubsamp);
0297 [tmp,ix] = min(abs(Tmsec(tsubsamp)));
0298 Jinfo.Pretrigger = ix;
0299 
0300 %
0301 % Temporal smoothing window weight
0302 %
0303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0304 [Tweight,Tindex,Nindex,Nsample] = ...
0305     vb_overlapped_timewindow_weight(Twindow,Tsample,tsubsamp, ...
0306                                     overlap_mode);
0307 
0308 Nwindow   = length(Nindex); % # of time window
0309 Jinfo.Tix = Nindex;
0310 
0311 if overlap_mode == 1,
0312   vb_disp('Non-overlapped concatenation mode\n'); 
0313 end
0314 
0315 %
0316 % Initialization
0317 %
0318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0319 
0320 % Current averaged over trials
0321 Zact_ave = zeros(Njact_area,Nsample);
0322 Jext_ave = zeros(Njext,Nsample);
0323 
0324 %
0325 % Estimated current variance
0326 %
0327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0328 a_inv = Model.a;
0329 Cov = Model.Cov;
0330 if ~isempty(Model_ext), e_inv = Model_ext.a;
0331 else e_inv = []; end
0332 
0333 %
0334 % Time window loop
0335 %
0336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0337 Ntrial_all = 0;
0338 
0339 % Current Info
0340 Jinfo.version   = '1.0-0.a.5'; %vbmeg('version');
0341 Jinfo.curr_type = 'Z-current';
0342 
0343 Jinfo.tindex    = tsubsamp;
0344 Jinfo.Lact      = Lact;
0345 Jinfo.Wact      = Wact;
0346 Jinfo.ix_act    = ix_act;
0347 Jinfo.ix_act_ex = ix_act_ex;
0348 Jinfo.NJact     = Njact_area;
0349 
0350 % MEG time window index
0351 Tstart  = bayes_parm.twin_meg(1);
0352 Tend    = bayes_parm.twin_meg(2);
0353 if isempty(tsubsamp)
0354   Jinfo.Tsample = Tstart:Tend;
0355 else
0356   Jinfo.Tsample = tsubsamp + Tstart - 1;
0357 end
0358 
0359 % Session loop
0360 for n=1:Nsession
0361   Ntry = size(B{n},3);
0362   Ntrials(n) = Ntry;
0363     
0364   % Lead field for each session
0365   G     = Gact{n};   % Ga
0366   if ~isempty(Gext), Ge = Gext{n}; else Ge = []; end
0367   Covs = Cov{n};     % Sg
0368   Nch     = size(G,1);
0369     
0370   %%%% Calculate Inverse filter for all time window
0371   for j=1:Nwindow
0372     Nid = Nindex{j};    % index in the total subsampled data
0373     if isempty(Nid), continue; end
0374 
0375     if ~isempty(e_inv), 
0376       [KW{j},KW_ext{j}] ...
0377           = vb_invfilter_z(a_inv(:,j),G,Covs,jx_act,e_inv(:,j),Ge);
0378     else
0379       [KW{j},KW_ext{j}] ...
0380           = vb_invfilter_z(a_inv(:,j),G,Covs,jx_act,[],[]);
0381     end
0382   end % Timewindow loop END
0383     
0384   %%%% Current reconstruction
0385   for m=1:Ntry
0386     Zact = zeros(Njact_area,Nsample);
0387     Jext = zeros(Njext,Nsample);
0388         
0389     for j=1:Nwindow
0390       % Subsampling time index
0391       Tid = Tindex{j};    % subsampled time index
0392       Nid = Nindex{j};    % index in the total subsampled data
0393             
0394       if isempty(Nid), continue; end
0395             
0396       %%%% Time window smoothing
0397       Bt = vb_repmultiply( B{n}(:,Tid,m) , Tweight{j});
0398             
0399       Zact(:,Nid) = Zact(:,Nid) + (KW{j} * Bt);
0400       if ~isempty(KW_ext{j}),
0401         Jext(:,Nid) = Jext(:,Nid) + (KW_ext{j} * Bt);
0402       end
0403     end % Timewindow loop END
0404         
0405     % Trial average current
0406     Zact_ave   = Zact_ave + Zact;
0407     Jext_ave   = Jext_ave + Jext;
0408     Ntrial_all = Ntrial_all + 1;
0409         
0410     fname = sprintf('data_s%04dt%04d',n,m);
0411     vb_fsave([jactdir_ab '/' fname], 'Zact','Jinfo','Jext','Pointlist', ...
0412              'MEGinfo','bayes_parm','vb_parm');
0413     if verbose==1,
0414       fprintf('.')
0415       if rem(m, 20) == 0 % linefeed per 20
0416         fprintf('\n');
0417       end
0418     elseif verbose==2,
0419       fprintf('progress... session:%04d/%04d, trial:%04d/%04d\n',...
0420               n,Nsession,m,Ntry);
0421     end
0422   end % Trial loop END
0423 end % Session loop END
0424 
0425 Zact_ave = Zact_ave/Ntrial_all;
0426 Jext_ave = Jext_ave/Ntrial_all;
0427 
0428 Jinfo.Ntrial   = Ntrials;
0429 Jinfo.Nsession = Nsession;
0430 Jinfo.jactdir  = jactdir;
0431 
0432 % ix_act : Vertex index corresponding to active current Zact
0433 % ix_act_ex : Vertex index corresponding to active current Jact
0434 % Wact   : Spatial smoothing matrix of focal window
0435 % Jact   = Wact * Zact
0436 
0437 % Actual time corresponding to columns of Zact, supporting overlap mode
0438 % and non-overlapped concatenation mode
0439 Tid_all = [];
0440 Nid_all = [];
0441 for j=1:Nwindow
0442   Tid_all = [Tid_all Tindex{j}];
0443   Nid_all = [Nid_all Nindex{j}];
0444 end
0445 
0446 if overlap_mode==false,
0447   ix          = unique(Tid_all);
0448   Jinfo.Tmsec = Tmsec(ix);
0449 else
0450   Jinfo.Tmsec = Tmsec(Tid_all);
0451 end
0452 
0453 %Tstart  = bayes_parm.twin_meg(1);
0454 %Tend    = bayes_parm.twin_meg(2);
0455 %if isempty(tsubsamp)
0456 %  Jinfo.Tsample = Tstart:Tend;
0457 %else
0458 %  Jinfo.Tsample = tsubsamp + Tstart - 1;
0459 %end
0460 
0461 if verbose==1,
0462   fprintf('\n')
0463 end
0464 
0465 return;
0466 
0467 %%%% ---------------
0468 function [bayes_parm,ix_area,trial_average,tsubsamp,overlap_mode,verbose,dsampf]= ...
0469     check_arg(bayes_parm,curr_parm)
0470 
0471 if isfield(curr_parm,'basisfile'), 
0472   bayes_parm.basisfile = curr_parm.basisfile;
0473 end;
0474 if isfield(curr_parm,'megfile'), 
0475   bayes_parm.megfile   = curr_parm.megfile  ;
0476 end;
0477 if isfield(curr_parm,'twin_meg'), 
0478   bayes_parm.twin_meg  = curr_parm.twin_meg ;
0479 end;
0480 if isfield(curr_parm,'Tperiod'), 
0481   bayes_parm.Tperiod   = curr_parm.Tperiod  ;
0482 end;
0483 if isfield(curr_parm,'Tnext'), 
0484   bayes_parm.Tnext     = curr_parm.Tnext    ;
0485 end;
0486 
0487 if ~isfield(curr_parm,'trial_average'), 
0488   trial_average = ON; 
0489 else
0490   trial_average = curr_parm.trial_average; 
0491 end;
0492 
0493 bayes_parm.trial_average = trial_average;
0494 
0495 if ~isfield(curr_parm,'ix_area'),  
0496   ix_area = []; 
0497 else
0498   ix_area = curr_parm.ix_area; 
0499 end;
0500 if ~isfield(curr_parm,'tsubsmpl'), 
0501   tsubsamp = []; 
0502 else
0503   tsubsamp = curr_parm.tsubsmpl; 
0504 end;
0505 if ~isfield(curr_parm,'overlap_mode'),     
0506   overlap_mode = 0; 
0507 else
0508   overlap_mode = curr_parm.overlap_mode; 
0509 end;
0510 if ~isfield(curr_parm,'verbose'),     
0511   verbose = 1; 
0512 else
0513   verbose = curr_parm.verbose; 
0514 end;
0515 
0516 if isfield(curr_parm,'extra'),
0517   if isfield(curr_parm.extra,'basisfile'), 
0518     bayes_parm.extra.basisfile = curr_parm.extra.basisfile;
0519   end;
0520 end;
0521 
0522 if ~isfield(curr_parm,'dsampf'), 
0523   dsampf = [];
0524 else
0525   dsampf = curr_parm.dsampf;
0526 end
0527 
0528 return;

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005