findpeaks

Locate the peaks of a signal.

Syntax

[pks,locs,extra] = findpeaks(signal)

[pks,locs,extra] = findpeaks(signal,fs,...)

[pks,locs,extra] = findpeaks(signal,time,...)

[pks,locs,extra] = findpeaks(...,property,value,...)

[pks,locs,extra] = findpeaks(...,'DoubleSided')

Inputs

signal
The signal data, sampled at a constant rate.
Type: double
Dimension: vector
fs
The sampling frequency.
Type: double
Dimension: scalar
time
A vector of increasing, equally spaced times.
Type: double
Dimension: vector
property
A control on the identification of peaks. See Comments.
The available options are as follows:
  • 'MinPeakHeight' (Default: eps)
  • 'MinPeakDistance' (Default: 1 sample interval)
  • 'MinPeakWidth' (Default: 1 sample interval)
  • 'DoubleSided'
Type: string
value
The value associated with the preceeding property.
Type: double
Dimension: scalar

Outputs

pks
The peak values.
Type: double
Dimension: vector
locs
The locations at which the peaks are found.
Units of time will be used when the inputs include fs or time. For fs the times will be relative to 0. With no time input, sample indices are reported.
Type: double | integer
Dimension: vector
extra
Extra information related to peak widths based on fitted parabolas. See Comments.
Type: struct
  • parabol: a struct containing polynomial fitting information.
  • height: the estimated heights of the peaks.
  • baseline: the height at which the widths are estimated.
  • roots: the locations at which the parabolas intersect the baseline.

Examples

With sample count inputs and output locations:

[pks,locs] = findpeaks([2,5,6,8,3,9,6,4,6,12,2,6,8,10,5],'MinPeakHeight',7,'MinPeakWidth',0)
pks = [Matrix] 1 x 4
8  9  12  10
locs = [Matrix] 1 x 4
4  6  10  14

With time inputs and output locations:

[pks,locs] = findpeaks([2,5,6,8,3,9,6,4,6,12,2,6,8,10,5],10,'MinPeakHeight',0.7,'MinPeakWidth',0.0)
pks = [Matrix] 1 x 4
8  9  12  10
locs = [Matrix] 1 x 4
0.30000  0.50000  0.90000  1.30000

Comments

'MinPeakHeight' sets the peak height threshold.

'MinPeakDistance' sets the neighborhood threshold. Starting with the highest peak, other peaks within the specified half interval are ignored. The units are in time when the inputs include fs or time, and are in sample counts otherwise.

'MinPeakWidth' sets the width threshold. For each peak, a parabola is fitted to the points in its neighboorhood based on 'MinPeakDistance'. The width is then measured halfway between the peak height and the MinPeakHeight value. Peaks with widths narrower than the threshold are ignored. The units are in time when the inputs include fs or time, and are in sample counts otherwise.

'DoubleSided' indicates that data has positive and negative values, and that both positive and negative peaks are desired. For this property, there is no associated 'value' argument that follows and the 'MinPeakHeight' is relative to the mean.

extra.parabol is a struct containing matrices x and pp. x contains the neighborhood of each peak on which the parabola is fitted, and pp contains the parabola coefficients.

extra.baseline is the average of each peak and the 'MinPeakHeight' threshold.

In the presence of noise, parabola fitting to estimate peak widths is sensitive to the values associated with 'MinPeakDistance'. A poor fit might cause peaks to be omitted from the result.