findpeaks_extents_fpeaks¶
- findpeaks_extents_fpeaks(Yin, varargin)¶
FINDPEAKS Find local peaks in data PKS = FINDPEAKS(Y) finds local peaks in the data vector Y. A local peak is defined as a data sample which is either larger than the two neighboring samples or is equal to Inf.
[PKS,LOCS]= FINDPEAKS(Y) also returns the indices LOCS at which the peaks occur.
[PKS,LOCS] = FINDPEAKS(Y,X) specifies X as the location vector of data vector Y. X must be a strictly increasing vector of the same length as Y. LOCS returns the corresponding value of X for each peak detected. If X is omitted, then X will correspond to the indices of Y.
[PKS,LOCS] = FINDPEAKS(Y,Fs) specifies the sample rate, Fs, as a positive scalar, where the first sample instant of Y corresponds to a time of zero.
[…] = FINDPEAKS(…,’MinPeakHeight’,MPH) finds only those peaks that are greater than the minimum peak height, MPH. MPH is a real-valued scalar. The default value of MPH is -Inf.
[…] = FINDPEAKS(…,’MinPeakProminence’,MPP) finds peaks guaranteed to have a vertical drop of more than MPP from the peak on both sides without encountering either the end of the signal or a larger intervening peak. The default value of MPP is zero.
[…] = FINDPEAKS(…,’Threshold’,TH) finds peaks that are at least greater than both adjacent samples by the threshold, TH. TH is a real-valued scalar greater than or equal to zero. The default value of TH is zero.
FINDPEAKS(…,’WidthReference’,WR) estimates the width of the peak as the distance between the points where the signal intercepts a horizontal reference line. The points are found by linear interpolation. The height of the line is selected using the criterion specified in WR:
- ‘halfprom’ - the reference line is posit1d beneath the peak at a
vertical distance equal to half the peak prominence.
- ‘halfheight’ - the reference line is posit1d at one-half the peak
height. The line is truncated if any of its intercept points lie beyond the borders of the peaks selected by the ‘MinPeakHeight’, ‘MinPeakProminence’ and ‘Threshold’ parameters. The border between peaks is defined by the horizontal position of the lowest valley between them. Peaks with heights less than zero are discarded.
The default value of WR is ‘halfprom’.
[…] = FINDPEAKS(…,’MinPeakWidth’,MINW) finds peaks whose width is at least MINW. The default value of MINW is zero.
[…] = FINDPEAKS(…,’MaxPeakWidth’,MAXW) finds peaks whose width is at most MAXW. The default value of MAXW is Inf.
[…] = FINDPEAKS(…,’MinPeakDistance’,MPD) finds peaks separated by more than the minimum peak distance, MPD. This parameter may be specified to ignore smaller peaks that may occur in close proximity to a large local peak. For example, if a large local peak occurs at LOC, then all smaller peaks in the range [N-MPD, N+MPD] are ignored. If not specified, MPD is assigned a value of zero.
[…] = FINDPEAKS(…,’SortStr’,DIR) specifies the direction of sorting of peaks. DIR can take values of ‘ascend’, ‘descend’ or ‘none’. If not specified, DIR takes the value of ‘none’ and the peaks are returned in the order of their occurrence.
[…] = FINDPEAKS(…,’NPeaks’,NP) specifies the maximum number of peaks to be found. NP is an integer greater than zero. If not specified, all peaks are returned. Use this parameter in conjunction with setting the sort direction to ‘descend’ to return the NP largest peaks. (see ‘SortStr’)
[PKS,LOCS,W] = FINDPEAKS(…) returns the width, W, of each peak by linear interpolation of the left- and right- intercept points to the reference defined by ‘WidthReference’.
[PKS,LOCS,W,P] = FINDPEAKS(…) returns the prominence, P, of each peak.
FINDPEAKS(…) without output arguments plots the signal and the peak values it finds
FINDPEAKS(…,’Annotate’,PLOTSTYLE) will annotate a plot of the signal with PLOTSTYLE. If PLOTSTYLE is ‘peaks’ the peaks will be plotted. If PLOTSTYLE is ‘extents’ the signal, peak values, widths, prominences of each peak will be annotated. ‘Annotate’ will be ignored if called with output arguments. The default value of PLOTSTYLE is ‘peaks’.
% Example 1: % Plot the Zurich numbers of sunspot activity from years 1700-1987 % and identify all local maxima at least six years apart load sunspot.dat findpeaks(sunspot(:,2),sunspot(:,1),’MinPeakDistance’,6) xlabel(‘Year’); ylabel(‘Zurich number’);
% Example 2: % Plot peak values of an audio signal that drop at least 1V on either % side without encountering values larger than the peak. load mtlb findpeaks(mtlb,Fs,’MinPeakProminence’,1)
% Example 3: % Plot all peaks of a chirp signal whose widths are between .5 and 1 % milliseconds. Fs = 44.1e3; N = 1000; x = sin(2*pi*(1:N)/N + (10*(1:N)/N).^2); findpeaks(x,Fs,’MinPeakWidth’,.5e-3,’MaxPeakWidth’,1e-3, …
‘Annotate’,’extents’)
See also MAX, FINDSIGNAL, FINDCHANGEPTS.