MATLAB: How to find peaks and troughs of a graph

findpeakspeaksplot

the function findpeaks will find the hall peaks (top and bottom), and I want to find the top peaks and bottom peaks separately. I know that I have to specify a limit (value) and say: if any number above this value consider it as peak, else consider it as trough, but I don't know how to transfer it into a matlab code? I am dealing with vectors: pks=findpeaks(RunUp.Set4(x,y)); x is time y is a second column in a file, this column contains the peaks, so I should play with numbers of this variable(y) to get the peaks and troughs Thanks

Best Answer

To get the troughs, use findpeaks on the negative of your signal, in a separate call to findpeaks. This turns the troughs into peaks, and findpeaks will locate them as well.
Related Question