Home > functions > gui > preAnalysis > trial_extractor > vb_trial_extractor_batch_exec.m

vb_trial_extractor_batch_exec

PURPOSE ^

extract trial and output MEG(EEG) mat file.

SYNOPSIS ^

function vb_trial_extractor_batch_exec(trx_parm)

DESCRIPTION ^

 extract trial and output MEG(EEG) mat file.
 [USAGE]
    vb_trial_extractor_batch_exec(trx_parm);
 [IN]
    trx_parm : Trial extraction parameter.

 =============================
  * Continuous file section : Base continuous MEG/EEG file
   trx_parm
     .con_file   : <required> Continuous MEG/EEG MAT file <<string>>

 =============================
  * Trial extraction section
   trx_parm
     .trigger_list{N} : <required> trigger settings <<cell>> {1xNtrigger}
                                   see [Memo] in this help.
       example:
         trx_parm.trigger_list{1}     <<struct>>
                 .status_ch = {'436'};
                 .trig_type = 'analog';
                 .status_level = 0.5;
                 .slope     = 'low_to_high';
         trx_parm.trigger_list{2}     <<struct>>
                 .status_ch: {'437'};
                 .trig_type: 'voice';
                 .status_level: 0.0200;

   trx_parm
      .trial_setting : Trial settings <<struct>>
         .pretrigger_ms  : <required> pretrigger length in miliseconds. 
         .posttrigger_ms : <required> posttrigger length in miliseconds.
         .minimum_distance_ms : <optional> minumum distance between 
                                           trial onsets in miliseconds.
        example:
           trx_parm.trial_setting.pretrigger_ms = 500;
           trx_parm.trial_setting.posttrigger_ms = 1000;
           trx_parm.trial_setting.minimum_distance_ms = 1000;

    ==>  Label named 'TRIGGERN' will be created by this operation

 =============================
  * Trial Labeling section : <optional> Label to extracted trials.
   trx_parm
     .label_spec : label trials by file.       <<struct>>
               .label_file : label file name <<string>>
                             [label file format]
                             label name is listed as below.
                             each row coresponding to trials in base_label.
                             (case-sensitive)
                             =====
                             LEFT
                             RIGHT
                             LOWER
                             LEFT
                             UPPER
                             ...
                             =====
               .base_label : Specify label name which you want to label<<cell>> {1xN}
                             example:
                                .base_label = {'TRIGGER1', 'TRIGGER2'};
                               if multiple labels are specified,
                               it will be processed as below.
                                 1.unite trials in labels.
                                 2.sort trials by time in ascending order.
                                 3.label trials by label_file.
                                 4.new labels are created.
    ==> As a result, new labels which are written in the label_file will be created.
        (In this case, 'LEFT', 'RIGHT', 'UPPER', 'LOWER' labels will be created)
   [For reference] extracted trial information.
    trx_parm
       .trial_list(n) : all extracted trial list. <<struct list>> [nx1]
                        The order is not sorted. It just contains extracted trials.
                .from    : The sample number of trial start point <<integer>> 
                .to      : The sample number of trial end point   <<integer>>
                .onset   : The sample number of trial onset point <<integer>>
       .label_list{m}  : created label info
            .name     : label name <<string>>.
            .trial_ix : values are indicies of trx_parm.trial_list.  <<integer>> [mx1]
 =============================
 * Trial output section
   trx_parm
     .output_file{n}.label_name  : <required> output label name. <<string>>
                    .output_file : <required> output filename(Evoked MEG/EEG-MAT) <<string>>
                                              specify with extension(.meg.mat, .eeg.mat)
            example:
              trx_parm.output_file{1}.label_name  = 'TRIGGER1';
              trx_parm.output_file{1}.output_file = 'TRIG1.meg.mat';

     .output_sample_freq         : <optional> sampling frequency of output files.

 [OUT]
    none

 [Memo]
    Template parameter can be made easily by using vb_trial_extractor.
     1.run vb_trial_extractor.
     2.Input trigger setting.
     3.Save parameter by "File->Save batch parameter(.trx.mat)".
     4.load('saved.trx.mat', 'trx_parm'); % Modify parameter here if necessary.
     5.run vb_trial_extractor_batch_exec(trx_parm);

 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 vb_trial_extractor_batch_exec(trx_parm)
