0001 function [trigger_channel_idx, trigger_sample_idx] = ...
0002 vb_util_read_trigger_file(trigger_file, sample_freq)
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 if ~exist('trigger_file', 'var') trigger_file = []; end;
0029 if ~exist('sample_freq', 'var') sample_freq = []; end;
0030
0031 [trigger_file, sampling_frequency, trigger_spec] = ...
0032 inner_check_argument(trigger_file, sample_freq);
0033
0034
0035
0036
0037 trigger_channel_idx = [];
0038
0039 switch trigger_spec.my_type
0040 case 'SAMPLE'
0041 trigger_sample_idx = ...
0042 inner_set_sample_index(trigger_spec.idx_type, trigger_spec.my_list);
0043
0044 case 'TIME'
0045 switch trigger_spec.my_unit
0046 case 'MS'
0047 if ~isempty(sampling_frequency)
0048 [msec_time, sample_idx] = vb_util_sample2msectime2sample( ...
0049 [], trigger_spec.my_list, sampling_frequency);
0050 trigger_sample_idx = ...
0051 inner_set_sample_index(trigger_spec.idx_type, sample_idx);
0052 end
0053 otherwise
0054 error('unknown trigger_spec.unit : %s', trigger_spec.my_unit);
0055 end
0056
0057 otherwise
0058
0059 trigger_sample_idx = ...
0060 inner_set_sample_index(trigger_spec.idx_type, trigger_spec.my_list);
0061
0062 end
0063
0064
0065
0066
0067
0068
0069
0070
0071 function [trigger_file, sample_freq, trigger_spec] = ...
0072 inner_check_argument(trigger_file, sample_freq)
0073
0074 if isempty(trigger_file)
0075 error('trigger_file is a required parameter');
0076 end
0077
0078 if exist(trigger_file, 'file') ~= 2
0079 error('cannot read trigger_file : %s', trigger_file)
0080 end
0081
0082
0083 trigger_spec.my_list = [];
0084 trigger_spec.my_type = [];
0085 trigger_spec.my_unit = [];
0086 trigger_spec.idx_type = [];
0087
0088 load(trigger_file);
0089
0090 if ~exist('my_list', 'var')
0091 error('trigger_file ''%s'' does not have trigger list data', trigger_file);
0092 end
0093
0094 if ~exist('my_type', 'var'), my_type = 'SAMPLE'; end;
0095 if ~exist('my_unit', 'var'), my_unit = 'MS'; end;
0096 if ~exist('idx_type', 'var'), idx_type = 'BEGIN'; end;
0097
0098 if strcmp(my_type, 'TIME') && isempty(sample_freq)
0099 error('''sample_freq'' is necessary when type is ''TIME''');
0100 end
0101
0102 trigger_spec.my_list = my_list; end;
0103 trigger_spec.my_type = my_type; end;
0104 trigger_spec.my_unit = my_unit; end;
0105 trigger_spec.idx_type = idx_type; end;
0106
0107
0108
0109
0110
0111 function sample_idx = inner_set_sample_index(index_type, this_index)
0112
0113
0114 this_index = vb_util_arrange_list(this_index, 1);
0115
0116 switch index_type
0117 case 'ALL'
0118 sample_idx.all_idx = this_index;
0119 case 'BEGIN'
0120 sample_idx.beg_idx = this_index;
0121 case 'END'
0122 sample_idx.end_idx = this_index;
0123 otherwise
0124 error('unknown index type: %s', index_type);
0125 end
0126
0127
0128