How to Detect Peak in MATLAB

by Chris Daniels

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.

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);

2

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

[peak_value, peak_location] = findpeaks(my_signal);

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);

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);

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);

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);

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');

About the Author

Chris Daniels covers advances in nutrition and fitness online. Daniels has numerous certifications and degrees covering human health, nutritional requirements and sports performance. An avid cyclist, weightlifter and swimmer, Daniels has experienced the journey of fitness in the role of both an athlete and coach.

Photo Credits

  • photo_camera NA/AbleStock.com/Getty Images