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=ipeak(DataMatrix) Keyboard-operated interactive peak finder written as a single self-contained m-file (Matlab function), for data in the matrix "DataMatrix", with x values in row 1 and y values in row 2. Simple keypress commands pan and zoom through the signal and allow the interactive adjustment of the four arguments of the findpeaks function described above. This function also has piecewise linear baseline subtraction, as described below for "FindPeakSliders". T. C. O'Haver (toh@umd.edu), Version 1.1, April 25, 2009. Click here to view or download. ipeak.m. There are three ways to call the function, with 1,2, or 6 arguments, which differ only in the way the initial values of the four peak detection parameters are calculated: EXAMPLE 1: (one argument) x=[0:.1:100];y=(x.*sin(x)).^2; ipeak([x' y']); Displays DataMatrix [x' y'] with starting values for peak detection parameters AmpT, SlopeT, SmoothW, FitW that are estimated by the function. EXAMPLE 2: (two arguments) x=[0:.1:100];y=5+5.*cos(x)+randn(size(x)); ipeak([x' y'],10); The optional second argument, which is an estimate of the maximum number of peaks that would fit into the data record (10 in this example), is used by the function to compute better starting values of the 4 peak detection parameters. EXAMPLE 3: (six arguments) ipeak([x' y'],0,0,.0001,33,33); As above, but specifies the exact initial values of AmpT, SlopeT, SmoothW, and FitW (in the last 4 arguments). Keyboard Controls: Pan left/right: Coarse pan: < and > Fine pan: left/right arrows Zoom in/out: Coarse zoom: / and " Fine zoom: up/down arrows Adjust AmpThreshold: A,Z Adjust SlopeThreshold:S,X Adjust SmoothWidth: D,C Adjust FitWidth: F,V Baseline: B, then click baseline at 8 points Print peak table: P Prints Peak#,Position,Height,Width Print key commands: K Prints this list Print parameters Q (Prints AmpT, SlopeT, SmoothW, FitW) Print report R Prints Peak table and parameters Peak labels ON/OFF: L (Peak #, Position, Height, Width) |
| >> ipeakdemo >> Peak # Position Height Width PercentErrors = 1 -0.035481 0.042445 -0.61178 2 -0.13457 -0.93707 -18.01 3 0.012393 -0.75061 0.78906 4 0.01442 -0.35048 0.19783 5 0.072319 1.6627 4.204 6 -0.069226 0.70238 8.6487 7 0.027877 -0.27144 2.7331 8 -0.061387 -1.4948 0.49849 9 -0.0017726 0.25882 0.48333 10 -0.0047634 -0.53386 1.2068 11 -0.00094297 0.0099868 -3.2264 12 0.033587 -5.272 -1.6698 13 0.00067791 0.65194 0.9434 14 -0.015964 -0.31073 2.658 AveragePercentError = 7.5 0.03467 0.94638 3.2772 | ipeakdemo This is a demo script for iPeak that demonstrates the operation of iPeak and its typical measurement errors. It generates a test signal consisting of several Gaussian peaks, adds random noise, runs iPeak, then calculates the errors between the actual and the measured peak positions, heights, and widths. Each time you run it you get a different set of peaks. (You can easily change the noise level or the peak heights, positions, and widths by editing the script in the indicated places). Click to view or download this script. In the example output on the left, you can see that the percent error of peak position measurements is excellent (less than 0.1%), that of peak height is also pretty good (about 1%) , but the error of width measurement is higher (about 3% here). For the most accurate measurements of highly overlapping peaks of various shapes, use the Interactive Peak Fitter (ipf.m). |
Interactive findpeaks script using mouse-controlled sliders for interactive control.
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 |
| 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. |
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 |
|
|
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
Number of unique visits since May 17, 2008: