finding peak value after minimum value

18 Ansichten (letzte 30 Tage)
Jan Kasparek
Jan Kasparek am 7 Feb. 2022
Kommentiert: Mathieu NOE am 14 Mär. 2022
Hi,
I have data of Sound Pressure Level and I need to find first maximum (not global) after global minimum. I dont know if its clear, so I will show it at an example at picture attached. There is a global minimum (22.09) and I need to find value of peak right after (57.969). I cant use "min" command since the value of peak is not global maximum. Hope its clear now. Is there some way how I can do this?
Thanks in advance,
J.

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 7 Feb. 2022
hello
this would be my suggestion - I added also the local peak "before" the global min also for sake of convenience
clc
clearvars
% dummmy data
n = 50;
x = 1:n;
y = 5*rand(1,n) + 55;
y(22) = 10;
% find global min
[y_min,ind_min] = min(y);
x_min = x(ind_min);
% find all peaks
ind_peaks = find(islocalmax(y));
x_peaks = x(ind_peaks);
y_peaks = y(ind_peaks);
% find local maximum before and after global min
% local maximum before global min
tmp1 = find(x_peaks <= x_min,1,'last');
ind_before = ind_peaks(tmp1);
% local maximum after global min
tmp2 = find(x_peaks >= x_min,1,'first');
ind_after= ind_peaks(tmp2);
figure(1)
plot(x,y,x_min,y_min,'dk',x(ind_before),y(ind_before),'dg',x(ind_after),y(ind_after),'dr');
legend('data','global min','local max before','local max after');
ylim([0 1.25*max(y)]);
  2 Kommentare
Jan Kasparek
Jan Kasparek am 14 Mär. 2022
sorry for late answer but.. thanks a lot, it helped
Mathieu NOE
Mathieu NOE am 14 Mär. 2022
hello
my pleasure !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by