function [newhr, newhrt] = hrsample(hrt,fs,window)

if(nargin < 2)
    error('Function requires two parameters');
elseif (nargin < 3) 
    window = 1/(2*fs)*1000;
end
window
lasttime = max(hrt);
n = (lasttime-2*window)*fs;
samples = length(hrt);
T = 1/fs*1000;
min = 1;
for i = 1:1500
    newhrt(i) = T*i+window;
    newhr(i)  = 0;
    tmin = newhrt(i) - window;
    tmax = newhrt(i) + window;
    n = min;
    m = samples;
    while(n < m)
        if(hrt(n) < tmin)
            if(hrt(n+1) < tmin)
                min=n+1;
            elseif(hrt(n+1) >= tmax)
                newhr(i) = newhr(i) + (2*window)/(hrt(n+1)-hrt(n));
            else
                newhr(i) = newhr(i) + (hrt(n+1)-tmin)/(hrt(n+1)-hrt(n));
            end
        elseif(hrt(n) < tmax)
            newhr(i) = newhr(i) + (tmax-hrt(n))/(hrt(n+1)-hrt(n));
        elseif(hrt(n) >= tmax)
            m = n;
        end
        n=n+1;
    end
end
        
                
                
