Home > vbmeg > functions > device > eeg > biosemi > vb_util_sample2msectime2sample.m

vb_util_sample2msectime2sample

PURPOSE ^

convert sample number to time[msec] or time[msec] to sample number

SYNOPSIS ^

function [msec_time, sample_num] = vb_util_sample2msectime2sample(sample_num, msec_time, sample_frequency)

DESCRIPTION ^

 convert sample number to time[msec] or time[msec] to sample number
 [usage]
   [msec_time, sample_num] = vb_util_sample2msectime2sample( ...
     sample_num, msec_time, sample_frequency)
 [input]
         sample_num : <optional> [[]]
                    : if this is empty, it is tried to calculate sample number
          msec_time : <optional> [[]]
                    : if this is empty, it is tried to calculate time
   sample_frequency : <required> sampling frequency [Hz]
 [output]
          msec_time : calculated or given time list [msec]
         sample_num : calculated or given list of sample number
 [note]
   if 
 [history]
   2006-12-21 (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 [msec_time, sample_num] = vb_util_sample2msectime2sample( ...
0002   sample_num, msec_time, sample_frequency)
0003 % convert sample number to time[msec] or time[msec] to sample number
0004 % [usage]
0005 %   [msec_time, sample_num] = vb_util_sample2msectime2sample( ...
0006 %     sample_num, msec_time, sample_frequency)
0007 % [input]
0008 %         sample_num : <optional> [[]]
0009 %                    : if this is empty, it is tried to calculate sample number
0010 %          msec_time : <optional> [[]]
0011 %                    : if this is empty, it is tried to calculate time
0012 %   sample_frequency : <required> sampling frequency [Hz]
0013 % [output]
0014 %          msec_time : calculated or given time list [msec]
0015 %         sample_num : calculated or given list of sample number
0016 % [note]
0017 %   if
0018 % [history]
0019 %   2006-12-21 (Sako) initial version
0020 %
0021 % Copyright (C) 2011, ATR All Rights Reserved.
0022 % License : New BSD License(see VBMEG_LICENSE.txt)
0023 
0024 % --- CHECK ARGUMENTS --- %
0025 if ~exist('sample_num', 'var') sample_num = []; end;
0026 if ~exist('msec_time', 'var')  msec_time  = []; end;
0027 if ~exist('sample_frequency', 'var') sample_frequency = []; end;
0028 [sample_num, msec_time, sample_frequency] = ...
0029   inner_check_arguments( sample_num, msec_time, sample_frequency );
0030 
0031 % --- MAIN PROCEDURE --------------------------------------------------------- %
0032 %
0033 if isempty(sample_num) && ~isempty(msec_time)
0034   sample_num = (msec_time .* sample_frequency) ./ 1000;
0035 end
0036 
0037 if isempty(msec_time) && ~isempty(sample_num)
0038   msec_time = 1000 .* sample_num ./ sample_frequency;
0039 end
0040 %
0041 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0042 
0043 
0044 % --- INNER FUNCTIONS -------------------------------------------------------- %
0045 %
0046 % --- inner_check_arguments()
0047 %
0048 function [sample_num, msec_time, sample_frequency] = ...
0049   inner_check_arguments(sample_num, msec_time, sample_frequency);
0050 
0051 if isempty(sample_frequency)
0052   error('sample_frequency is a required parameter');
0053 end
0054 
0055 if isempty(sample_num) && isempty(msec_time)
0056   error('neighther sample_num nor msec_time are empty');
0057 end
0058 %
0059 % --- end of inner_check_argument()
0060 %
0061 % --- END OF INNER FUNCTIONS ------------------------------------------------- %
0062 
0063 %%% END OF FILE %%%

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