Find peaks (maxima and minima) of a function

版本 1.1.0.0 (1.8 KB) 作者: Shoaibur Rahman
This function detects the transition points (maxima and minima) in a function like y = f(x)
703.0 次下载
更新时间 2016/1/28

查看许可证

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 版本兼容性
创建方式 R2014b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Descriptive Statistics 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.1.0.0

Change in function name as it was conflicting with a built-in function
Title made shorter
Change title

1.0.0.0