File Exchange

image thumbnail


version (290 Bytes) by Nagi Hatoum
Find the peaks and troughs in a vector.

1 Download

Updated 10 Jun 2005

No License

A simple rugged script that finds the peaks and troughs of a signal, vector, or data points. The results are returned in two index vectors p and t.
Notice: Might drop end points or give two point where adjacent data have the same value.
Returns column-wise peak and through index vectors

Cite As

Nagi Hatoum (2021). peaks (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)



Nagi Hatoum:
Can you give me an example of peak.m.How I can adapt peak.m into my file? This is the command:

%imported data from excel sheet
%signal plot
title('Ripple current');
grid on

I really appreciate your help and also others response.

Nikola Stanchev

Excellent! The code is very helpful. Simple and genius.

Viprali Bhatkar

It is really helpful for finding peaks and troughs in any signal. Thank you!!

Dimitri Shvorob

Outdated - see other comments.

Ai Ve

Check out EXTREME.M on this site, it is a great improvement, also for 2D!


Works well, exactly what I was looking for. Thanks

hi ya

this is rubbish, just use Diff() and don't bother downloading


Is it possible to add a script/function to measure the absolute vertical distance between peaks and corresponding troughs?
Overall the function worked well identifying peaks and their horizontal location for me.

ravs sam

great code, could use comments!

Duane Hanselman

No usable help text provided. It is unclear what the function does without testing it. Poor programming practices.

Gao Jianqiang

In this article,can the author give me a example of the use of the peak.m.
Why can't I produce the same figure above?
Waiting for other friends help me?!

John Walters

Thanks, I don't have the latest Matlab version

James J. Cai

Xmax = find(diff(X,2)<0)==1)+1;
Xmin = find(diff(X,2)>0)==1)+1;

Sergei Koptenko

There are at least two entries in Matlab File Exchange- "Local min, max, nearest neighbour" from 2003-03-21 and "Find Peak Value" from 2003-12-10 that do exactly the same as this function.

Yuri Kotliarov

1. Function PEAKS exists in R14.
2. vector has to be a column.
3. Will those commands do the same thing?
Xmax = find(diff(diff(X)<0)==1)+1;
Xmin = find(diff(diff(X)>0)==1)+1;

MATLAB Release Compatibility
Created with R10
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!