MATLAB: Extract peaks and troughs from a curve

digital signal processingMATLAB

How to extract only peaks and troughs from a curve
2.jpg

Best Answer

If you want to identify the individual peaks and troughs, use islocalmax and islocalmin, or findpeaks on the positive and negative versions of your signal respectively:
[pks, pklocs] = findpeaks(s);
[troughs,trlocs] = findpeaks(-s);
where ā€˜sā€™ is youir signal vector.