Home > vbmeg > functions > device > vb_msrmnt_get_trigger_samples.m

vb_msrmnt_get_trigger_samples

PURPOSE ^

return indices of trigger sample from measurement file and specified

SYNOPSIS ^

function [trigger_channel_idx, trigger_sample_idx] =vb_msrmnt_get_trigger_samples(msrmnt_file, trigger_ch, tr_strt_idx)

DESCRIPTION ^

 return indices of trigger sample from measurement file and specified 
 trigger channels
 [usage]
   [trigger_channel_idx, trigger_sample_idx] = ...
     vb_msrmnt_get_trigger_samples(msrmnt_file, trigger_ch, tr_strt_idx)
 [input]
   msrmnt_file : <required> measurement file
               : EEG-MAT(.eeg.mat) or MEG-MAT(.meg.mat = unsupported yet)
    trigger_ch : <required> cell array of trigger channel labels
   tr_strt_idx : <optional> trigger starting index [auto-detect]
 [output]
   trigger_channel_idx : array of trigger channel index
    trigger_sample_idx : <struct> information box of trigger [1 x N_channel]
               : all_idx : index of all samples
               : beg_idx : index of beginning samples
               : end_idx : index of ending samples
 [note]
   
 [history]
   2007-01-04 (Sako) initial version
   2011-06-01 (Sako) converted return values of vb_load_device to upper case
   2011-07-29 (Sako) replaced searching index function

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [trigger_channel_idx, trigger_sample_idx] = ...
0002   vb_msrmnt_get_trigger_samples(msrmnt_file, trigger_ch, tr_strt_idx)
0003 % return indices of trigger sample from measurement file and specified
0004 % trigger channels
0005 % [usage]
0006 %   [trigger_channel_idx, trigger_sample_idx] = ...
0007 %     vb_msrmnt_get_trigger_samples(msrmnt_file, trigger_ch, tr_strt_idx)
0008 % [input]
0009 %   msrmnt_file : <required> measurement file
0010 %               : EEG-MAT(.eeg.mat) or MEG-MAT(.meg.mat = unsupported yet)
0011 %    trigger_ch : <required> cell array of trigger channel labels
0012 %   tr_strt_idx : <optional> trigger starting index [auto-detect]
0013 % [output]
0014 %   trigger_channel_idx : array of trigger channel index
0015 %    trigger_sample_idx : <struct> information box of trigger [1 x N_channel]
0016 %               : all_idx : index of all samples
0017 %               : beg_idx : index of beginning samples
0018 %               : end_idx : index of ending samples
0019 % [note]
0020 %
0021 % [history]
0022 %   2007-01-04 (Sako) initial version
0023 %   2011-06-01 (Sako) converted return values of vb_load_device to upper case
0024 %   2011-07-29 (Sako) replaced searching index function
0025 %
0026 % Copyright (C) 2011, ATR All Rights Reserved.
0027 % License : New BSD License(see VBMEG_LICENSE.txt)
0028 
0029 vb_define_device;
0030 
0031 % --- CHECK ARGUMENTS --- %
0032 if ~exist('msrmnt_file', 'var'), msrmnt_file = []; end
0033 if ~exist('trigger_ch', 'var'),  trigger_ch = []; end
0034 if ~exist('tr_strt_idx', 'var'), tr_strt_idx = []; end
0035 [msrmnt_file, trigger_ch, tr_strt_idx, ...
0036     Measurement, info, data, trg_ch_idx] = ...
0037   inner_check_arguments(msrmnt_file, trigger_ch, tr_strt_idx);
0038 
0039 trigger_channel_idx = trg_ch_idx;
0040 
0041 % --- MAIN PROCEDURE --------------------------------------------------------- %
0042 %
0043 func_ = mfilename;
0044 switch Measurement
0045   case  'EEG'
0046     idx = vb_eeginfo_get_trigger_status_label(info);
0047 
0048     status_data = data(idx,:);
0049 
0050     bit_len = DEFAULT_BIT_LEN;
0051     bit_arrays = vb_eeg_make_channel_bit_array(status_data, trg_ch_idx, bit_len);
0052 
0053     trigger_sample_idx = [];
0054     for nch = 1:size(bit_arrays,1)
0055       trigger_sample_idx = [trigger_sample_idx; ...
0056         vb_util_get_bit_on_list(bit_arrays(nch,:), bit_len)];
0057     end
0058 
0059   case  'MEG'
0060     error('(%s)not be implemented yet for ''%s''', func_, Measurement);
0061   otherwise
0062     error('(%s)unknown Measurement: ''%s''', func_, Measurement);
0063 end
0064 %
0065 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0066 
0067 % --- INNER FUNCTIONS -------------------------------------------------------- %
0068 %
0069 % --- inner_check_arguments()
0070 %
0071 function [msrmnt_file, trigger_ch, tr_strt_idx, ...
0072     Measurement, info, data, trg_ch_idx] = ...
0073   inner_check_arguments(msrmnt_file, trigger_ch, tr_strt_idx)
0074 
0075 func_ = mfilename;
0076 
0077 info = [];
0078 data = [];
0079 trg_ch_idx = [];
0080 
0081 if isempty(msrmnt_file)
0082   error('(%s)msrmnt_file is a required parameter', func_);
0083 end
0084 
0085 if exist(msrmnt_file, 'file') ~= 2
0086   error('(%s)cannot read msrmnt_file : %s', func_, msrmnt_file);
0087 end
0088 
0089 [measurement] = vb_load_device(msrmnt_file);
0090 Measurement = upper(measurement);
0091 
0092 switch Measurement
0093   case  'EEG'
0094     info = vb_eegfile_load_eeginfo(msrmnt_file);
0095     data = load_eeg_data(msrmnt_file);
0096 
0097     if isempty(tr_strt_idx)
0098       tr_strt_idx = vb_eeginfo_get_sensor_number(info) + 1;
0099     end;
0100 
0101     % index of trigger channel
0102     all_ch_label = vb_eegfile_get_channel_label(msrmnt_file);
0103     org_ch_idx = vb_util_get_matching_label_index(all_ch_label, trigger_ch);
0104     trg_ch_idx = org_ch_idx - tr_strt_idx + 1;
0105     
0106     % re-arrange [1 x N] is expected in this function
0107     trg_ch_idx = vb_util_arrange_list(trg_ch_idx,1);
0108     
0109   case  'MEG'
0110     error('(%s)not be implemented yet for ''%s''', func_, Measurement);
0111   otherwise
0112     error('(%s)unknown Measurement : ''%s''', func_, Measurement);
0113 end
0114 
0115 if isempty(trigger_ch)
0116   error('(%s)trigger_ch is a required parameter', func_);
0117 end
0118 
0119 %
0120 % --- end of inner_check_arguments()
0121 
0122 % --- END OF FILE --- %

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005