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.
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;
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.
Under Workspace Contents, click mhb. Click the right arrow ( ) button to the left of the Data box.
Under Workspace Contents, click Fs. Click the right arrow ( ) button to the left of the Sampling Frequency box.
In the Name box, type ECG.
Click OK. The SPTool Signals list now contains a signal named ECG [vector].
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.
|Parameter||Display 1 Setting|
|Axes background color||Black|
|Ticks, labels, and grid colors||Dark Gray|
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.