Home > vbmeg > functions > device > vb_msrmnt_auto_detect_trigger_info.m

vb_msrmnt_auto_detect_trigger_info

PURPOSE ^

get trigger information from msrmnt_file by auto-detect

SYNOPSIS ^

function [trigger_channel_idx, trigger_sample_idx] =vb_msrmnt_auto_detect_trigger_info(msrmnt_file, ch_type)

DESCRIPTION ^

 get trigger information from msrmnt_file by auto-detect

 [usage]
   [trigger_channel_idx, trigger_sample_idx] = ...
     vb_msrmnt_auto_detect_trigger_info(msrmnt_file, ch_type)

 [input]
   msrmnt_file : <required> actually EEG-MAT(.eeg.mat) file
       ch_type : <optional> 1 or 2 [1]
               : channel type
               : 1) standard
               : 2) hardware

 [output]
   trigger_channel_idx : index of channels of trigger (cell array)
                       : normally one
    trigger_sample_idx : <struct> sample numbers information of trigger
                      : [1 x N_channel]
            :  - all_idx : list of index of "ON" bit
            :  - beg_idx : index that "ON" bit begins
            :  - end_idx : index that "ON" bit breathe

 [note]

 [history]
   2007-01-10 (Sako) initial version
   2011-06-01 (Sako) converted return values of vb_load_device to upper case

 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_auto_detect_trigger_info(msrmnt_file, ch_type)
0003 % get trigger information from msrmnt_file by auto-detect
0004 %
0005 % [usage]
0006 %   [trigger_channel_idx, trigger_sample_idx] = ...
0007 %     vb_msrmnt_auto_detect_trigger_info(msrmnt_file, ch_type)
0008 %
0009 % [input]
0010 %   msrmnt_file : <required> actually EEG-MAT(.eeg.mat) file
0011 %       ch_type : <optional> 1 or 2 [1]
0012 %               : channel type
0013 %               : 1) standard
0014 %               : 2) hardware
0015 %
0016 % [output]
0017 %   trigger_channel_idx : index of channels of trigger (cell array)
0018 %                       : normally one
0019 %    trigger_sample_idx : <struct> sample numbers information of trigger
0020 %                      : [1 x N_channel]
0021 %            :  - all_idx : list of index of "ON" bit
0022 %            :  - beg_idx : index that "ON" bit begins
0023 %            :  - end_idx : index that "ON" bit breathe
0024 %
0025 % [note]
0026 %
0027 % [history]
0028 %   2007-01-10 (Sako) initial version
0029 %   2011-06-01 (Sako) converted return values of vb_load_device to upper case
0030 %
0031 % Copyright (C) 2011, ATR All Rights Reserved.
0032 % License : New BSD License(see VBMEG_LICENSE.txt)
0033 
0034 vb_define_device;
0035 
0036 % --- CHECK ARGUMENTS --- %
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 % --- MAIN PROCEDURE --------------------------------------------------------- %
0044 %
0045 % auto-detect trigger channel
0046 func_ = mfilename;
0047 
0048 switch Measurement
0049   case  'EEG'
0050     % return values
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 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0080 
0081 % --- INNER FUNCTIONS -------------------------------------------------------- %
0082 %
0083 % --- inner_check_arguments()
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;  % standard
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 % --- end of inner_check_arguments()
0125 
0126 % --- END OF FILE --- %

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