I would use findpeaks on the negative of your signal:
[negpks, neglocs]= findpeaks( -aline );
Then take the first ‘neglocs’ value less than the maximum peak ‘locs’ value, and the first ‘neglocs’ value greater than the the maximum peak ‘locs’ value. Use the corresponding ‘negpks’ values (as ‘-negpks’) to find the values you want.
Example —
x = linspace(0, 10*pi);
aline = abs(sin(x-5*pi)./(x-5*pi))*7;
[pks, locs]= findpeaks(aline, 'MinPeakHeight',5);
[negpks, neglocs]= findpeaks( -aline );
minidx = find(neglocs < locs, 1, 'last');
maxidx = find(neglocs > locs, 1, 'first');
minloc = neglocs(minidx);
maxloc = neglocs(maxidx);
figure(1)
plot(x,aline,'-b', x(locs),pks,'^r')
hold on
plot(x([minloc maxloc]), aline([minloc maxloc]), 'vr')
hold off
Best Answer