Home > bml > sync > bml_time2idx.m

bml_time2idx

PURPOSE ^

BML_TIME2IDX calculates sample indices from a time vector and file coordinates

SYNOPSIS ^

function idx=bml_time2idx(cfg, time, skipFactor)

DESCRIPTION ^

 BML_TIME2IDX calculates sample indices from a time vector and file coordinates

 Use as 
   idx=bml_time2idx(cfg, time)
   idx=bml_time2idx(cfg, time, skipFactor)

 time - numeric vector of times to transform to indices
 skipFactor - numeric, integer indicating skip factor as used by blackrock
     NPMK package. Defaults to 1. 

 where cfg is a configuration structure or roi table row
 cfg.t1
 cfg.s1
 cfg.t2
 cfg.s2
 cfg.nSamples - double: optional total number of samples in file

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function idx=bml_time2idx(cfg, time, skipFactor)
0002 
0003 % BML_TIME2IDX calculates sample indices from a time vector and file coordinates
0004 %
0005 % Use as
0006 %   idx=bml_time2idx(cfg, time)
0007 %   idx=bml_time2idx(cfg, time, skipFactor)
0008 %
0009 % time - numeric vector of times to transform to indices
0010 % skipFactor - numeric, integer indicating skip factor as used by blackrock
0011 %     NPMK package. Defaults to 1.
0012 %
0013 % where cfg is a configuration structure or roi table row
0014 % cfg.t1
0015 % cfg.s1
0016 % cfg.t2
0017 % cfg.s2
0018 % cfg.nSamples - double: optional total number of samples in file
0019 %
0020 
0021 pTT = 9; %pTT = pTimeTolerenace = - log10(timetol)
0022 
0023 if nargin==2
0024   skipFactor=1;
0025 elseif nargin==3
0026   skipFactor=round(skipFactor);
0027 else
0028   error('unsupported call to bml_time2idx, see usage');
0029 end
0030 
0031 t1=round(bml_getopt(cfg,'t1'),pTT);
0032 s1=ceil(bml_getopt(cfg,'s1')/skipFactor);
0033 t2=round(bml_getopt(cfg,'t2'),pTT);
0034 s2=floor(bml_getopt(cfg,'s2')/skipFactor);
0035 nSamples=bml_getopt(cfg,'nSamples');
0036 
0037 idx = round((t2*s1-s2*t1+(s2-s1).*round(time,pTT))/(t2-t1));
0038 
0039 if any(idx<=0); error('negative index'); end
0040 if ~isempty(nSamples)
0041   if any(idx>nSamples); error('index exceeds number of samples in file'); end
0042 end
0043   
0044   
0045   
0046

Generated on Tue 25-Sep-2018 10:08:19 by m2html © 2005