View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Peak finding and measurement

4.8 | 22 ratings Rate this file 185 Downloads (last 30 days) File Size: 428 KB File ID: #11755 Version: 4.0
image thumbnail

Peak finding and measurement


Tom O'Haver (view profile)


20 Jul 2006 (Updated )

Functions to locate and measure the positive peaks and valleys in noisy data sets.

| Watch this File

File Information

A set of fast customizable functions for locating and measuring the peaks in noisy time-series signals. Adjustable parameters allow discrimination of "real" signal peaks from noise and background. Determines the position, height, and width of each peak by least-squares curve-fitting. It can find and count over 10,000 peaks per second, and find and measure 1800 peaks per second, in very large signals. Includes two interactive versions, one with mouse-controlled sliders and one with keyboard control, for adjusting the peak finding criteria in real-time. Self-contained demos show how it works. See for details.


This file inspired I Dpeak: Peak Identifier Function and Demo Functions For Peak Detection And Fitting..

MATLAB release MATLAB 7.8 (R2009a)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (47)
01 Aug 2016 ZHENG WANG

Very good code. Saved me!

22 Apr 2016 Tom O'Haver

Tom O'Haver (view profile)

Black Hawk, the line number you mentioned don't match up with the current version 5, so you probably have an older version.

One restriction of the current version is that x and y must be column vectors (size 1 x n) not row vectors. I'll fix that in the next version.

You can always find the latest versions of all my functions and scripts at

Comment only
21 Apr 2016 Tom O'Haver

Tom O'Haver (view profile)

Black Hawk, sorry I didn't see this earlier; evidently I am no longer getting email notifications and I don't go on the Matlab site very often. I'll check the errors you got. Make sure you have the latest version - some debugging has already been done. Do the demos in the internal help file not work?

Comment only
25 Mar 2016 Black Hawk

It appears like findpeaksb and findpeaksb3 have never been tested or debugged. That is extremely disappointing. There are just too many errors, and I tried debugging findpeaksb3 without success. Here are some basic examples for findpeaksb3:

- Line 164: why do you put "MeasuredError(peak)=Error" if Error is a 1x2 row vector? Or was it done on purpose..? That obviously gives the error message "In an assignment A(I) = B, the number of elements in B and I must be the same." So the line has to be modified to something like "MeasuredError(peak)=Error(1)", or "=Error(2)" depending on what you want.

- Lines 121, 236 and 151: why do you put "signal=[XXX',YYY']"? This makes a row vector of the independent variable concatenated with the dependent variable. Why didn't you simply choose "signal=[XXX,YYY]" so that signal is automatically a two-column matrix, 1st column=independent variable and 2nd column=dependent variable. That would also avoid the huge confusion when calling the peakfit function in which line 382 "if datasize(1)<datasize(2),signal=signal';end
" is not very useful...

- The cases when length(signal)=0 or 1 are not considered at all, yielding errors when these cases are encountered

Sorry for being very direct but I think the scripts should have been carefully tested and debugged prior to submission. It is very frustrating to spend time debugging from A to Z without success a code that one hasn't written.

Comment only
20 Feb 2016 arnold

arnold (view profile)

I posted the problem with val2ind and r2015b with your iPeak contribution but I guess it applies here as well.

Error: File: findpeaksb.m Line: 2168 Column: 29
Function with duplicate name "val2ind" cannot be defined.

there is a function like this in one of the matlab toolboxes and I think this might call this problem?

C:\Program Files\MATLAB\R2015b\toolbox\phased\phased

Comment only
11 Nov 2013 Tom O'Haver

Tom O'Haver (view profile)

Oops, I meant to say that the area/width ratio is 1.06447...

Comment only
09 Nov 2013 Tom O'Haver

Tom O'Haver (view profile)

There is a typo there on my part; the number should be 1.06447.... Here's why: The simplest expression for a Gaussian peak is y=exp(-x^2). This has a full-width at half maximum of 2 * sqrt(ln(2)=1.66561 and the area under the curve is sqrt(pi)= 1.77245. So the width/height ratio is 1.06447.... The peak area is proportional to both peak height and width. Therefore the area is 1.06447 * peak height * peak width. Hint: You can use Wolfram Alpha ( to do all the algebra for stuff like that.

Comment only
04 Nov 2013 CC

CC (view profile)

Dear Tom,
Sorry about this really basic question, but could you please explain to me the reasoning behind calculating the area of the peak using 1.0646 * peak height * peak width? I'm not sure where the 1.0646 value comes from.

Many thanks

Comment only
07 Sep 2013 Rahul Mohan

14 Jul 2013 Tom O'Haver

Tom O'Haver (view profile)

Iman, you can use File > Import Data to import data files in various format, including three sound formats (.au, .snd, and .wav). These is also a Data Acquisition Toolbox that I would assume has additional data import capabilities.

