finding peak value after minimum value

18 views (last 30 days)
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.

Accepted Answer

Mathieu NOE
Mathieu NOE on 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 Comments
Jan Kasparek
Jan Kasparek on 14 Mar 2022
sorry for late answer but.. thanks a lot, it helped

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!