vb_test_extract_trial_emg ----- Trial onset extraction for EMG ----- --- 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 : trigger signal type [string] = 'integer' or 'analog' or 'voice' or 'emg' parm.slope : type of signal change [string] = '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' or '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] --- 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 --- 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 if there are multi condition 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] 2009-6-14 Masa-aki Sato 2009-9-5 Masa-aki Sato Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 % vb_test_extract_trial_emg 0002 % ----- Trial onset extraction for EMG ----- 0003 % --- Input 0004 % parm.data_file : Data file name [string] 0005 % parm.trig_file : Trial onset file name [string] 0006 % parm.status_ch : status channel name [string] 0007 % parm.trig_type : trigger signal type [string] 0008 % = 'integer' or 'analog' or 'voice' or 'emg' 0009 % parm.slope : type of signal change [string] 0010 % = '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' or '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 % 0018 % --- Optional parameter for EMG onset 0019 % parm.t_event : minimum distance from previous onset event [150 ms] 0020 % distance from previous onset should be larger than t_event 0021 % parm.p_val : P-value corresponding to the threshold for [EMG, smooth(EMG)] 0022 % [0.0001, 0.0005] or [0.0001, 0.001] 0023 % cumulative histgram is used to determine threshold from P-value 0024 % 0025 % --- Usually following parameters need not be changed 0026 % parm.hist_mode : histgram mode [1] 0027 % = 1: Estimate threshold by gamma distribution approximation 0028 % = 0: Estimate threshold by histgram 0029 % parm.t_smooth : moving average window length [25 ms] 0030 % parm.t_slope : slope estimation period near onset [25 ms] 0031 % if t_slope==0, zero cross point is not calculated 0032 % parm.t_peak : peak evaluation period [100 ms] 0033 % peak_val : EMG value should exceed peak_val within 't_peak' after onset 0034 % = mean(peak value > threshold) if hist_mode = 1 0035 % = (max(y) * status_level) if hist_mode = 0 or 2 0036 % --- Condition for EMG onset 0037 % 1. distance from previous onset should be larger than t_event 0038 % 2. distance between EMG & smoothed EMG onset should be smaller than t_event 0039 % 3. EMG value should exceed peak_val within t_peak after onset 0040 % 4. zero cross point is estimated 0041 % by linear fitting around smoothed EMG threshold point 0042 % 0043 % --- Save variables 0044 % status : status signal 0045 % status_val(m) = status value for m-th condition (m=1:Ncomdition) 0046 % trig(n) : Onset time index for n-th trial 0047 % cond_id(n) : Condition ID for n-th trial if there are multi condition 0048 % ix_trial(:,n) : Time index for n-th trial [Tperiod x Ntrial] 0049 % Tperiod : # of time sample in one trial 0050 % Ntrial : # of trials 0051 % parm : parameter setting 0052 % parm.fsamp : Sample Frequency [Hz] 0053 % 0054 % 2009-6-14 Masa-aki Sato 0055 % 2009-9-5 Masa-aki Sato 0056 % 0057 % Copyright (C) 2011, ATR All Rights Reserved. 0058 % License : New BSD License(see VBMEG_LICENSE.txt) 0059 0060 clear all 0061 0062 % --- root directry 0063 root_dir = [getenv('MATHOME') '/Finger_move/RH070222']; 0064 0065 % --- List of data file names (base name without extension) 0066 data_file = {'RH070222a'}; 0067 % data file extension 0068 ext = '.meg.mat'; 0069 0070 plot_parm.mode = 1; % = 1: plot all trial 0071 % = 2: subplot for each trial 0072 % = 3: multiple trials in one subplot 0073 plot_parm.NXmax = 4; % # of trial in X-axis 0074 plot_parm.NYmax = 4; % # of subplot in Y-axis 0075 plot_parm.status = 0; 0076 0077 % --- Set condition list 0078 % EMG:226,227 0079 % 光 :240,241 (EMG-光は対応関係) 0080 parm.condition = 'EMG'; 0081 parm.status_ch = '227'; 0082 parm.trig_type = 'emg'; 0083 parm.slope = '' ; 0084 parm.status_level = 1/4; 0085 parm.Pretrigger_ms = [ 100 ]; % [msec] 0086 parm.Posttrigger_ms = [ 200 ]; % [msec] 0087 0088 % --- Critical parameter (this value may be changed) 0089 parm.t_event = 150; % 150 ms 0090 %parm.t_event = 300; 0091 0092 %parm.p_val = [0.0001 0.001]; 0093 parm.p_val = [0.0001 0.0005]; 0094 0095 % --- Default parameter for EMG onset 0096 % Usually these parameters need not be changed 0097 parm.hist_mode = 1; 0098 parm.t_smooth = 25; % 25 ms 0099 parm.t_slope = 25; % 25 ms 0100 parm.t_peak = 100; % 100 ms 0101 0102 Nfile = length(data_file); 0103 0104 % --- Trial onset extraction start 0105 for n=1:Nfile 0106 % MEG mat file 0107 parm.data_file = [data_file{n} ext]; 0108 0109 % Trial onset file 0110 parm.trig_file = [data_file{n} '_' parm.condition '.trig.mat']; 0111 0112 % Get time index for each trial by checking status channel 0113 vb_job_trial_onset(root_dir,parm); 0114 0115 if plot_parm.mode > 0, 0116 % png file name 0117 fpng = [root_dir '/' data_file{n} '_' parm.condition ]; 0118 plot_parm.png = []; %fpng; 0119 0120 vb_plot_status([root_dir '/' parm.trig_file ], plot_parm); 0121 end 0122 0123 end 0124 0125 return