Solved!
% Function to Generate ECG of heart beat signal for specified duration
%---------------------------------------
function [Heartbeat,t] = ECG_Gen (HR,pulse_width,Amp,duration)
Fs = 48000;
delay = (60/HR);
t = 0 : 1/Fs : duration; % 48000 kHz sample freq for duration (secs)
d = 0 : delay : duration;
Heartbeat = Amp*pulstran(t,d,'tripuls',pulse_width);
I'm having problem outputting my generated Heart beat signals, when I play the signal using Sound in matlab and measure it on an external heart rate monitor. I get a different reading to the simulated value. But seem to be correct only at 60 Bpm to maybe 100 Bpm. Need to include heart rates up to 200 Bpm. In order words, I get a lot of unstable output at high Bpm.
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).