function [nt,nv] = hrtach(starttime,rrintervals,labels,sr,ecgt)

% [nt,nv] = hrtach(starttime,rrintervals,labels,sr)
% assumes the rr itervals are in milliseconds
bpm = 60*1000./rrintervals;
bpmt = starttime + [0; cumsum(rrintervals)/1000];  % in seconds
bpmt = (bpmt(2:end)+bpmt(1:end-1))/2;
if(nargin < 5)
    nt = [0:(1/sr):(max(bpmt))];    
else
    nt = ecgt;
end
%nv = spline([nt(1); bpmt; nt(end)],[0;bpm(1); bpm; bpm(end); 0],nt);
rr2 = spline([nt(1); bpmt; nt(end)], [0;rrintervals(1);rrintervals;rrintervals(end);0],nt);
nv = 60*1000./rr2;
%plot(nt,nv,bpmt,bpm)
%pause