Find peaks for a given 2D curve.
Versión 1.0.3 (32,4 KB) por
Peter Seibold
The code is very simple and needs only two lines of code.
Full call:
PeakValues=FindPeaksSimple(x,y,PeakType,Interpolate)
INPUT:
1 x: x-values. Vector with numbers.
2 y: y-values. Vector with numbers.
Optional values:
You may omit all off them or the trailing value.
3 PeakType: -1: only minima
0: minima and maxima (default)
1: only maxima
4 Interpolate: true or 1: parabolic interpolation
false or 0: no interpolation (default)
If the curve is noisy, you might consider to smooth it beforehand,
OUTPUT:
PeakValues: Array with peak x-positions and peak y-values
Empty PeakValues for no peak at all.
Processing time on my PC is:
No interpolation: 40us overhead + 17ns per sample.
Is for 10^6 samples: 17 ms.
With interpolation: 40us overhead + 17ns per sample + 34ns per peak.
Is for 10^6 samples with 3.4*10^5 peaks=28 ms
If you process always in the same manner, you can delete many code lines.
E.g. you want only nearest maxima:
PeakValues=FindPeaksSimpleMaxima(x,y)
PeakIndx = find(diff(sign(diff(y)))<0)+1;
PeakValues=[x(PeakIndx)',y(PeakIndx)'];
Or you want only maxima interpolated:
PeakValues=FindPeaksSimpleMaximaInterpolated(x,y)
PeakIndx = find(diff(sign(diff(y)))<0)+1;
y1=y(PeakIndx-1);%Left of peak
y2=y(PeakIndx);%At peak
y3=y(PeakIndx+1);%Right of peak
PeakPos=(x(2)-x(1))*(y3-y1)./(4*y2-2*y1-2*y3)+x(PeakIndx);
PeakMinMax=y2-(y3-y1).^2./(8*(y1-2*y2+y3));
PeakValues=[PeakPos(:),PeakMinMax(:)];
Citar como
Peter Seibold (2024). Find peaks for a given 2D curve. (https://www.mathworks.com/matlabcentral/fileexchange/114145-find-peaks-for-a-given-2d-curve), MATLAB Central File Exchange. Recuperado .
Compatibilidad con la versión de MATLAB
Se creó con
R2020a
Compatible con cualquier versión desde R2016a
Compatibilidad con las plataformas
Windows macOS LinuxEtiquetas
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Descubra Live Editor
Cree scripts con código, salida y texto formateado en un documento ejecutable.