Code covered by the BSD License

### Highlights from iPeak: Interactive Peak Detector (Version 7.1)

4.77778
4.8 | 9 ratings Rate this file 32 Downloads (last 30 days) File Size: 250 KB File ID: #23850 Version: 1.38

# iPeak: Interactive Peak Detector (Version 7.1)

### Tom O'Haver (view profile)

21 Apr 2009 (Updated )

Keypress operated interactive peak detector function.

File Information
Description

iPeak is a keyboard-operated Interactive Peak Finder for time series
data. Expected input forms:
ipeak(y); % Data in single y vector')
ipeak(x,y); % Data in separate x and y vectors')
ipeak(DataMatrix); % Data in two columns of DataMatrix')
ipeak(x,y,10), ipeak([x;y],10) or ipeak(y,10), specifying peak density, PeakD
ipeak(DataMatrix,PeakD,AmpT,SlopeT,SmoothW,FitW) specifying peak density, AmpT, SlopeT, SmoothW, FitW')
ipeak(DataMatrix,PeakD,AmpT,SlopeT,SmoothW,FitW,xcenter,xrange) Adding pan and zoom settings ')
ipeak(DataMatrix,PeakD,AmpT,SlopeT,SmoothW,FitW,xcenter,xrange,Autozero) Adding Autozeo as 9th argument')

EXAMPLE 1: One input argument; data in single vector
>> y=cos(.1:.1:100);ipeak(y)

EXAMPLE 2: One input argument; data in two columns of a matrix
>> x=[0:.01:5]';y=x.*sin(x.^2).^2;M=[x y];ipeak(M);

EXAMPLE 3: Two input arguments; data in separate x and y vectors
>> x=[0:.1:100];y=(x.*sin(x)).^2;ipeak(x,y);

EXAMPLE 4: Additional input argument (after the data) to control peak
sensitivity.
>> x=[0:.1:100];y=5+5.*cos(x)+randn(size(x));ipeak(x,y,10);
or >> ipeak([x;y],10); or >> ipeak(humps(0:.01:2),3)
or >> x=[0:.1:10];y=exp(-(x-5).^2);ipeak([x' y'],1)
T. C. O'Haver (toh@umd.edu), Version 7.1 adds improved Octave compatibility and includes 33 model peak shapes for curve fitting.
http://terpconnect.umd.edu/~toh/spectrum/PeakFindingandMeasurement.htm

Acknowledgements

This file inspired Demo Functions For Peak Detection And Fitting..

MATLAB release MATLAB 7.8 (R2009a)
MATLAB Search Path
```/
/ipeak7```
23 Jan 2015 Tom O'Haver

### Tom O'Haver (view profile)

Amir, you could delete all the "plot(", "subplot(", "xlabel", "ylabel", and "title" statements in the code. Or you could use the findpeaksG.m function instead of ipeak.m, which does not plot but only returns the peak table.

Comment only
23 Jan 2015 amir afrashtehpour

### amir afrashtehpour (view profile)

hello
it really works great
i have a question
i want to run this program in a loop (the ipeak.m)
i have done that and it works great.
but i don't need the code to plot it i just want the "ans" data
how to modify the code to turn of plotting
is it possible for you to change the code so the ipeak.m take a function like yes or no as input argument to wether plot the data or not
thanks

09 Jun 2014 arnold

### arnold (view profile)

what is the "width" this function gives for a gaussian fit i.e.? it is not n*sigma, so I'm at a loss ATM.

=======
nevermind, I got it .... FWHM

Comment only
19 Feb 2014 Jochen

### Jochen (view profile)

Fantastic work! Thanks a lot!

Comment only
19 Feb 2014 Jochen

### Jochen (view profile)

10 Feb 2014 Tom O'Haver

### Tom O'Haver (view profile)

Oops, I forgot to include that function. I'll fix it, but in the meantime, here it is:

function [index,closestval]=val2ind(x,val)
% Returns the index and the value of the element of vector x that is closest to val
% If more than one element is equally close, returns vectors of indicies and values
% Tom O'Haver (toh@umd.edu) October 2006
% Examples: If x=[1 2 4 3 5 9 6 4 5 3 1], then val2ind(x,6)=7 and val2ind(x,5.1)=[5 9]
% [indices values]=val2ind(x,3.3) returns indices = [4 10] and values = [3 3]
dif=abs(x-val);
index=find((dif-min(dif))==0);
closestval=x(index);

