0001 function [trigger_channel_idx, trigger_sample_idx] = ...
0002 vb_msrmnt_auto_detect_trigger_info(msrmnt_file, ch_type)
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
0029
0030
0031
0032
0033
0034 vb_define_device;
0035
0036
0037 if ~exist('msrmnt_file', 'var'), msrmnt_file = []; end;
0038 if ~exist('ch_type', 'var'), ch_type = []; end;
0039
0040 [msrmnt_file, ch_type, Measurement, info, data] = ...
0041 inner_check_arguments(msrmnt_file, ch_type);
0042
0043
0044
0045
0046 func_ = mfilename;
0047
0048 switch Measurement
0049 case 'EEG'
0050
0051 trigger_channel_idx = [];
0052 trigger_sample_idx = [];
0053
0054 [idx, trigger_channel] = vb_eeginfo_get_trigger_status_label(info);
0055
0056 status_data = data(idx,:);
0057
0058 [ch_list, bit_list] = ...
0059 vb_eeg_get_active_trigger_channel(status_data, DEFAULT_BIT_LEN);
0060
0061 valid_ch_idx = find(ch_list <= DEFAULT_TRIGGER_CH_NUM);
0062 valid_bit_list = bit_list(valid_ch_idx,:);
0063
0064 trigger_channel_idx = valid_ch_idx;
0065
0066 trigger_sample_idx = [];
0067 for nch = 1:size(valid_bit_list,1)
0068 trigger_sample_idx = [trigger_sample_idx; ...
0069 vb_util_get_bit_on_list(valid_bit_list(nch,:), DEFAULT_BIT_LEN)];
0070 end
0071
0072 case 'MEG'
0073 error('(%s)not be implemented yet for ''%s''', func_, Measurement);
0074
0075 otherwise
0076 error('(%s)unknown Measurement: ''%s''', func_, Measurement);
0077 end
0078
0079
0080
0081
0082
0083
0084
0085 function [msrmnt_file, ch_type, Measurement, info, data] = ...
0086 inner_check_arguments(msrmnt_file, ch_type)
0087 func_ = mfilename;
0088
0089 if isempty(msrmnt_file)
0090 error('(%s)msrmnt_file is a required parameter', func_);
0091 end
0092
0093 if exist(msrmnt_file, 'file') ~= 2
0094 error('(%s)cannot find measurement file : %s', func_, msrmnt_file);
0095 end
0096
0097 if isempty(ch_type)
0098 ch_type = 1;
0099 end
0100
0101 [measurement] = vb_load_device(msrmnt_file);
0102 Measurement = upper(measurement);
0103
0104 switch Measurement
0105 case 'EEG'
0106 load(msrmnt_file, 'EEGinfo', 'eeg_data');
0107 if ~exist('EEGinfo', 'var') || isempty(EEGinfo)
0108 error('(%s)measurement file doesnot have EEGinfo field', func_);
0109 end
0110
0111 if ~exist('eeg_data', 'var') || isempty(eeg_data)
0112 error('(%s)measurement file doesnot have eeg_data field', func_);
0113 end
0114 info = EEGinfo;
0115 data = eeg_data;
0116
0117 case 'MEG'
0118 error('(%s)not be implemented yet for ''%s''', func_, Measurement);
0119
0120 otherwise
0121 error('(%s)unknown Measurement: ''%s''', func_, Measurement);
0122 end
0123
0124
0125
0126