Home > vbmeg > demo > test_scripts > vb_test_job_trial_onset.m

vb_test_job_trial_onset

PURPOSE ^

get time index for each trial by checking status channel

SYNOPSIS ^

function vb_test_job_trial_onset(fname, parm)

DESCRIPTION ^

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

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