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.
- fs
- The sampling frequency.
- time
- A vector of increasing, equally spaced times.
- property
- A control on the identification of peaks. See Comments.
- value
- The value associated with the preceeding property.
Outputs
- pks
- The peak values.
- locs
- The locations at which the peaks are found.
- extra
- Extra information related to peak widths based on fitted parabolas. See Comments.
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.