Home > vbmeg > functions > job > vb_job_trial_onset.m

vb_job_trial_onset

PURPOSE ^

get time index for each trial by checking status channel

SYNOPSIS ^

function vb_job_trial_onset(varargin)

DESCRIPTION ^

 get time index for each trial by checking status channel
 --- Usage
    vb_job_trial_onset(parm)
    vb_job_trial_onset(proj_root,parm)    [old style]
 --- Input
  parm.data_file : Data file name         [string]
  parm.trig_file : Trial onset file name  [string]
  parm.status_ch : status channel name    [string]
  parm.trig_type = 'integer' or 'analog' or 'voice' or 'emg'
  parm.slope = 'const_start' or 'const_end'    if trig_type = 'integer'
               'low_to_high' or 'high_to_low'  if trig_type = 'analog'
               No meaning                      if trig_type = 'voice','emg'
  parm.condition : string describing condition [string or cell array]
  parm.status_level : status level      [1 x Ncomdition]
  parm.Pretrigger_ms : Pretrigger period   [msec]
  parm.Posttrigger_ms: Posttrigger period  [msec]
 --- Save variables
 status : status signal
 status_out = (smoothed) status signal used for onset search
 status_val(m) = status value for m-th condition (m=1:Ncomdition)
 trig(n)       : Onset time index for n-th trial 
 cond_id(n)    : Condition ID for n-th trial 
 ix_trial(:,n) : Time index for n-th trial   [Tperiod x Ntrial]
                 Tperiod : # of time sample in one trial
                 Ntrial  : # of trials
 parm : parameter setting
 parm.fsamp : Sample Frequency [Hz]

 --- Optional parameter for EMG onset
 parm.t_event  : minimum distance from previous onset event [150 ms]
                 distance from previous onset should be larger than t_event
 parm.p_val : P-value corresponding to the threshold for [EMG, smooth(EMG)] 
               [0.0001, 0.0005] or [0.0001, 0.001] 
     cumulative histgram is used to determine threshold from P-value

 --- Usually following parameters need not be changed
 parm.hist_mode : histgram mode [1]
                = 1: Estimate threshold by gamma distribution approximation
                = 0: Estimate threshold by histgram
 parm.t_smooth : moving average window length               [25 ms]
 parm.t_slope  : slope estimation period near onset         [25 ms]
                 if t_slope==0, zero cross point is not calculated
 parm.t_peak   : peak evaluation period                     [100 ms]
 peak_val : EMG value should exceed peak_val within 't_peak' after onset
          = mean(peak value > threshold) if hist_mode = 1
          = (max(y) * status_level)      if hist_mode = 0 or 2
 --- Condition for EMG onset
 1. distance from previous onset should be larger than t_event
 2. distance between EMG & smoothed EMG onset should be smaller than t_event
 3. EMG value should exceed peak_val within t_peak after onset
 4. zero cross point is estimated 
    by linear fitting around smoothed EMG threshold point


 2009-6-14  Masa-aki Sato

 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:

SOURCE CODE ^