Comment only
14 Jul 2013 iman

iman (view profile)

How can i import the signal from the file? such as sound file or RF signal

Comment only
08 Jun 2013 Tom O'Haver

Tom O'Haver (view profile)


As you requested, I have created variants of findpeaks that compute the peak start and end positions. See
I'll include these in the next update of fileexchange entry.

Comment only
22 Mar 2013 Dan

Dan (view profile)

Tom, it works very well for me. Thank you!
The start and the end position of the peaks would also help me… the definition of 1% of the peak amplitude would be great.

09 Jan 2013 Tom O'Haver

Tom O'Haver (view profile)

Dieter, I would be glad to add that if you could define quantitatively what you mean by peak start and end - for example, when the amplitude of the signal reaches 1% of the peak amplitude. Or would some other definition be more appropriate for your work?

Comment only
08 Jan 2013 Dieter K.

It is really good and easy to use. Only one thing I miss: The start and end position of the peaks would be really helpful.

26 Jun 2012 Tom O'Haver

Tom O'Haver (view profile)

Andre, iPeak reports only the position, height, and width of peak parameterized as Gaussians, not the parabolic results of polyfit. But you can generate the Gaussian model from height.*exp(-((x-position)./(0.6005615.*width)) .^2) and plot it over the raw data. iPeak does this automatically for the peaks detected in the upper window.

Comment only
26 Jun 2012 Andre

Andre (view profile)

This works really well for me, thanks!

One quick question: I would like to overlay the fitted parabola onto the raw data that I used findpeaks on, for visualization purposes (and to show that the fits are reasonable).

I tried going into the function and doing polyval on the coefs that are returned by polyfit, but this doesn't produce anything sensible.

I would like the drawn parabola to have the same units as the original data. Perhaps I could re-create the parabola from the output of findpeaks (ie the width, height, mean, etc), but it seems that polyval and other parabola drawers parameterize the parabolas in other ways.

Any ideas on which way to go??? Thanks!


03 Jun 2012 mitra devkota

Dear MATLAB users, I have x and y as vectors, I plotted them and now I need to detect the peaks and also find the corresponding peak locations. How can I do it?
Thanks in advance,

Comment only
31 Mar 2012 zaidan

zaidan (view profile)

great code for beginner

06 Sep 2011 mohammad

thanks a lot Tom
this code is so useful

06 Sep 2011 Tom O'Haver

Tom O'Haver (view profile)

When looking at a signal for the first time, it is best to use iPeak.m, iSignal.m, or ipf.m to inspect the data interactively. All of these can be downloaded from the Matlab File Exchange or from

Use the "pan and zoom" capabilities of these programs to inspect the whole signal closely. If the signal has important features that cover a very wide amplitude range or are superimposed on a much larger baseline or background, then those features may not be visible when the entire signal is plotted normally. Try using a semilog(x,y) plot, or use iSignal's semilog mode (H key).

Comment only
05 Sep 2011 mohammad

i have a .xls file, i saved data of that in a matrix like : r=xlsread(.xls)
now its needed to find peaks but this discrete data (r) is noisy data and using of 'findpeaks' command give me a lot of numbers of peaks (because of nois).
i think your code can help me. so, could you tell me how can i use this?
best regard

Comment only
03 Sep 2011 Tom O'Haver

Tom O'Haver (view profile)

I am not exactly sure what you mean by "matrix (discrete) wave" .Please explain.

Comment only
02 Sep 2011 mohammad

dear how can i use this for a matrix (discrete) wave?

02 Sep 2011 Tom O'Haver

Tom O'Haver (view profile)

See for a version that includes iterative curve fitting to selected peak shapes.

Comment only
04 Jun 2011 Tom O'Haver

Tom O'Haver (view profile)

See for a version that uses keyboard control and that works in recent versions of Matlab.

Comment only
12 Feb 2010 Andre Guy Tranquille

05 Jan 2010 ZULIN

ZULIN (view profile)

19 Aug 2009 Michael Coen

And comment out line 372 of rtslid.m as well... :)

Comment only
19 Aug 2009 Michael Coen

Ah, commenting out line 337 of rtslid.m:


eliminates crashes for later versions of Matlab...

19 Aug 2009 Michael Coen

Very nifty idea but it crashes quickly in Matlab 2008b, 2009a, and 2009b. There are clearly some GUI incompatibilities.

Comment only
17 Apr 2009 Tom O'Haver

Tom O'Haver (view profile)

Latest version just uploaded corrects a bug in the FindPeakSlidersG script that caused a malfunction when individual peaks are viewed if the x-axis data series does not start with zero.

Comment only
21 Jun 2008 Christof Devriendt

Just what I needed! Thank you very much!

29 Apr 2008 Ralph Ernstorfer

