Find peaks (maxima and minima) of a function
function [nmax,maxAt,maxValues,nmin,minAt,minValues] = peak(y,x,threshold,stepsize)
This function detects the transition points (maxima and minima) of a function like y = f(x), where x is indpendent variable and y is dependent variable. If there is no clue about x, then use x = [], which is an empty vector, and if so, it automatically defines x = 1:length(y).
Optional input arguments: threshold is the thresholding applied to y, and stepsize is the step size for computation of slopes. The smaller the stepsize is, the more accurate result is. By default stepsize = abs(x(1)-x(2))/10.
Finally, it returns, nmax: the number of peaks in y; maxAt: the x values at which peaks occur; maxValues: the peak values of y; nmin: number of minima in y; minAt: the x values at which minima occur; and
minValues: the minima of y; (all after thresholding, if any).
Examples 1: no threshodling
x = -pi:pi/100:pi;
y = sin(x)+cos(x.^2);
[nmax,maxAt,maxValues,nmin,minAt,minValues] = peak(y,x)
Example 2: thresholding at 0
x = -pi:pi/100:pi;
y = sin(x)+cos(x.^2);
[nmax,maxAt,maxValues,nmin,minAt,minValues] = peak(y,x,0)
引用格式
Shoaibur Rahman (2024). Find peaks (maxima and minima) of a function (https://www.mathworks.com/matlabcentral/fileexchange/48818-find-peaks-maxima-and-minima-of-a-function), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
- Signal Processing > Signal Processing Toolbox > Measurements and Feature Extraction > Descriptive Statistics >
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!