
How would I find the first twelve local maximum (peak) values for y and the corresponding times using a script?
조회 수: 2 (최근 30일)
이전 댓글 표시
How would I find the first twelve local maximum (peak) values for y and the corresponding times (t) using a script?

댓글 수: 0
채택된 답변
Star Strider
2014년 11월 18일
If you don’t have the Signal Processing Toolbox, and since you have a clean, noise-free signal, this works:
x = linspace(0,20,250); % Create Data
y = exp(-0.25*x) .* sin(2.5*pi*x); % Create Data
dy = gradient(x,y); % Derivative: dy/dx
zx = dy.*circshift(dy, [0 -1]); % Zero-Crossings Of Derivative
pkix = find(zx<0); % Zero-Crossing Indices
pkix = pkix(y(pkix)>0); % Indices Of Peaks
xpks = x(pkix(1:12)); % X-Coordinates Of First 12 Peaks
ypks = y(pkix(1:12)); % Y-Coordinates Of First 12 Peaks
figure(1)
plot(x,y)
hold on
plot(xpks,ypks,'^r')
hold off

추가 답변 (1개)
Image Analyst
2014년 11월 18일
Do you have the Signal Processing Toolbox? If so, use findpeaks(). If not, check the File Exchange.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!