0001 function    vb_job_trial_onset(varargin)
0002 % get time index for each trial by checking status channel
0003 % --- Usage
0004 %    vb_job_trial_onset(parm)
0005 %    vb_job_trial_onset(proj_root,parm)    [old style]
0006 % --- Input
0007 %  parm.data_file : Data file name         [string]
0008 %  parm.trig_file : Trial onset file name  [string]
0009 %  parm.status_ch : status channel name    [string]
0010 %  parm.trig_type = 'integer' or 'analog' or 'voice' or 'emg'
0011 %  parm.slope = 'const_start' or 'const_end'    if trig_type = 'integer'
0012 %               'low_to_high' or 'high_to_low'  if trig_type = 'analog'
0013 %               No meaning                      if trig_type = 'voice','emg'
0014 %  parm.condition : string describing condition [string or cell array]
0015 %  parm.status_level : status level      [1 x Ncomdition]
0016 %  parm.Pretrigger_ms : Pretrigger period   [msec]
0017 %  parm.Posttrigger_ms: Posttrigger period  [msec]
0018 % --- Save variables
0019 % status : status signal
0020 % status_out = (smoothed) status signal used for onset search
0021 % status_val(m) = status value for m-th condition (m=1:Ncomdition)
0022 % trig(n)       : Onset time index for n-th trial
0023 % cond_id(n)    : Condition ID for n-th trial
0024 % ix_trial(:,n) : Time index for n-th trial   [Tperiod x Ntrial]
0025 %                 Tperiod : # of time sample in one trial
0026 %                 Ntrial  : # of trials
0027 % parm : parameter setting
0028 % parm.fsamp : Sample Frequency [Hz]
0029 %
0030 % --- Optional parameter for EMG onset
0031 % parm.t_event  : minimum distance from previous onset event [150 ms]
0032 %                 distance from previous onset should be larger than t_event
0033 % parm.p_val : P-value corresponding to the threshold for [EMG, smooth(EMG)]
0034 %               [0.0001, 0.0005] or [0.0001, 0.001]
0035 %     cumulative histgram is used to determine threshold from P-value
0036 %
0037 % --- Usually following parameters need not be changed
0038 % parm.hist_mode : histgram mode [1]
0039 %                = 1: Estimate threshold by gamma distribution approximation
0040 %                = 0: Estimate threshold by histgram
0041 % parm.t_smooth : moving average window length               [25 ms]
0042 % parm.t_slope  : slope estimation period near onset         [25 ms]
0043 %                 if t_slope==0, zero cross point is not calculated
0044 % parm.t_peak   : peak evaluation period                     [100 ms]
0045 % peak_val : EMG value should exceed peak_val within 't_peak' after onset
0046 %          = mean(peak value > threshold) if hist_mode = 1
0047 %          = (max(y) * status_level)      if hist_mode = 0 or 2
0048 % --- Condition for EMG onset
0049 % 1. distance from previous onset should be larger than t_event
0050 % 2. distance between EMG & smoothed EMG onset should be smaller than t_event
0051 % 3. EMG value should exceed peak_val within t_peak after onset
0052 % 4. zero cross point is estimated
0053 %    by linear fitting around smoothed EMG threshold point
0054 %
0055 %
0056 % 2009-6-14  Masa-aki Sato
0057 %
0058 % Copyright (C) 2011, ATR All Rights Reserved.
0059 % License : New BSD License(see VBMEG_LICENSE.txt)
0060 
0061 if length(varargin) == 1
0062   proj_root = [];
0063   parm = varargin{1};
0064 elseif length(varargin) == 2
0065   proj_root = varargin{1};
0066   parm = varargin{2};
0067 end
0068 
0069 proj_root = vb_rm_trailing_slash(proj_root);
0070 
0071 % Original data file
0072 fname = fullfile(proj_root, parm.data_file);
0073 ftrig = fullfile(proj_root, parm.trig_file);
0074 
0075 % Load info
0076 info = vb_load_meg_info(fname);
0077 % Sample Frequency [Hz]
0078 parm.fsamp  = info.SampleFreq;
0079 
0080 if iscell(parm.status_ch),
0081     status_ch = parm.status_ch;
0082 else
0083     status_ch = {parm.status_ch};
0084 end
0085 
0086 % Load status channel
0087 loadspec = [];
0088 loadspec.ChannelName = status_ch;
0089 status = vb_load_meg_data(fname, loadspec);
0090 
0091 [ix_trial, trig, cond_id, status_val,status_out] = ...
0092         vb_get_trial_time_index(status,parm);
0093 
0094 if isempty(ix_trial), return; end;
0095 
0096 % ix_trial(:,n) : Time index for n-th trial   [Tperiod x Ntrial]
0097 tmin = min(ix_trial,[],1);
0098 tmax = max(ix_trial,[],1);
0099 
0100 % check time is inside the data
0101 ix = find( (tmin > 0) & (tmax <= info.Nsample));
0102 
0103 trig     = trig(ix);
0104 ix_trial = ix_trial(:,ix);
0105 cond_id  = cond_id(ix);
0106 
0107 vb_fsave(ftrig,'ix_trial','trig','status','status_out','status_val','cond_id','parm');

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