Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make findpeak function detect the negative peaks not the positive ones

Tags:

arrays

matlab

I am wondering how can I make findpeak function detect the negative peaks not the positive ones, it detects the red peaks shown in the figure below and I need to detect the blue ones .. any ideas??

Many Thanks.

enter image description here

like image 870
SMH Avatar asked Nov 10 '14 04:11

SMH


1 Answers

As mentioned, you have to use -data.

Here is an example,

x = 0 : 1e-3 : 5*pi;
t = (0 : length(x)-1)*1e-3;
y = sin(x);
[p l] = findpeaks(y);
plot(t,y);hold on
plot(t(l),p,'ko','MarkerFaceColor','g');
[pn ln] = findpeaks(-y);
plot(t(ln),-pn,'ko','MarkerFaceColor','r');

gives,

enter image description here

like image 117
Rashid Avatar answered Nov 16 '22 04:11

Rashid