Comment only
10 Feb 2014 aoli ao

### aoli ao (view profile)

Thanks so much for sharing this useful toolbox. I have a question here. when I tried to run ipeakdemo2.m or DemoFindPeaksb.m, it kept saying
??? Undefined function or method 'val2ind' for input arguments of type 'double'.

so how should do with this problem? Thanks for your help!

Comment only
05 Feb 2014 Tom O'Haver

### Tom O'Haver (view profile)

iPeak version 5.9, submitted this morning, adds the percent fitting as the 6th column of the peak table. Thanks to helin for making this suggestion. Also available on http://terpconnect.umd.edu/~toh/spectrum/PeakFindingandMeasurement.htm

Comment only
01 Feb 2014 helin

### helin (view profile)

Thanks for your quick answer. I believe an estimate of fitting error would be extremely useful, so that we can have a quantified understanding of goodness of fit quickly. Thanks again.

Comment only
01 Feb 2014 helin

### helin (view profile)

Thanks for your quick answer. I believe an estimate of fitting error would be extremely useful, so that we can have a quantified understanding of goodness of fit. Thanks again.

01 Feb 2014 Tom O'Haver

### Tom O'Haver (view profile)

In iPeak, the fitting error is calculated only when you perform a curve fit (N or M keys). It's displayed in the x-axis label of the upper panel. You don't need to specify estimated/known peaks because it gets that info from the peak table.
But if you mean peak parameter error instead of fitting error, then you must use my ipf.m or peakfit.m programs instead, which include a bootstrap error estimate capability.
Would it be useful to add an estimate of fitting error to the usual peak parameter results?

Comment only
01 Feb 2014 helin

### helin (view profile)

Thanks for this great code. I want to learn if there is a way to calculate fitting error if we do not have any estimated/known peaks in contrast to 11-input case.

Comment only
04 Jul 2013 Tom O'Haver

### Tom O'Haver (view profile)

Thanks, Bernhard, that's good advice. I'll look into "namespace" and "nlimt".

I do not believe "findpeaks" was a basic built-in function when I first created my function (back in Matlab 6.5), but I agree that I should change the name of my function to avoid the conflict.

Comment only
04 Jul 2013 Bernhard

### Bernhard (view profile)

Great and very useful work!
The only drawbacks are that the function findpeaks already comes with MATLAB and you make heavy use of global variables (can lead to bad side effects when used in conjunction with other code).
Consider using a namespace or rename the function and generally check mlint results (this should also improve performance).

01 Feb 2013 Tom O'Haver

### Tom O'Haver (view profile)

Thanks, Robert. After doing an iterative curve fit, the best-fit parameters are printed out in the command window. Or did you mean something else by "write the outcome"?

Comment only
31 Jan 2013 Robert

### Robert (view profile)

Hi Tom, thanks for sharing this wonderful code. It is not possible to write the outcome obtained after iterative curve fitting to a variable or am I missing something?

29 Aug 2012 Tom O'Haver

### Tom O'Haver (view profile)

Version 4 is now available from http://terpconnect.umd.edu/~toh/spectrum/PeakFindingandMeasurement.htm. It adds the 'H' key that more easily detects 'shoulders' and poorly-resolved peaks.

Comment only
09 May 2012 Tom O'Haver

### Tom O'Haver (view profile)

Kenric Lam, thanks for the heads-up. That bug has been tracked down and fixed in iPeak version 3.9, just uploaded to the file exchange and also available at http://terpconnect.umd.edu/~toh/spectrum/ipeak3.zip

Comment only
12 Apr 2012 Kenric Lam

### Kenric Lam (view profile)

It is a big trap that there is a subfunction 'findpeaks' in 'ipeak.m' that is the same to the separate file 'findpeaks.m', but the results given are different.

Comment only
08 Mar 2012 Eric Diaz

### Eric Diaz (view profile)

Wonderfully documented!

Comment only
08 Mar 2012 Eric Diaz

### Eric Diaz (view profile)

Great code Tom!

wonderful code !!!

01 Sep 2011 Tom O'Haver

### Tom O'Haver (view profile)

Version 3 adds iterative curve fitting of the detected peaks with selectable peak shapes.

Comment only
27 Jun 2011 Tom O'Haver

### Tom O'Haver (view profile)

Version 2.0, June 24, 2011, adds two main new features. You can set the initial values of pan and zoom in optional input arguments 7 ('xcenter') and 8 ('xrange'). There is also an optional "peak identification" function if optional input arguments 9 ('MaxError'), 10 ('Positions'), and 11 ('Names') are included. Type Help ipeak for more info.

