MATLAB: How to find the first edge (not minimum value) after the peak

find non-minimum value edgepeaks

The subplot 1 shows a line profile across a density column. I want to find the radius of this column by getting the coordinate of peak(max) and the first edges. The problem is that the edge is not at minimum value, therefore I can't use min().
The subplot 2 is obtained from findpeaks().
figure; imagesc(FT_phase_shift), colorbar;title('Phase shift'); aline=FT_phase_shift(1:600,700); amax=max(aline);amin=min(aline) pmax =find(aline==amax(:,1));pmin=find(aline==amin(:,1));x_max = aline(pmax);
% find peaks and location [pks, locs]= findpeaks(aline); figure;subplot (211); plot(aline); subplot(212); plot(locs, pks);
Please comment.Thank you.

Best Answer

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); % Create Data

aline = abs(sin(x-5*pi)./(x-5*pi))*7; % Create Data
[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