


get time index for each trial by checking status channel
--- Usage
vb_job_trial_onset(proj_root,parm)
--- 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)

0001 function vb_job_trial_onset(proj_root,parm) 0002 % get time index for each trial by checking status channel 0003 % --- Usage 0004 % vb_job_trial_onset(proj_root,parm) 0005 % --- Input 0006 % parm.data_file : 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 proj_root = vb_rm_trailing_slash(proj_root); 0061 0062 % Original data file 0063 fname = [proj_root filesep parm.data_file ]; 0064 ftrig = [proj_root filesep parm.trig_file ]; 0065 0066 % Load info 0067 info = vb_load_meg_info(fname); 0068 % Sample Frequency [Hz] 0069 parm.fsamp = info.SampleFreq; 0070 0071 if iscell(parm.status_ch), 0072 status_ch = parm.status_ch; 0073 else 0074 status_ch = {parm.status_ch}; 0075 end 0076 0077 % Load status channel 0078 loadspec = []; 0079 loadspec.ChannelName = status_ch; 0080 status = vb_load_meg_data(fname, loadspec); 0081 0082 [ix_trial, trig, cond_id, status_val,status_out] = ... 0083 vb_get_trial_time_index(status,parm); 0084 0085 if isempty(ix_trial), return; end; 0086 0087 % ix_trial(:,n) : Time index for n-th trial [Tperiod x Ntrial] 0088 tmin = min(ix_trial,[],1); 0089 tmax = max(ix_trial,[],1); 0090 0091 % check time is inside the data 0092 ix = find( (tmin > 0) & (tmax <= info.Nsample)); 0093 0094 trig = trig(ix); 0095 ix_trial = ix_trial(:,ix); 0096 cond_id = cond_id(ix); 0097 0098 vb_fsave(ftrig,'ix_trial','trig','status','status_out','status_val','cond_id','parm');