Change
delay = ((60/HR)/2)-(0.5*pulse_width);
into
delay = 30/HR;
tripuls
does not change anything to the time input t1
, so the pulse width should not be subtracted from the time vector.
You can see this is correct by setting
pulse_width = 60e-4;
% (try)
pulse_width = 60e-10;
% (try again)
You should see that your results slowly go more and more towards the correct HR (provided your external equipment is capable of handling such short pulses).