# How Does the Peak Detector VI Work?

Updated Aug 21, 2018

• LabVIEW

## Issue Details

How does the Peak Detector VI in LabVIEW work?

## Solution

The Peak Detector VI takes an array of points representing a signal and finds the locations, amplitudes, and second derivatives of any peaks or valleys in the signal. The VI is based on an algorithm that fits a quadratic polynomial to sequential groups of data points.

The width parameter determines the number of consecutive points to fit the data using a quadratic least squares fit. As such, the width roughly controls smoothing of the data when searching for peaks. If the data is noisy, you would want more smoothing (specifically, a larger width), and vice versa. The disadvantage of larger widths is that the position (and value) of the detected peak may turn out to be less accurate.

For fast moving signals and better tracking, use the minimum width of three. If a narrow width leads to errors due to noise, increasing the width may help, but a blurring of the detection could occur. For slower and noisier signals, you can expand the width, but do not increase it past the half-width of the peak or valley you are expecting.

The VI performs a quadratic fit on a window consisting of the number of data points specified in the width. It slides this window, performs the fit, slides the window, performs the fit, and so on. While doing the fit, the VI calculates the parameters of the quadratic fit. For the fit, it finds the second derivative, and checks to see if the slope changes, to determine if there is a peak or a valley.

For example, let us assume that there are 2000 points representing 2 cycles of a sine wave, with peaks at 250 and 1250 and valleys at 750 and 1750. Consider the second peak at 1250. It lies between the two valleys. This peak ranges from sample points 750 to 1750, with the max value at 1250. The distance between 750 & 1250, or 1250 & 1750, is known as the half-width of the peak (this is what the explanation in the LabVIEW VI Reference Manual refers to; it says that the maximum width should be no more than half of the half-width). Since the half-width in this case is 500, the maximum value of the width should be no more than 250.

For an example of peak detection, see: <LabVIEW>\Examples\Analysis\Peakxmpl.llb\Peak Detection and Display.vi