how to find local minima of a graph like shown in the figure?

Hello Everyone,
I am trying to find local minima (to get x and y values) as circled in the figure..Any suggestion please as how to find the local minima (or x and y values for the lowest valley)? I tried to use findpeaks by inverting the plot but it gave me more number of points. Thank you!

 Risposta accettata

If you have R2017b or later release, the islocalmin (link) function is an option.
Your are correct in using findpeaks with your inverted (negated) signal to find the minima. There are a number of name-value pair arguments (such as 'MinPeakHeight' and 'MinPeakProminence') that can help in sorting your peaks.

7 Commenti

Thank you for your suggestion, I did try using islocalmin. It was working for some figures and it did not work for other.
My pleasure.
Without your data, and without knowing what result you want, it is not possible to write specific code for your problem.
For the data that islocalmin did not work with (note that it has a number of name-value pair arguments that could help you identify the minima you want), I would use findpeaks as you did previously (with your negated data), using the appropriate name-value pair arguments to get the result you want.
Okay. I am sharing you the data. Basically it has three columns, representing index finger movement in x, y and z directions. Like I said, I need to know the local minima (valley) in the z direction. Thank you once again for taking time and responding to my question.
Try this:
[D,S] = xlsread('file.xlsx');
xv = 1:size(D,1);
[pks,locs,widths,proms] = findpeaks(-D(:,3),xv);
wplv = (proms > 0.5) & (widths(:) > 200); % Width & Prominence Logical Vector
figure
plot(xv, D(:,3))
hold on
plot(locs(wplv), -pks(wplv), 'or')
hold off
grid
% text(locs(plv), -pks(plv), sprintfc('W = %.1f\nP = %.1f',[widths(plv); proms(plv)']'), 'FontSize',8)
I ended up using both the ‘widths’ and ‘proms’ outputs to determine the peak values to return and plot. This appears to get all the ones you are interested in:
how to find local minima of a graph like shown in the figure - 2019 05 10.png
It also gets the last one, however you can delete that by simply using (1:end-1) as the reference, for example: -pks(wplv(1:end-1)).
I commented-out the text call I used to help me determine the widths and prominences of the various peaks. I kept in the code so you can use it if you need to in order to change the ‘wplv’ logical conditions if the current ones do not work in your other data sets. (It displays the widths and prominences of each identified peak, as a valley, on the plot.)
If my Answer helped you solve your problem, please Accept it!
As always, my pleasure!

Accedi per commentare.

Più risposte (1)

gonzalo Mier
gonzalo Mier il 9 Mag 2019
Modificato: gonzalo Mier il 9 Mag 2019

1 Commento

Thank you! I did try using find peaks but it is not working for all the data (coming from different trials)

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by