File Exchange

image thumbnail

Find Peak Value

version (40 KB) by Geng Jun
Help you find peak value from a lot of data.


Updated 12 Dec 2003

No License

Editor's Note: This file was a File Exchange Pick of the Week

It's a simple function. Can help you find peak value from a lot of datas. It contains some demos.

It's my first time to submit file, thanks for your using.

Cite As

Geng Jun (2021). Find Peak Value (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (43)

Chirag Deb

This is amazing!, very helpful, thank you Geng Jun.


Takko Vendetti

Works great for my purpose.
Nevertheless I think minimum peaks get detected, too.

Takko Vendetti

Nur Muzammil

How do we modify this code to just find the minima/ valley point and ignore the maxima? Thank you.


how I define the number of peaks that I need the function to return. For example if I only need the first three peaks of data?



Thanks, It works great!

Jesse Sipple

Has anyone had any trouble finding the peaks for a vector that has both positive and negative values? Does not seem to be working with that.


About the input parameter,"Range":
Range is a 4-element vector:
[Xmin, Xmax, Ymin, Ymax]
Xmin: the lower x boundary of region of interest(ROI).
Xmax: the upper x boundary of ROI
Ymin and Ymax are the same as Xmin and Xmax.
For example,
find the peaks whose x are between 23 and 90 and their values is between 700 and inf.


I would be grateful if you put some explanation about the inputs. What is the input "Range"? and why is it a four-element vector?


Great performance.


Ah never mind... d'oh


Sorry if this is a dumb question, but where is this getPeak function that is called within this function?? I tried finding it on File Exchange and am not getting anything...



There is a bug in this program. when the peak/valley contains more than 1 point with same value, this program will just ignore this peak/valley.


David Jessop

Poorly explained, poor performance for large data sets and requires too much parameter tweaking in order to find peaks.

antonio Acampora

john Chandler

it doesn't work.

Change line 9 in ma.m to

and you will see that it picks peaks and valleys, both.

shilin guo

working perfect!!

Kristin Golmon

Doesn't work when there are two data matching values at the top of a peak. Other than that, perfect.

Vinh Nguyen Quang

Rishi Bansal

works like a charm!!!

Vlad Vlad

Excellent! Thank you

Estella Liu

This works great!! Thank you so much :)

Mukesh V.

this is the best that I found, relavent code

Sunil Arya

I found a very good m code to pick up the peak data.

Rory Gamble

I would really like to see a version of this that does functions of two wariables, eg extreme.m/extreme2.m

Linda Best

i found extreme.m is geat and also find peaks from surface: extreme2.m! But this was the first i used

Frederick Lu

Performance need improvements.

Bernard Grundlehner

Too slow on large sets of data. I prefer peakdetect.m

Alexandre Chirokov

I added small code (see below) to the getPeak function, now it works even better on my data.

if abs(y(i)-avg)<delta
delta = std(y)
avg = mean(y) it can be local std and mean with window equal to +-several values of "s"

ling lin

It saved my time.

Geng Jun

Hi,please contact me using this email address!

Tom Wang

Not sure if I'm using this correctly but I'm not getting accurate peaks at all. My call to the function is fpeak(1:129, data, 2). "data" has 129 values. I'm getting values of 4.0 0 next to 5.0 1, and 3.0 2. Any suggestions would be appreciated.

Peng Wang

I just need a function to find peaks. Thank you so much to solve my problem and save my time. It works great. The sensitivity is actually the half-width of the peak. A point is defined as a peak if its value is biger than that of any s points ahead and s points behind.

James McDonald

It worked perfectly for my example. Thanks!!

Ertu sariaslan

Thanks for solving my Problem !!!
But I dont understand the sensitivity, can anybody help me ???

Keven Chang

Great Job.

Barney de Villiers

Really Good!
Thanks, It helps me alot!

ma alex


Jiao Shibo

You are Genius!

gu wan

very good

MATLAB Release Compatibility
Created with R13
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!