Comment only
14 Jun 2011 Tom O'Haver

### Tom O'Haver (view profile)

Version 1.4 fixed a problem with missing functions.

Comment only
09 Jun 2011 Tom O'Haver

### Tom O'Haver (view profile)

Version 1.3 has improved input argument flexibility, accepts signals as separate x and y vectors or a two-column or two-row matrix. Adds a function to restore the original signal after the baseline has been subtracted. Adds peak area to the peak table.

Comment only
26 Apr 2011 Tom O'Haver

### Tom O'Haver (view profile)

Version 1.2 (April 2011) has improved graphic performance on recent versions of Matlab.

Comment only
25 Mar 2011 Tom O'Haver

### Tom O'Haver (view profile)

That should work, Aurora. Download the iPeak function, put it in the Matlab path, then type "help ipeak".

Comment only
24 Mar 2011 Aurora

### Aurora (view profile)

I want to use it to detect density peaks in my 1 dimensional data. How to do this? Thanks!

17 Feb 2010 Andre Guy Tranquille

### Andre Guy Tranquille (view profile)

27 Apr 2009 Tom O'Haver

### Tom O'Haver (view profile)

Version 1.1 posted 25 Apr 2009 adds keypress command "L" which toggles ON and OFF peak labels in the upper panel (zoomed-in segment). Each peak in that segment is labeled with peak position, height, and width. The labels change in real-time as the peak detection parameters are modified.

Comment only
21 Apr 2009 1.1

Revised description

25 Apr 2009 1.3

Version 1.1 adds "L" keypress to toggle peak labels in upper panel ON and OFF. Peak shown in the upper panel (zoom-in view) are labeled with peak position, height, and width, which changes in real-time as the peak detection parameters are varied.

26 Apr 2011 1.4

Improved graphics performance on Matlab 7.8 (R2009a)

09 Jun 2011 1.6

Several enhancements to UI and input argument flexibility. Added baseline restore function.

14 Jun 2011 1.7

Includes embedded functions that were omitted in previous version.

17 Jun 2011 1.8

Improved keyboard error handling

24 Jun 2011 1.10

Version 2 allows specifying the initial values of pan and zoom. Also the 'IDpeak' function compares the found peak positions (maximum x-values) to a database of known peaks and identifies matching peaks in the signal.

30 Jun 2011 1.11

Edited description

01 Sep 2011 1.14

Version 3 adds iterative least-squares curve fitting with selected peak shapes.

12 Sep 2011 1.15

Version 3.2 has better noise

20 Sep 2011 1.17

Bug fixes

26 Sep 2011 1.19

Version 3.7, Adds valley detection mode (U key)

22 Oct 2011 1.21

Version 3.8 adds manual entry of AmpT after entering number of click points for background subtraction; '0' key to set minimum to zero.

09 May 2012 1.22

Version 3.9: Bug fixes; replaced internal findpeaks function with version 4; FitWidth now equals number of points, not number of intervals.

09 May 2012 1.24

Version 3.9: Bug fixes; replaced internal findpeaks function with version 4; FitWidth now equals number of points, not number of intervals.

09 May 2012 1.25

Typo correction.

29 Aug 2012 1.28

Version 4.0, August, 2012, adds 'H' key to help in detecting 'shoulders' and poorly-resolved peaks.

24 Sep 2012 1.31

Version 4.1: peakfit internal function updated to version 3.3. Bug fixes.

28 Dec 2012 1.32

Version 5: Faster jump between peaks with spacebar and tab keys; other small bug fixes

26 Apr 2013 1.33

Version 5.3 adds table of summary statistics of the maximum, minimum, average, percent standard deviation, and displays histograms of the peak intervals (the x-axis interval between adjacent detected peaks), heights, widths, and areas.

14 Nov 2013 1.34

Version 5.8: Includes version 4.2 of peakfit.m, adds Voigt profile shape and flat baseline mode for iterative least-squares fits.

05 Feb 2014 1.35

Version 5.9 adds relative % fitting error as 6th column of peak table

19 Mar 2014 1.36

Version 5.96 adds interpolation function (Shift-I).

25 Jun 2014 1.37

Version 6 adds an ensemble averaging function (Shift-E).

24 Apr 2015 1.38

Version 7.1 adds improved Octave compatibility and includes 33 model peak shapes for curve fitting.