0002 % extract trial and output MEG(EEG) mat file.
0003 % [USAGE]
0004 %    vb_trial_extractor_batch_exec(trx_parm);
0005 % [IN]
0006 %    trx_parm : Trial extraction parameter.
0007 %
0008 % =============================
0009 %  * Continuous file section : Base continuous MEG/EEG file
0010 %   trx_parm
0011 %     .con_file   : <required> Continuous MEG/EEG MAT file <<string>>
0012 %
0013 % =============================
0014 %  * Trial extraction section
0015 %   trx_parm
0016 %     .trigger_list{N} : <required> trigger settings <<cell>> {1xNtrigger}
0017 %                                   see [Memo] in this help.
0018 %       example:
0019 %         trx_parm.trigger_list{1}     <<struct>>
0020 %                 .status_ch = {'436'};
0021 %                 .trig_type = 'analog';
0022 %                 .status_level = 0.5;
0023 %                 .slope     = 'low_to_high';
0024 %         trx_parm.trigger_list{2}     <<struct>>
0025 %                 .status_ch: {'437'};
0026 %                 .trig_type: 'voice';
0027 %                 .status_level: 0.0200;
0028 %
0029 %   trx_parm
0030 %      .trial_setting : Trial settings <<struct>>
0031 %         .pretrigger_ms  : <required> pretrigger length in miliseconds.
0032 %         .posttrigger_ms : <required> posttrigger length in miliseconds.
0033 %         .minimum_distance_ms : <optional> minumum distance between
0034 %                                           trial onsets in miliseconds.
0035 %        example:
0036 %           trx_parm.trial_setting.pretrigger_ms = 500;
0037 %           trx_parm.trial_setting.posttrigger_ms = 1000;
0038 %           trx_parm.trial_setting.minimum_distance_ms = 1000;
0039 %
0040 %    ==>  Label named 'TRIGGERN' will be created by this operation
0041 %
0042 % =============================
0043 %  * Trial Labeling section : <optional> Label to extracted trials.
0044 %   trx_parm
0045 %     .label_spec : label trials by file.       <<struct>>
0046 %               .label_file : label file name <<string>>
0047 %                             [label file format]
0048 %                             label name is listed as below.
0049 %                             each row coresponding to trials in base_label.
0050 %                             (case-sensitive)
0051 %                             =====
0052 %                             LEFT
0053 %                             RIGHT
0054 %                             LOWER
0055 %                             LEFT
0056 %                             UPPER
0057 %                             ...
0058 %                             =====
0059 %               .base_label : Specify label name which you want to label<<cell>> {1xN}
0060 %                             example:
0061 %                                .base_label = {'TRIGGER1', 'TRIGGER2'};
0062 %                               if multiple labels are specified,
0063 %                               it will be processed as below.
0064 %                                 1.unite trials in labels.
0065 %                                 2.sort trials by time in ascending order.
0066 %                                 3.label trials by label_file.
0067 %                                 4.new labels are created.
0068 %    ==> As a result, new labels which are written in the label_file will be created.
0069 %        (In this case, 'LEFT', 'RIGHT', 'UPPER', 'LOWER' labels will be created)
0070 %   [For reference] extracted trial information.
0071 %    trx_parm
0072 %       .trial_list(n) : all extracted trial list. <<struct list>> [nx1]
0073 %                        The order is not sorted. It just contains extracted trials.
0074 %                .from    : The sample number of trial start point <<integer>>
0075 %                .to      : The sample number of trial end point   <<integer>>
0076 %                .onset   : The sample number of trial onset point <<integer>>
0077 %       .label_list{m}  : created label info
0078 %            .name     : label name <<string>>.
0079 %            .trial_ix : values are indicies of trx_parm.trial_list.  <<integer>> [mx1]
0080 % =============================
0081 % * Trial output section
0082 %   trx_parm
0083 %     .output_file{n}.label_name  : <required> output label name. <<string>>
0084 %                    .output_file : <required> output filename(Evoked MEG/EEG-MAT) <<string>>
0085 %                                              specify with extension(.meg.mat, .eeg.mat)
0086 %            example:
0087 %              trx_parm.output_file{1}.label_name  = 'TRIGGER1';
0088 %              trx_parm.output_file{1}.output_file = 'TRIG1.meg.mat';
0089 %
0090 %     .output_sample_freq         : <optional> sampling frequency of output files.
0091 %
0092 % [OUT]
0093 %    none
0094 %
0095 % [Memo]
0096 %    Template parameter can be made easily by using vb_trial_extractor.
0097 %     1.run vb_trial_extractor.
0098 %     2.Input trigger setting.
0099 %     3.Save parameter by "File->Save batch parameter(.trx.mat)".
0100 %     4.load('saved.trx.mat', 'trx_parm'); % Modify parameter here if necessary.
0101 %     5.run vb_trial_extractor_batch_exec(trx_parm);
0102 %
0103 % Copyright (C) 2011, ATR All Rights Reserved.
0104 % License : New BSD License(see VBMEG_LICENSE.txt)
0105 
0106 %
0107 % --- Previous check
0108 %
0109 if ~exist('trx_parm', 'var')
0110     error('trx_parm is a required parameter.');
0111 end
0112 
0113 %err = inner_check_proc_spec(trx_parm);
0114 %if err, error('Unknown field was detected.'); end
0115 
0116 if isfield(trx_parm, 'output_file')
0117     output_file = trx_parm.output_file;
0118 end
0119 if isfield(trx_parm, 'con_file') && exist(trx_parm.con_file, 'file') == 2
0120     trx_parm.continuous_file = vb_continuous_file_new(trx_parm.con_file);
0121 else
0122     error('Invalid trx_parm.con_file was specified..');
0123 end
0124 
0125 % set batch mode
0126 trx_parm.batch_mode = true;
0127 
0128 %
0129 % --- Trial Extraction
0130 %
0131 trx_parm = vb_trial_extractor_extract_trial(trx_parm);
0132 
0133 %
0134 % --- Label Trial by file
0135 %
0136 if isfield(trx_parm, 'label_spec') && exist(trx_parm.label_spec.label_file, 'file') == 2
0137     trx_parm = vb_trial_extractor_tag_by_file(trx_parm, trx_parm.label_spec);
0138 end
0139 
0140 %
0141 % --- Output Evoked MEG(EEG)-MAT
0142 %
0143 
0144 % output_file is initialized in vb_trial_extractor_extract_trial()
0145 % so reset the field here.
0146 trx_parm.output_file = output_file;
0147 
0148 if exist('output_file', 'var') && ~isempty(output_file)
0149     trx_parm.output_file = output_file;
0150 else
0151     warning('Cannot find output settings.');
0152     return;
0153 end
0154 
0155 % Output files
0156 vb_trial_extractor_output_file(trx_parm);
0157 
0158 
0159 
0160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0161 % inner functions(Under construction)
0162 %
0163 function err = inner_check_proc_spec(trx_parm)
0164 list = {'con_file', 'trigger_list', 'trial_setting', 'label_spec', 'output_file'};
0165 
0166 % Check top level parameters
0167 err = inner_check_fieldname(...
0168             'trx_parm', ...
0169             trx_parm, list);
0170 if err, return; end
0171 
0172 % Check second level parameters
0173 if isfield(trx_parm, 'label_spec')
0174     list = {'label_file', 'base_label'};
0175     err = inner_check_fieldname(...
0176             'trx_parm.label_spec',...
0177             trx_parm.label_spec, list);
0178     if err, return; end
0179 end
0180 if isfield(trx_parm, 'trigger_list')
0181     list = {''};
0182 end
0183 
0184 if isfield(proc_spec, 'output_file')
0185     list = {'label_name', 'output_file'};
0186     for k=1:length(proc_spec.output_file)
0187         err = inner_check_fieldname(...
0188             ['proc_spec.outputfile{' num2str(k), '}'], ...
0189             proc_spec.output_file{k}, list);
0190         if err, return; end
0191     end
0192 end
0193 
0194 function err = inner_check_fieldname(struct_name, structure, list)
0195 
0196 err = 0;
0197 names = fieldnames(structure);
0198 for k=1:length(names)
0199     hit = 0;
0200     for j=1:length(list)
0201         if strcmp(names{k}, list{j})
0202             hit = hit + 1;
0203         end
0204     end
0205     if hit == 0
0206         fprintf('Unknown field : %s\n', [struct_name '.' names{k}]);
0207         err = 1;
0208     end
0209 end

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