This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Use Peak Finder to Find Heart Rate from ECG Input

This example shows how to use the Time Scope Peak Finder panel to measure the heart rate from an ECG.

This model emulates an ECG heart rate.

To emulate a heart beat, the model imports the variable mhb from the MATLAB® workspace. This variable is created when the model loads because the commands that construct it are in the model Preload function. To view these commands, in the Simulink® menu, select File > Model Properties > Model Properties. The Model Properties dialog box appears. Click the Callbacks tab. The following lines of MATLAB® code appear.

x1 = 3.5*ecg(2700);
y1 = sgolayfilt(kron(ones(1,13),x1),0,21);
n = (1:30000)';
del = round(2700*rand(1));
mhb = y1(n + del);
ts = 0.00025;

ecg is a custom function that helps generate the heartbeat signal.

function x = ecg(L)
a0 = [0,  1, 40,  1,   0, -34, 118, -99,   0,   2,  21,   2,   0,   0,   0];
d0 = [0, 27, 59, 91, 131, 141, 163, 185, 195, 275, 307, 339, 357, 390, 440];
a = a0 / max(a0);
d = round(d0 * L / d0(15));
d(15) = L;
for i = 1:14
    m = d(i) : d(i+1) - 1;
    slope = (a(i+1) - a(i)) / (d(i+1) - d(i));
    x(m+1) = a(i) + slope * (m - d(i));
end

Run your model to see the time domain output.

  1. To show the Peak Finder panel, in the Time Scope menu, select Tools > Measurements > Peak Finder.

  2. To expand the Settings section, click the arrow next to the label.

  3. Enter 10 for Max Num of Peaks. The Time Scope Peaks section now displays a list of 10 peak amplitude values, and the times at which they occur.

The list of peak values show a constant time difference of 0.675 seconds between each heartbeat. Therefore, the heart rate of the ECG signal is 88.89 beats per min (bpm).