Home > functions > common > utility > vb_time_to_index.m

vb_time_to_index

PURPOSE ^

Return sample number for given time (ms)

SYNOPSIS ^

function index = vb_time_to_index(time,meg_info)

DESCRIPTION ^

 Return sample number for given time (ms)

 --- Syntax
 index = vb_time_to_index(time,MEGinfo)

 --- History
 2008-10-30 Taku Yoshioka

 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:

SOURCE CODE ^

0001 function index = vb_time_to_index(time,meg_info)
0002 % Return sample number for given time (ms)
0003 %
0004 % --- Syntax
0005 % index = vb_time_to_index(time,MEGinfo)
0006 %
0007 % --- History
0008 % 2008-10-30 Taku Yoshioka
0009 %
0010 % Copyright (C) 2011, ATR All Rights Reserved.
0011 % License : New BSD License(see VBMEG_LICENSE.txt)
0012 
0013 sample_freq     = vb_meginfo_get_sampling_frequency(meg_info);
0014 Nsample         = vb_meginfo_get_sample_number(meg_info);
0015 pretrigger      = vb_meginfo_get_pre_trigger(meg_info);
0016 
0017 % sampling length(msec).
0018 sampling_length = 1000/sample_freq;
0019 
0020 % time list of sample points
0021 sampling_point = -(sampling_length * pretrigger) : sampling_length : ...
0022     (sampling_length * (Nsample-pretrigger-1));
0023 
0024 for k=1:length(time)
0025   if time(k) < min(sampling_point)
0026     time(k) = min(sampling_point);
0027   elseif time(k) > max(sampling_point)
0028     time(k) = max(sampling_point);
0029   end
0030 
0031   % Index of MEG data
0032   index(k) = min(find(sampling_point>=time(k)));
0033 end

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