0001 function time=bml_idx2time(cfg, idx, skipFactor)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 pTT = 9;
0023
0024 if nargin==2
0025 skipFactor=1;
0026 elseif nargin==3
0027 skipFactor=round(skipFactor);
0028 else
0029 error('unsupported call to bml_idx2time, see usage');
0030 end
0031
0032 if istable(cfg)
0033 if height(cfg) > 1
0034
0035 assert(isempty(bml_annot_overlap(cfg(:,{'s1','s2'}))),...
0036 "cfg table contains overlapping segments of samples");
0037
0038 time = zeros(1,length(idx));
0039 for i=1:height(cfg)
0040 t1=round(cfg.t1(i),pTT);
0041 s1=cfg.s1(i);
0042 t2=round(cfg.t2(i),pTT);
0043 s2=cfg.s2(i);
0044 Fs=round((s2-s1)/round(t2-t1,pTT),pTT,'significat');
0045 if skipFactor > 1
0046 s1=ceil(s1/skipFactor);
0047 s2=floor(s2/skipFactor);
0048 t1=t1+(skipFactor-1)*0.5/Fs;
0049 t2=t2-(skipFactor-1)*0.5/Fs;
0050 Fs = round((s2-s1)/round(t2-t1,pTT),pTT,'significat');
0051 end
0052 idx_filt = idx>=s1 & idx<=s2;
0053 time(idx_filt) = double(idx(idx_filt))/Fs - 0.5/Fs + (s2*t1-t2*s1)/(s2-s1);
0054 end
0055 return
0056 end
0057 cfg=table2struct(cfg);
0058 end
0059
0060
0061 t1=round(bml_getopt(cfg,'t1'),pTT);
0062 s1=bml_getopt(cfg,'s1');
0063 t2=round(bml_getopt(cfg,'t2'),pTT);
0064 s2=bml_getopt(cfg,'s2');
0065 Fs = round((s2-s1)/round(t2-t1,pTT),pTT,'significant');
0066 if skipFactor > 1
0067 s1=ceil(s1/skipFactor);
0068 s2=floor(s2/skipFactor);
0069 t1=t1+(skipFactor-1)*0.5/Fs;
0070 t2=t2-(skipFactor-1)*0.5/Fs;
0071 Fs = round((s2-s1)/round(t2-t1,pTT),pTT,'significant');
0072 end
0073
0074 time = double(idx)/Fs - 0.5/Fs + (s2*t1-t2*s1)/(s2-s1);