FUNCTION REFERENCE
findpeaks
Find interior maxima, their locations, widths and prominences.
Find interior maxima, their locations, widths and prominences.
Syntax
[pks,locs,w,p] = findpeaks(y[,x],Name,Value,...)Syntax
findpeaks(y[,x],Name,Value,...)Use finite real vectors; x must increase strictly and match y. Without x, locations are one-based sample indices. Endpoints are excluded. A flat top uses its first sample. Prominence is peak height minus the higher of the two minima reached before a strictly higher sample or an endpoint; equal-height peaks do not stop the search. WidthReference 'halfprom' (default) measures width at peak height minus half its prominence, bounded by those minima. 'halfheight' uses half the absolute height and may extend to the signal endpoints; nonpositive peaks have zero half-height width. Crossings use linear interpolation in x. Widths and distances use x units.
Options: MinPeakHeight (default -Inf), MinPeakProminence (0), MinPeakDistance (0), Threshold (0), NPeaks (all), SortStr ('none', 'ascend', 'descend'), WidthReference ('halfprom', 'halfheight'), MinPeakWidth (0), MaxPeakWidth (Inf). MinPeakHeight is strict: a peak equal to the limit is excluded. Threshold requires both drops from a flat top to its adjacent samples to meet the threshold. Height, threshold, prominence and width gates precede greedy distance suppression. Tallest peaks win; ties choose the first sample. SortStr orders the surviving peaks before NPeaks truncation. All four outputs are row vectors. With no output, plot the signal and mark the selected peaks.
Example
[p,l,w,q] = findpeaks([0 2 0 1 0],'MinPeakProminence',1);Example
findpeaks([0 2 0 1 0]);Differences from MATLAB: finite real vectors only; flat tops and selection order follow the definitions above. No sample-rate scalar, datetime coordinates or annotation options. At most 1048576 samples; prominence, width and distance searches use bounded O(N log N) work and linear scratch storage.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.