File Exchange

image thumbnail

peaks

version 1.0.0.0 (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 (https://www.mathworks.com/matlabcentral/fileexchange/7694-peaks), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)

Giorgia

UMP

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
x=xlsread('Data_Test.xls','A4:A65536');
y=xlsread('Data_Test.xls','B4:B65536');
%signal plot
figure
plot(x,y);
title('Ripple current');
xlabel('Time');
ylabel('Voltage');
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!

L J

Works well, exactly what I was looking for. Thanks

hi ya

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

J W

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?!
Thanks!

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!