Products & Services Solutions Academia Support User Community Company

Learn more about Signal Processing Toolbox   

findpeaks - Find local maxima

Syntax

pks = findpeaks(data)
[pks,locs] = findpeaks(data)
[...] = findpeaks(data,'minpeakheight',mph)
[...] = findpeaks(data,'minpeakdistance',mpd)
[...] = findpeaks(data,'threshold',th)
[...] = findpeaks(data,'npeaks',np)
[...] = findpeaks(data,'sortstr',str)

Description

pks = findpeaks(data)finds local maxima or peaks pks in the input data. data must be a row or column vector with real-valued elements and have a minimum length of three. findpeaks compares each element of data to its neighboring values. If an element of data is larger than both of its neighbors, it is a local peak. If there are no local maxima, pks is an empty vector.

[pks,locs] = findpeaks(data) returns the indices of the peaks.

[...] = findpeaks(data,'minpeakheight',mph) returns only peaks that exceed the real-valued scalar mph. mph defaults to -Inf.

[...] = findpeaks(data,'minpeakdistance',mpd) returns only peaks with indices separated by more than the positive integer mpd. mpd defaults to 1.

[...] = findpeaks(data,'threshold',th) returns only peaks that exceed their neighbors by greater than the nonnegative real scalar th. th defaults to 0.

[...] = findpeaks(data,'npeaks',np) returns a maximum number of peaks np. findpeaks operates from the first element of data and terminates when the number of peaks reaches np. By default, findpeaks returns all peaks meeting your criteria.

[...] = findpeaks(data,'sortstr',str) returns peaks in the order specified by the string str. 'ascend' returns peaks ordered from smallest to largest. 'descend' returns peaks ordered from largest to smallest. 'none' is the default and returns peaks in the order in which they occur in data.

Examples

Find peaks in a vector:

data = [2 12 4 6 9 4 3 1 19 7];
pks=findpeaks(data);
% returns the 1x3 vector [12 9 19];
 

Find peaks separated by more than three elements and return their locations:

data = [2 12 4 6 9 4 3 1 19 7];
[pks,locs]=findpeaks(data,'minpeakdistance',3);
% returns pks=[12 19]
% locs=[2 9]
  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS