function rr = myecg2hr(ecgt,ecg) lowpasscutoff = 500; highpasscutoff = 15; fs = 10/(ecgt(11)-ecgt(1)); n = 2; k = .04/14; w = floor(fs/5); b = fs*k/w; ecgfilt = lowpass(lowpasscutoff,fs,highpass(highpasscutoff,fs,ecg)); thresh = conv(abs(ecgfilt),ones([2*w,1]))*b; cond = ecgfilt > thresh(w:(length(ecgfilt)+w-1)); cond = diff(cond) == 1; rrt = ecgt(cond); rr = diff(rrt); subplot(311); hold off; plot(ecgt,ecgfilt,ecgt,thresh(w:(length(ecgfilt)+w-1))); hold on; stem(rrt,.5*ones(size(rrt)),'r'); subplot(312); plot(rrt(1:length(rr)), rr); [nt nv] = hrtach(0, rr*1000, ones(size(rr)), 64); subplot(313); plot(nt,nv); %axis([84 87 -0.1 0.1]);