Find peaks for a given 2D curve.

버전 1.0.3 (32.4 KB) 작성자: Peter Seibold
The code is very simple and needs only two lines of code.
다운로드 수: 53
업데이트 날짜: 2022/7/21

라이선스 보기

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(:)];

인용 양식

Peter Seibold (2025). 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. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2020a
R2016a 이상 릴리스와 호환
플랫폼 호환성
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.3

Minor speed improvement.
Some changes in demo.

1.0.2

Minor changes in demo.

1.0.1

Corrected description

1.0.0