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, and apply the Savitzky-Golay filter. 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;

For more information about the Savitzky-Golay filter, see the sgolayfilt function reference page or run the sgolaydemosgolaydemo example.

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 OK. The SPTool Signals list now contains a signal named ECG [vector].

  5. In SPTool, in the Signals list, select ECG [vector], and click the View 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.

Was this topic helpful?