get time index for each trial by checking status channel --- Usage job_trial_onset_nmag(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_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 job_trial_onset_nmag(proj_root,parm) 0002 % get time index for each trial by checking status channel 0003 % --- Usage 0004 % job_trial_onset_nmag(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_val(m) = status value for m-th condition (m=1:Ncomdition) 0020 % trig(n) : Onset time index for n-th trial 0021 % cond_id(n) : Condition ID for n-th trial 0022 % ix_trial(:,n) : Time index for n-th trial [Tperiod x Ntrial] 0023 % Tperiod : # of time sample in one trial 0024 % Ntrial : # of trials 0025 % parm : parameter setting 0026 % parm.fsamp : Sample Frequency [Hz] 0027 % 0028 % --- Optional parameter for EMG onset 0029 % parm.t_event : minimum distance from previous onset event [150 ms] 0030 % distance from previous onset should be larger than t_event 0031 % parm.p_val : P-value corresponding to the threshold for [EMG, smooth(EMG)] 0032 % [0.0001, 0.0005] or [0.0001, 0.001] 0033 % cumulative histgram is used to determine threshold from P-value 0034 % 0035 % --- Usually following parameters need not be changed 0036 % parm.hist_mode : histgram mode [1] 0037 % = 1: Estimate threshold by gamma distribution approximation 0038 % = 0: Estimate threshold by histgram 0039 % parm.t_smooth : moving average window length [25 ms] 0040 % parm.t_slope : slope estimation period near onset [25 ms] 0041 % if t_slope==0, zero cross point is not calculated 0042 % parm.t_peak : peak evaluation period [100 ms] 0043 % peak_val : EMG value should exceed peak_val within 't_peak' after onset 0044 % = mean(peak value > threshold) if hist_mode = 1 0045 % = (max(y) * status_level) if hist_mode = 0 or 2 0046 % --- Condition for EMG onset 0047 % 1. distance from previous onset should be larger than t_event 0048 % 2. distance between EMG & smoothed EMG onset should be smaller than t_event 0049 % 3. EMG value should exceed peak_val within t_peak after onset 0050 % 4. zero cross point is estimated 0051 % by linear fitting around smoothed EMG threshold point 0052 % 0053 % 0054 % 2009-6-14 Masa-aki Sato 0055 % 0056 % Copyright (C) 2011, ATR All Rights Reserved. 0057 % License : New BSD License(see VBMEG_LICENSE.txt) 0058 0059 % Original data file 0060 fname = [proj_root filesep parm.data_file ]; 0061 ftrig = [proj_root filesep parm.trig_file ]; 0062 0063 % Load info 0064 info = vb_load_meg_info(fname); 0065 0066 % Sample Frequency [Hz] 0067 parm.fsamp = info.SampleFreq; 0068 0069 %if iscell(parm.status_ch), 0070 % status_ch = parm.status_ch; 0071 %else 0072 % status_ch = {parm.status_ch}; 0073 %end 0074 0075 % Load status channel 0076 %loadspec = []; 0077 %loadspec.ChannelName = status_ch; 0078 %status = load_meg_data(fname, loadspec); 0079 load(fname,'MEGinfo','bexp_ext') 0080 0081 ch = strmatch(parm.status_ch{1}, MEGinfo.ExtraChannelInfo.Channel_name); 0082 status = bexp_ext(ch,:); 0083 0084 [ix_trial, trig, cond_id, status_val,status] = ... 0085 vb_get_trial_time_index(status,parm); 0086 % get_trial_time_index(status,parm); 0087 0088 if isempty(ix_trial), return; end; 0089 0090 % ix_trial(:,n) : Time index for n-th trial [Tperiod x Ntrial] 0091 tmin = min(ix_trial,[],1); 0092 tmax = max(ix_trial,[],1); 0093 0094 % check time is inside the data 0095 ix = find( (tmin > 0) & (tmax <= info.Nsample)); 0096 0097 trig = trig(ix); 0098 ix_trial = ix_trial(:,ix); 0099 cond_id = cond_id(ix); 0100 0101 vb_fsave(ftrig,'ix_trial','trig','status','status_val','cond_id','parm');