Home > functions > device > eeg > biosemi > vb_util_make_mark_trigger_spec.m

vb_util_make_mark_trigger_spec

PURPOSE ^

make struct of mark_trigger_spec from given information

SYNOPSIS ^

function my_spec = vb_util_make_mark_trigger_spec(msrmnt_file, target_list, to_read_swt, output_file, auto_info)

DESCRIPTION ^

 make struct of mark_trigger_spec from given information

 [usage]
   my_spec = vb_util_make_mark_trigger_spec( ...
     msrmnt_file, target_list, to_read_swt, output_file, auto_info)

 [input]
   msrmnt_file : <required>
               : MAT file which includes next information :
               :   - data (Nchannel x Nsample) <must>
               :   - base channel list <must>
               :   - sample_frequency <if needed>
               : e.g. EEG-MAT (.eeg.mat), MEG-MAT (.meg.mat)
   target_list : <optional> [[]]
               : list of used channel label
               :   "base channel list" must have these channels
   to_read_swt : <optional> true or false [false]
               :   switch that "target_channel_list" is whether to read
               :   or not
               :   error if "to_read_swt" is true and "target_list" is empty
   output_file : <optional> ['./trigger_list.mat']
     auto_info : <optional> <<struct>> [[]]
         : information for auto marking. fields are as follows:
         :   - auto_detect
         :     : true or false
         :     : auto-detect switch
         :     : if this switch is 'true', other fields of auto_info are
         :     : ignored.
         :   - trigger_channel
         :     : trigger channel label of "base channel list"
         :   - trigger_file
         :     : MAT file which includes trigger time list

 [output]
       my_spec : <<struct>>
         :   mark_trigger_spec type whose fields are as follows:
         :                 data : <required> (Nchannel x Nsample)
         :                      :  measured data matrix
         :             plot_idx : <required> (Nchannel x 1)
         :                      :  list of index of 'data' to be plotted
         :  trigger_channel_idx : <optional> (Nchannel x 1) [[]]
         :                      :  trigger index of 'data'
         :   trigger_sample_idx : <optional> [[]]
         :                      :  list of trigger points as sample number
         :          output_file : <optional> ['.\trigger_(date).mat']
         :                      :  output file which has trigger_sample_list

 [note]
   
 [history]
   2007-01-10 (Sako) initial version
   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 my_spec = vb_util_make_mark_trigger_spec( ...
0002   msrmnt_file, target_list, to_read_swt, output_file, auto_info)
0003 % make struct of mark_trigger_spec from given information
0004 %
0005 % [usage]
0006 %   my_spec = vb_util_make_mark_trigger_spec( ...
0007 %     msrmnt_file, target_list, to_read_swt, output_file, auto_info)
0008 %
0009 % [input]
0010 %   msrmnt_file : <required>
0011 %               : MAT file which includes next information :
0012 %               :   - data (Nchannel x Nsample) <must>
0013 %               :   - base channel list <must>
0014 %               :   - sample_frequency <if needed>
0015 %               : e.g. EEG-MAT (.eeg.mat), MEG-MAT (.meg.mat)
0016 %   target_list : <optional> [[]]
0017 %               : list of used channel label
0018 %               :   "base channel list" must have these channels
0019 %   to_read_swt : <optional> true or false [false]
0020 %               :   switch that "target_channel_list" is whether to read
0021 %               :   or not
0022 %               :   error if "to_read_swt" is true and "target_list" is empty
0023 %   output_file : <optional> ['./trigger_list.mat']
0024 %     auto_info : <optional> <<struct>> [[]]
0025 %         : information for auto marking. fields are as follows:
0026 %         :   - auto_detect
0027 %         :     : true or false
0028 %         :     : auto-detect switch
0029 %         :     : if this switch is 'true', other fields of auto_info are
0030 %         :     : ignored.
0031 %         :   - trigger_channel
0032 %         :     : trigger channel label of "base channel list"
0033 %         :   - trigger_file
0034 %         :     : MAT file which includes trigger time list
0035 %
0036 % [output]
0037 %       my_spec : <<struct>>
0038 %         :   mark_trigger_spec type whose fields are as follows:
0039 %         :                 data : <required> (Nchannel x Nsample)
0040 %         :                      :  measured data matrix
0041 %         :             plot_idx : <required> (Nchannel x 1)
0042 %         :                      :  list of index of 'data' to be plotted
0043 %         :  trigger_channel_idx : <optional> (Nchannel x 1) [[]]
0044 %         :                      :  trigger index of 'data'
0045 %         :   trigger_sample_idx : <optional> [[]]
0046 %         :                      :  list of trigger points as sample number
0047 %         :          output_file : <optional> ['.\trigger_(date).mat']
0048 %         :                      :  output file which has trigger_sample_list
0049 %
0050 % [note]
0051 %
0052 % [history]
0053 %   2007-01-10 (Sako) initial version
0054 %   2011-07-29 (Sako) replaced searching index function
0055 %
0056 % Copyright (C) 2011, ATR All Rights Reserved.
0057 % License : New BSD License(see VBMEG_LICENSE.txt)
0058 
0059 % --- CHECK ARGUMENTS --- %
0060 if ~exist('msrmnt_file', 'var'), msrmnt_file = []; end;
0061 if ~exist('target_list', 'var'), target_list = []; end;
0062 if ~exist('to_read_swt', 'var'), to_read_swt = []; end;
0063 if ~exist('output_file', 'var'), output_file = []; end;
0064 if ~exist('auto_info', 'var'),   auto_info = [];   end;
0065 
0066 [msrmnt_file, target_list, to_read_swt, output_file, auto_info] = ...
0067   inner_check_arguments( ...
0068   msrmnt_file, target_list, to_read_swt, output_file, auto_info);
0069 
0070 % --- MAIN PROCEDURE ----------------------------------------------------------%
0071 %
0072 my_spec = [];
0073 
0074 % --- 1) measured data
0075 my_spec.data     = vb_load_meg_data(msrmnt_file);
0076 
0077 base_channel_list = vb_msrmnt_get_channel_list(msrmnt_file);
0078 
0079 read_channel_list = vb_util_get_labels_to_read( ...
0080   base_channel_list, target_list, to_read_swt);
0081 
0082 % --- 2) plot index list
0083 my_spec.plot_idx = ...
0084   vb_util_get_matching_label_index(base_channel_list, read_channel_list);
0085 
0086 % --- 3) 4) trigger information (indices of channel and sample)
0087 sampling_frequency = vb_msrmnt_get_sampling_frequency(msrmnt_file);
0088 
0089 [trigger_channel_idx, trigger_sample_idx] = ...
0090   inner_get_trigger_info(msrmnt_file, auto_info, sampling_frequency);
0091 % [trigger_channel, trigger_list] = inner_get_trigger_info( ...
0092 %   msrmnt_file, auto_info, sampling_frequency);
0093 
0094 my_spec.trigger_sample_idx = trigger_sample_idx;
0095 my_spec.trigger_channel_idx = trigger_channel_idx;
0096 
0097 % --- 5) output file
0098 my_spec.output_file = output_file;
0099 %
0100 % --- END OF MAIN PROCEDURE ---------------------------------------------------%
0101 
0102 
0103 % --- INNER FUNCTIONS -------------------------------------------------------- %
0104 %
0105 % --- inner_check_arguments() -------------------- %
0106 %
0107 function [msrmnt_file,target_list,to_read_swt,output_file,auto_info] = ...
0108   inner_check_arguments(msrmnt_file, ...
0109     target_list, to_read_swt, output_file, auto_info)
0110 
0111 vb_define_device;
0112 
0113 % required parameter
0114 if isempty(msrmnt_file)
0115   error('msrmnt_file is a required parameter');
0116 end
0117 
0118 if exist(msrmnt_file, 'file') ~= 2
0119   error('cannot read measurement file : %s', msrmnt_file);
0120 end
0121 
0122 % optional parameters
0123 if isempty(to_read_swt)
0124   to_read_swt = false;
0125 end
0126 
0127 if isempty(output_file)
0128   output_file = ['.' filesep 'trigger_list.mat'];
0129 end
0130 
0131 % error if to_read_swt is true and target_list is empty
0132 if isempty(target_list) && to_read_swt == true
0133   error('target_list is empty and to_read_swt is true');
0134 end
0135 
0136 % how to get initial triggers
0137 if isfield(auto_info, 'auto_detect') ...
0138     && auto_info.auto_detect == true
0139   auto_info.how = TRIGGER_HOW_FULL;
0140   
0141 elseif isfield(auto_info, 'trigger_channel') ...
0142     && ~isempty(auto_info.trigger_channel)
0143   auto_info.how = TRIGGER_HOW_SEMI;
0144   
0145 elseif isfield(auto_info, 'trigger_file') ...
0146     && ~isempty(auto_info.trigger_file)
0147   auto_info.how = TRIGGER_HOW_FILE;
0148   
0149 else
0150   auto_info.how = TRIGGER_HOW_MANUAL;
0151 end
0152 %
0153 % --- end of inner_check_argument() -------------------- %
0154 
0155 
0156 % --- inner_get_trigger_info() -------------------- %
0157 %
0158 % function [trigger_channel, trigger_list] = inner_get_trigger_info( ...
0159 %   auto_info, sampling_frequency, bit_list)
0160 function [trigger_channel_idx, trigger_sample_idx] = ...
0161   inner_get_trigger_info(msrmnt_file, auto_info, sampling_frequency)
0162 
0163 vb_define_device;
0164 
0165 trigger_channel_idx = [];
0166 trigger_sample_idx = [];
0167 
0168 if isempty(auto_info)
0169   return;
0170 end
0171 
0172 % check highest priority switch
0173 switch auto_info.how
0174   case  TRIGGER_HOW_FULL
0175 
0176     % auto-detect trigger list
0177     [trigger_channel_idx, trigger_sample_idx] = ...
0178       vb_msrmnt_auto_detect_trigger_info(msrmnt_file);
0179     return;
0180 
0181   case  TRIGGER_HOW_SEMI
0182     trigger_channels = auto_info.trigger_channel;
0183 
0184     [trigger_channel_idx, trigger_sample_idx] = vb_msrmnt_get_trigger_samples( ...
0185       msrmnt_file, trigger_channels);
0186     return;
0187 
0188   case  TRIGGER_HOW_FILE
0189     [trigger_channel_idx, trigger_sample_idx] = ...
0190       vb_util_read_trigger_file(auto_info.trigger_file, sampling_frequency);
0191   
0192   otherwise
0193     % nothing to do
0194 end % end of switch auto_spec.how
0195 %
0196 % --- end of inner_get_trigger_info() -------------------- %
0197 
0198 %%% END OF FILE %%%

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005