1

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.

Federico
  • 89
  • 1
  • 8

1 Answers1

0

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).

Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96
  • Well I can't really change the delay = 30/HR, because that alone is used to determine the duration from any one heart beat to the next next heart beat which is a measure of the heart beats per minute(Bpm) I have managed to find a solution by using pulstran with tripuls and setting the parameter to suit the delay constants. thanks – Federico Jul 02 '13 at 16:03
  • @user2527428: as I understood it, your `delay` variable should be equal to half of the time in seconds between two peaks, so in other words, simply `60/2/HR` or `30/HR`. But you got it working, that's the important part. – Rody Oldenhuis Jul 03 '13 at 06:38
  • Well for the current method I used, the condition still holds as shown in the above code! – Federico Jul 03 '13 at 11:13