How to Detect Peak in MATLAB

By Chris Daniels

MATLAB functions can find peaks, also known as local maxima.
i NA/AbleStock.com/Getty Images

MATLAB is a technical software package that can be used for signal processing and analysis. A common procedure in signal analysis is peak detection, or finding local maxima -- values larger than adjacent data points -- within a noisy signal. It is usually necessary to limit peak detection to local maxima of a certain width -- duration when the signal is in the time domain -- as well as a certain height or magnitude.

Step 1

Define a data source by importing data into MATLAB. For example, create a sine wave with random noise:

my_signal = sin(0:0.1:10) + rand(1,101);

Step 2

Find peaks in your signal using the quadratic interpolation method of "findpeaks()":

[peak_value, peak_location] = findpeaks(my_signal);

Step 3

Search for peaks of a minimum height using the "minpeakheight" parameter. The height is a real-valued scalar that refers to the minimum data value of allowable peaks:

[peak_value, peak_location] = findpeaks(my_signal,'minpeakheight',2.5);

Step 4

Search for peaks separated by a minimum distance using the "minpeakdistance" parameter. The value is the minimum number of indices between peaks in the "my_signal" vector, and must be an integer:

[peak_value, peak_location] = findpeaks(my_signal,'minpeakdistance',5);

Step 5

Search only for peaks above a certain threshold using the "threshold" parameter. This is a real-valued scalar that refers to the minimum allowable difference between peak and adjacent data points:

[peak_value, peak_location] = findpeaks(my_signal,'threshold',0.5);

Step 6

Find only a certain number of peaks using the "npeaks" parameter. The value must be an integer:

[peak_value, peak_location] = findpeaks(my_signal,'npeaks',5);

Step 7

Sort the returned list of peaks using the "sortstr" parameter. Allowable values are "ascend," "descend" and "none":

[peak_value, peak_location] = findpeaks(my_signal,'sortstr','ascend');

×