fast and reliable tool ... thanks for sharing!

11 Jan 2008 Julius Kusuma

Very useful interactive software! Thanks for sharing this.

20 Nov 2007 Hugo Banziger

Please gat back to me with your private phone number.

Dr. Hugo.

Comment only
06 Nov 2007 Karan Jain

This is a good algorithm but can it be changed to give peeks over a certain datum instead of the trough values.

10 Sep 2007 Li XinBo

Your algorithm is excellent.But I find a problem in it.
Your algorithm is limited only when the data are positive number.If all the data are negative and there is peak points.Your algorithm can't detect the peak points.
But I can translate the coordinate axis.
It is to make all the y data into positive number. Then using your algorithm we can find the peak points.
I think you can modify your algorithm and make it adapt to the situation that the data is all negative number.
If you can modify your algorithm,please send the message to my email.(
Thank your.
A student from BIT of China

03 May 2007 Matthew Butcher

You saved my MEng project with this one. I credited you thogh, don't worry.
Many thanks Tom,

12 Apr 2007 Tom Driscoll

Perfect for scientific data processing. Good performance without being overly complicated. You just saved me a week of my time.

20 Jan 2007 Dmitry Kazachk

Would be greate if it will do deconvolution and gave the areas for deconvolved peaks.
In general - great tool!

Comment only

14 Oct 2006 Tom O'Haver

K. Tampa is correct; extreme.m is the one to use if you want to find ALL the minima and maxima. But "Peak finding and measurement" is intended to distinguish real peaks from noise in experimentally measured signals and to measure their height, position, and width. Two completely different purposes.

Comment only
03 Oct 2006 mcs swamy

15 Sep 2006 K. Tampa

Get EXTREME.M in this site and you'll find the ALL peaks (minima and maxima!) of
rand(10^6,1) in less than a second, 10^7 in about 10 sec, and from matrix too, so...

24 Aug 2006 Tom O'Haver

Version 1.2, dated August 24, 2006, is even faster than the previous version It can find and measure 1000 peaks in a 1,000,000 point signal in 13 seconds.

Comment only
20 Aug 2006 Frank Anold

It is pretty good and easy to use. Yet some commercial software,such as origin, can do faster.


Add or update the screenshot

24 Jul 2006

replace missing function in ZIP file

02 Aug 2006

Add or update the screenshot
Bug fixes

22 Aug 2006

Bug fixes and enhancements (Version 1.1)

25 Aug 2006

Enhancements: Version 1.2 is a faster version of the original findpeaks function.

18 Sep 2006

Change to file details (title, description, requirements, ...),
Bug fixes.

22 Sep 2006

Change to file details (title, description, requirements, ...)

24 Oct 2006

Change to file details

01 Nov 2006


17 Apr 2009 1.1

Fixes a bug in the FindPeakSlidersG script that caused a malfunction in the individual peak viewing mode when the x-axis data series did not start at zero.

03 Sep 2009 1.3

The rtslid.m function in this version has been
modified by commenting out lines 337 and 373
to prevent crashs on Matlab 20078 and 2009,
as recommended by Michael Coen's comment on

12 Sep 2011 1.4

Includes the version 3.2 update of iPeak and version 4 of findpeaks.m, as well as the older 2008 version with sliders.

20 Sep 2011 1.5

Bug fix

28 Oct 2011 1.8

This version includes the findvalleys function and version 3.81 of the interactive iPeak function.

09 May 2012 1.10

This zip file includes version 3.9 of the interactive iPeak function.

09 May 2012 1.11

Typo correction.

31 Aug 2012 1.13

This version includes some additional demos plus version 4 of the interactive iPeak function.

28 Dec 2012 1.14

Version 5 has faster jumps between peaks with spacebar and tab keys; other small bug fixes.

20 May 2013 1.16

This version includes new command-line functions findpeaksplot.m, findpeaksnr.m, and peakstats.m. plus version 5.3 of iPeak.

11 Jun 2013 1.17

This version includes findpeaksL.m for Lorentzian peaks, and findpeaksGSS.m and findpeaksLSS that compute the 1% start and end positions.

14 Nov 2013 1.18

This version includes updated versions of findpeaksfit.m and findpeaksb.m.

24 Apr 2015 1.19

This version includes updated versions of several functions.

24 Oct 2015 2.0

This version contains several small corrections, additions, and bug fixes.

20 Apr 2016 3.0

Bug fixes and speed improvements.

22 Apr 2016 3.1

Bug fix. Data vectors x and y can be either column or row vectors.

02 May 2016 3.2

Included version 7.7 of iPeak.

04 May 2016 3.3

Bug fix

08 Feb 2017 4.0

Added several new functions including measurepeaks, autofindpeaks, and autopeaks plus test scripts for each.

Contact us