How to Detect Peak in MATLAB
by Chris DanielsMATLAB 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.
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);
Find peaks in your signal using the quadratic interpolation method of "findpeaks()":
[peak_value, peak_location] = findpeaks(my_signal);
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);
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);
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);
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);
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');
References
Photo Credits
- photo_camera NA/AbleStock.com/Getty Images