[Table of Contents] [Previous section] [Next section]

Peak Finding and Measurement, Version 1.6 October 26, 2006

A fast, customizable Matlab routine for locating and measuring the peaks in noisy time-series data sets. Determines the position, height, and width of each peak by least-squares curve-fitting. It can find and measure 1000 peaks in a 1,000,000 point signal in 8 seconds. Click here to download the ZIP file "Peakfinder.zip" that also includes supporting functions, several self-contained demos to show how it works, and an interactive version with sliders for adjusting the peak finding criteria in real-time. Version 1.6 works with a wider range of signal types and includes baseline (background) correction. You can also download it from the Matlab File Exchange.

The findpeaks function

function P=findpeaks(x,y,SlopeThreshold,AmpThreshold,SmoothWidth,FitWidth)
This is the basic function to locate and measure the positive peaks in a noisy data sets. It detects peaks by looking for downward zero-crossings in the smoothed first derivative that exceed SlopeThreshold and peak amplitudes that exceed AmpThreshold, and determines the position, height, and approximate width of each peak by least-squares curve-fitting the top part of the peak. Returns a list (in matrix P) containing the peak number and the estimated position, height, and width of each peak. The data are passed in the vectors x and y (x = independent variable, y = dependent variable). The other four parameters are user-adjustable:

DemoFindPeak


Click to view enlarged figure
A simple demonstration script using the findpeaks function on noisy synthetic data. Numbers the peaks and prints out the P matrix in the Matlab command window:
    Peak #   Position   Height    Width
P =
    1.0000   10.0235    0.1814    1.7506
    2.0000   29.9964    0.6412    1.9931
    3.0000   50.0205    0.4315    2.1433
    4.0000   70.0120    1.3935    2.0202
    5.0000   79.9567    0.2580    1.8267
    6.0000  100.0086    1.0862    2.0306
    ......

FindPeakSliders


Before baseline correction


After baseline correction
Interactive findpeaks script for your own data. Requires Matlab 6.5. This can be used to determine what values of the parameters give the most reliable peak detection. Load your data set into the vectors x and y (x = independent variable, y = dependent variable), then run this m-file and adjust the sliders to change the four arguments of the peakfind function. The four sliders correspond to the arguments of the findpeaks function described above: SlopeThreshold (SlopeT), AmpThreshold (AmpT), SmoothWidth (Smooth), and FitWidth (Fit). The range of these sliders is easily changed in lines 65 - 70 to suit a wide range of data types. The BG button is used for baseline (background) subtraction: click once on the BG button, then click on the baseline at five points starting to the left of the lowest x-value and ending to the right of the higest x-value. The background will be subtracted. You can repeat as needed. (You can also change the number of baseline points by changing BaselinePoints in the function BG.m). Peak number and the estimated position, height, and width of each peak is returned in the matrix P:
>> P
P =
    1.0000   45.0095    0.1328    4.0102
    2.0000   90.5301    0.3655    4.7127
    3.0000   94.9673    1.4075    4.0967
    ......

DemoFindPeakSliders

Click to view enlarged figure
Click to view enlarged figure
A self-contained interactive demonstration of FindPeakSliders applied to noisy synthetic data set consisting of a random number of narrow peaks superimposed on a gently curved background. Requires Matlab 6.5. Use the sliders to explore the effect of the variables SlopeThreshold (SlopeT), AmpThreshold (AmpT), SmoothWidth (Smooth), and FitWidth (Fit), and the baseline correct (BG) button. Peak number and the estimated position, height, and width of each peak is returned in the matrix P.

DemoFindPeakSliders2


Click to view enlarged figure
A self-contained interactive demonstration of FindPeakSliders applied to a data set containing four simple peaks with increasing peak height and peak width. Use this to understand the difference between the variables SlopeThreshold (SlopeT), which discriminates on the basis of peak width, and AmpThreshold (AmpT), which discriminates on the basis of peak amplitude. Peak number and the estimated position, height, and width of each peak is returned in the matrix P:
>> P
P =
    1.0000   49.9096    1.9895   20.1960
    2.0000  126.1034    3.0585   42.3508
    3.0000  201.3947    4.0752   63.3354
    4.0000  299.9242    4.9925   82.2000


FindPeakSlidersG


Click to view enlarged figure
Click to view enlarged figure
Click to view enlarged figure
Interactive findpeaks script with peak-zoom feature, for pre-defined data in x,y. Requires Matlab 6.5. Load a typical data set into the vectors x,y, then run this m-file and adjust the sliders to determine what values of the parameters give the most reliable peak detection. Peak number and position, height, and width of each peak is returned in the matrix P. This version has an additional slider, Peak, which zooms in on any one of the detected peaks and shows the fitted top of the peak (FitWidth) as a blue curve. To see all the peaks, set the Peaks slider to zero (all the way down).
Note: If the slider ranges are not appropriate for your data, change them in lines 63-69.

DemoFindPeakSlidersG

A self-contained interactive demonstration of FindPeakSlidersG. Requires Matlab 6.5.

ZIP file containing all of the above peakfind functions and demos.

Video Demonstration of FindPeakSliders

This is a 26-second, 1.4 MByte video (PeakFind2.wmv) of FindPeakSliders (version 1.1), showing the effect of varying the four parameters SlopeThreshold (SlopeT), AmpThreshold (AmpT), SmoothWidth, and FitWidth (labeled "PeakWidth" in this video).

Tom O'Haver
Professor Emeritus
Department of Chemistry and Biochemistry
The University of Maryland at College Park
toh@umd.edu
http://www.wam.umd.edu/~toh


[Table of Contents] [Previous section] [Next section]