Home > vbmeg > functions > device > eeg > vb_eegfile_trial_ch_data.m

vb_eegfile_trial_ch_data

PURPOSE ^

Make trial data files after extracting trials from continuous raw data

SYNOPSIS ^

function result = vb_eegfile_trial_ch_data(proc_spec)

DESCRIPTION ^

 Make trial data files after extracting trials from continuous raw data
 [usage]
   result = vb_eegfile_trial_ch_data(proc_spec)
 [input]
   proc_spec : <required> <<struct>> struct defined process specifications
             :  .root_dir  : data directory for new eeg file and trig_file
             :             : <optional> ['.'] (current directory)
             :  .trig_file : <required> <<file>> trigger file name
             :             :  this file is expected to have data as follows:
             :             :   .trig [1 x Ntrial]
             :             :   .parm.data_file (without path)
             :             :   .parm.Pretrigger_ms
             :             :   .parm.Posttrigger_ms
             :  .new_file  : new EEG filename
             :             :  ['<root_dir>/
             :             :    <old_meg_file>_epoch_yymmdd-HHMMSS'.eeg.mat]
             :  .proc_parm :  <<struct>>
             :             :  .Pretrigger_ms  : Pretrigger period   [msec]
             :             :  .Posttrigger_ms : Posttrigger period  [msec]
                              if they are specified, 
                              they overwrite the setting values of trig_file
 [output]
      result : <<struct>> depends on current process
 [note]

 [history]
   2009-07-23 (Sako) initial version

 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 result = vb_eegfile_trial_ch_data(proc_spec)
0002 % Make trial data files after extracting trials from continuous raw data
0003 % [usage]
0004 %   result = vb_eegfile_trial_ch_data(proc_spec)
0005 % [input]
0006 %   proc_spec : <required> <<struct>> struct defined process specifications
0007 %             :  .root_dir  : data directory for new eeg file and trig_file
0008 %             :             : <optional> ['.'] (current directory)
0009 %             :  .trig_file : <required> <<file>> trigger file name
0010 %             :             :  this file is expected to have data as follows:
0011 %             :             :   .trig [1 x Ntrial]
0012 %             :             :   .parm.data_file (without path)
0013 %             :             :   .parm.Pretrigger_ms
0014 %             :             :   .parm.Posttrigger_ms
0015 %             :  .new_file  : new EEG filename
0016 %             :             :  ['<root_dir>/
0017 %             :             :    <old_meg_file>_epoch_yymmdd-HHMMSS'.eeg.mat]
0018 %             :  .proc_parm :  <<struct>>
0019 %             :             :  .Pretrigger_ms  : Pretrigger period   [msec]
0020 %             :             :  .Posttrigger_ms : Posttrigger period  [msec]
0021 %                              if they are specified,
0022 %                              they overwrite the setting values of trig_file
0023 % [output]
0024 %      result : <<struct>> depends on current process
0025 % [note]
0026 %
0027 % [history]
0028 %   2009-07-23 (Sako) initial version
0029 %
0030 % Copyright (C) 2011, ATR All Rights Reserved.
0031 % License : New BSD License(see VBMEG_LICENSE.txt)
0032 
0033 % --- CHECK ARGUMENTS --- %
0034 if ~exist('proc_spec', 'var'), proc_spec = []; end
0035 [proc_spec, trig_file, data_file] = inner_check_arguments(proc_spec);
0036 
0037 % --- MAIN PROCEDURE --------------------------------------------------------- %
0038 %
0039 result = [];
0040 
0041 trig = load(trig_file);
0042 
0043 % --- pretrigger / posttrigger
0044 if ~isempty(proc_spec.proc_parm)
0045   if isfield(proc_spec.proc_parm, 'Pretrigger_ms') ...
0046     && ~isempty(proc_spec.proc_parm.Pretrigger_ms)
0047     pretrigger_ms = proc_spec.proc_parm.Pretrigger_ms;
0048   else
0049     pretrigger_ms = trig.parm.Pretrigger_ms;
0050   end
0051   
0052   if isfield(proc_spec.proc_parm, 'Posttrigger_ms') ...
0053     && ~isempty(proc_spec.proc_parm.Posttrigger_ms)
0054     posttrigger_ms = proc_spec.proc_parm.Posttrigger_ms;
0055   else
0056     posttrigger_ms = trig.parm.Posttrigger_ms;
0057   end
0058 else
0059   pretrigger_ms  = trig.parm.Pretrigger_ms;
0060   posttrigger_ms = trig.parm.Posttrigger_ms;
0061 end
0062 
0063 load_spec.Trigger = trig.trig;
0064 
0065 % convert trigger data from msec to sample
0066 load_spec.Pretrigger  = ceil(pretrigger_ms *(fsamp/1000));
0067 load_spec.Posttrigger = ceil(posttrigger_ms *(fsamp/1000));
0068 
0069 load_spec.ChannelType = 'ALL';
0070 new_file = proc_spec.new_file;
0071 
0072 [eeg_data, ch_info] = vb_load_meg_data(data_file, load_spec, new_file);
0073 return;
0074 %
0075 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0076 
0077 % --- INNER FUNCTIONS -------------------------------------------------------- %
0078 %
0079 % --- inner_check_arguments()
0080 %
0081 function [proc_spec, trig_file, data_file] = inner_check_arguments(proc_spec)
0082 func_ = mfilename;
0083 
0084 if isempty(proc_spec)
0085   error('(%s) proc_spec is a required parameter', func_);
0086 end
0087 
0088 % --- proc_spec
0089 %  .root_dir
0090 %  .trig_file
0091 %  .new_file
0092 %  .proc_parm
0093 if ~isfield(proc_spec, 'root_dir') || isempty(proc_spec.root_dir)
0094   proc_spec.root_dir = '.';
0095 end
0096 
0097 if ~isfield(proc_spec, 'proc_parm') 
0098   proc_spec.proc_parm = [];
0099 end
0100 
0101 % --- check trigger file
0102 if ~isfield(proc_spec, 'trig_file') || isempty(proc_spec.trig_file)
0103   error('(%s) trig_file is a required field of proc_spec', func_);
0104 end
0105 
0106 trig_file = [proc_spec.root_dir '/' proc_spec.trig_file];
0107 
0108 if exist(trig_file, 'file') ~= 2
0109   error('(%s) cannot find proc_spec.trig_file : %s', ...
0110     func_, trig_file);
0111 end
0112 
0113 trig = load(trig_file);
0114 if ~isfield(trig, 'trig') || isempty(trig.trig)
0115   error('(%s) trig_file must have trig field', func_);
0116 end
0117 
0118 if isfield(trig, 'parm') && ~isempty(trig.parm)
0119   if isfield(trig.parm, 'data_file') && ~isempty(trig.parm.data_file)
0120     data_file = [proc_spec.root_dir '/' trig.parm.data_file];
0121   else
0122     error('(%s) trig_file.parm must have data_file field', func_);
0123   end
0124 else
0125   error('(%s) trig_file must have parm field', func_);
0126 end
0127 
0128 if exist(data_file, 'file') ~= 2
0129   error('(%s) cannot find data_file : %s', func_, data_file);
0130 end
0131 
0132 % --- new eeg file
0133 if ~isfield(proc_spec, 'new_file') || isempty(proc_spec.new_file)
0134   [fpath, fname] = vb_get_file_parts(data_file);
0135   proc_spec.new_file = ...
0136     sprintf('%s_epoch_%s.eeg.mat', fname, datestr(now, 'yymmdd-HHMMSS'));
0137 end
0138 return;
0139 %
0140 % --- end of inner_check_arguments()
0141 %
0142 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0143 
0144 %%% END OF FILE %%%

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