How to make findpeak detect negative peaks rather than positive

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

Many thanks.

enter image description here

+6
source share
1 answer

As mentioned, you should 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

+6
source

All Articles