lowest peak between two values

Hello
I need to find the lowest minimum peak between every maximum peak. As you can see in the image
every red peak has more than one green peak in between. I want the lowest one. (by the way I also need the lowest at the beginning and at the end). I should get 11 green peaks, no more.
How can I do? I make a total mix-mess in my head between the functions find, min, max and findpeaks.
function [pp,pn,lp,ln,keep] = AllPeaks(ang)
[pp,lp] = findpeaks(ang,'minpeakheight',1.1,'MinPeakDistance',150);
[pn,ln] = findpeaks(-ang,'minpeakheight',0.5,'MinPeakDistance',50); % réfléchir au 150. peut-on le réduire. regarde les différents plots
pn = -pn;
w2 =[];
[taille, w] = size(lp);
for i=1:1:taille-1
w2 = [w2; ln(ln>lp(i) & ln<lp(i+1))];
index_i = [];
[taille2, w3] = size(w2);
for i=1:1:taille2
index_i = [index_i; find(w2(i))];
end
keep = [];
[taille3, w4] = size(index_i);
for i=1:1:taille3-1
if (pn(i) < pn(i+1))
keep = [keep; pn(i)];
end
if (pn(i) > pn(i+1))
keep = [keep; pn(i+1)];
end
end
end
This code is repeating the values I want twice sometimes. So there is something I am double doing.
Thank you very much

Respuestas (1)

Walter Roberson
Walter Roberson el 11 de Dic. de 2015

0 votos

If you have a routine that can reliably find maximum peaks, then you can find the lowest minimum by asking the routine to find the maximum of negative one times the signal.

3 comentarios

Tshahé Anongba
Tshahé Anongba el 11 de Dic. de 2015
Hello I don't have a routine that can reliably find maximum peaks. I just ask what are the positif peaks. I just happen to be lucky the positive peaks are easier to find than the negative ones.
You're already doing it:
[pn,ln] = findpeaks(-ang,..............
Taking the negative basically inverts the signal so that your major valleys are now major peaks. You just need adjust the parameters to find big peaks, not little ones. It may help you if you plotted -ang to see what it looks like.
Adi Purwandana
Adi Purwandana el 16 de Abr. de 2023
Hello, I follow your suggestion...and it's fine. Anyway I'm doing this:
%peaks
[pks1,locs1] = findpeaks(A,D,'MinPeakProminence',4,'Annotate','extents');
findpeaks(A,D,'MinPeakProminence',4,'Annotate','extents'););
%lowest
[pks2,locs2] = findpeaks(-A,D,'MinPeakProminence',4,'Annotate','extents'););
findpeaks(-A,D,'MinPeakProminence',4,'Annotate','extents');
My question then is: how to put the lowest symbols attached to the first plot (pks1)? Because I need only a plot with the peak and lowest values in a plot (pks1 plot).

Iniciar sesión para comentar.

Preguntada:

el 10 de Dic. de 2015

Comentada:

el 16 de Abr. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by