Documentation

This is machine translation

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

Find Peak Amplitudes in Signal Browser

This example shows how to use the Peak Finder panel in the SPTool Signal Browser to find heart rate, given an electrocardiogram (ECG) signal.

First, open SPTool by typing the following at the MATLAB® command line.

`sptool`

SPTool opens.

Using SPTool, you can import signals from variables in the MATLAB workspace. First, create an electrocardiogram (ECG) signal, sampled at 4 kHz. To create the signal, save this function definition in a file called `ecg.m`:

```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```
Now apply the Savitzky-Golay filter to the ECG signal. At the MATLAB command line, enter the following commands:

```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; Fs = 1/ts;```

To import the signal from these variables, in the SPTool menu, select File > Import. Alternatively, you can press the Ctrl+I keyboard shortcut. The Import to SPTool dialog box appears.

1. Under Workspace Contents, click `mhb`. Click the right arrow () button to the left of the Data box.

2. Under Workspace Contents, click `Fs`. Click the right arrow () button to the left of the Sampling Frequency box.

3. In the Name box, type `ECG`.

4. Click . The SPTool Signals list now contains a signal named `ECG [vector]`.

5. In SPTool, in the Signals list, select `ECG [vector]`, and click the button. The Signal Browser opens and displays the ECG signal.

Because you only selected one signal, the legend is not needed. Turn off the legend by clicking the Show All Legends () button. Then, use the Style dialog box to modify the appearance of the axes and the lines for the signal. In the Signal Browser menu, select View > Style.

ParameterDisplay 1 Setting
Axes background colorBlack
Ticks, labels, and grid colorsDark Gray
Line colorYellow

To show the Peak Finder panel, in the Signal Browser menu, select Tools > Measurements > Peak Finder. To expand the Settings pane, click the pane expand button () next to that label. In the Max Num of Peaks box, type `10` and press the Enter key. Signal Browser now displays in the Peaks pane a list of 10 peak amplitude values, and the times at which they occur, as shown in the following figure.

As you can see from the list of peak values, there is a constant time difference of 0.675 seconds between each heartbeat. Therefore, the heart rate detected by the ECG signal is given by the following equation.