Home > functions > device > trigger_timing > vb_get_time_index_from_onset.m

vb_get_time_index_from_onset

PURPOSE ^

get trial time index from status channel

SYNOPSIS ^

function [ix_trial,trig,cond_id,status_val,status_out] =vb_get_time_index_from_onset(trig,parm)

DESCRIPTION ^

 get trial time index from status channel

    [ix_trial,trig,cond_id,status_val,status_out] = ...
          vb_get_time_index_from_onset(trig,parm)
 --- Inout
  trig(n)       : Onset time index for n-th trial 
  parm.Pretrigger_ms : Pretrigger period   [msec]
  parm.Posttrigger_ms: Posttrigger period  [msec]
  parm.status_level : status level (ratio for max) for onset [Ncondition x 1]
  parm.fsamp     : Sample Frequency [Hz]
 --- Output
 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
 status_val(m) = parm.status_level(m) * max(status)
 status_out : masked status signal if mask flag is specified

 2009-6-11 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    [ix_trial,trig,cond_id,status_val,status_out] = ...
0002             vb_get_time_index_from_onset(trig,parm)
0003 % get trial time index from status channel
0004 %
0005 %    [ix_trial,trig,cond_id,status_val,status_out] = ...
0006 %          vb_get_time_index_from_onset(trig,parm)
0007 % --- Inout
0008 %  trig(n)       : Onset time index for n-th trial
0009 %  parm.Pretrigger_ms : Pretrigger period   [msec]
0010 %  parm.Posttrigger_ms: Posttrigger period  [msec]
0011 %  parm.status_level : status level (ratio for max) for onset [Ncondition x 1]
0012 %  parm.fsamp     : Sample Frequency [Hz]
0013 % --- Output
0014 % trig(n)       : Onset time index for n-th trial
0015 % cond_id(n)    : Condition ID for n-th trial
0016 % ix_trial(:,n) : Time index for n-th trial   [Tperiod x Ntrial]
0017 %                 Tperiod : # of time sample in one trial
0018 %                 Ntrial  : # of trials
0019 % status_val(m) = parm.status_level(m) * max(status)
0020 % status_out : masked status signal if mask flag is specified
0021 %
0022 % 2009-6-11 Masa-aki Sato
0023 %
0024 % Copyright (C) 2011, ATR All Rights Reserved.
0025 % License : New BSD License(see VBMEG_LICENSE.txt)
0026 
0027 % Pre/Post period in msec
0028 Pretrigger_ms  = parm.Pretrigger_ms ; % [msec]
0029 Posttrigger_ms = parm.Posttrigger_ms; % [msec]
0030 
0031 % Sample Frequency [Hz]
0032 fsamp  = parm.fsamp;
0033 %fprintf('Sampleing Frequency: %6.1f [Hz]\n',fsamp)
0034 
0035 % Sample number for Pre/Post period
0036 Pretrigger  = ceil(Pretrigger_ms *(fsamp/1000));
0037 Posttrigger = ceil(Posttrigger_ms*(fsamp/1000));
0038 
0039 status_level  = parm.status_level ;
0040 status_val = status_level;
0041 status_out = status_level;
0042 
0043 Ntrial = length(trig);
0044 cond_id = ones(Ntrial,1);
0045 
0046 % trig(n) : n-th triger time
0047 % cond_id(n) : corresponding condition label
0048 
0049 %--- sort triger timing according to temporal order
0050 [trig, jx] = sort(trig);
0051 
0052 % Time index for one trial
0053 ix = (-Pretrigger:Posttrigger)';
0054 Tp = length(ix);
0055 
0056 % Time index for all trials extracted from 'trig'
0057 trig = round(trig);
0058 ix_trial = repmat(ix,[1 Ntrial]) + repmat(trig,[Tp 1]);
0059

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