21
Peak Finding and Measurement A common requirement in signal processing is to detect peaks in a signal and to measure their positions, heights, and widths. A common way to do this is to make use of the fact that the first derivative of a peak has a downward-going zero-crossing at the peak maximum. But the presence of random noise in real experimental signal will cause many false zero-crossing simply due to the noise. To avoid this prolem, the technique descried here first smooths the first derivative of the signal, efore looking for downward-going zero-crossings, and then it takes only those zero crossings whose slope exceeds a certain pre-determined minimum !called the "slope threshold"# at a  point wh ere the or iginal si gnal exc eeds a cert ain min imum !calle d the "amplitude threshold"#. By carefully ad$usting the smoothwidth, slope threshold, and amplitude threshold, it%s possile to detect only the desired peaks and ignore peaks that are too small, too wide, or too narrow. &oreover, ecause smoothing can distort peak signals, reducing peak heights and increasing peak widths, this technique estimates the position, height, and width of each peak y least-squares curve-fitting of a segment of the original unsmoothed signal  in the vicinity of the zero-crossing. Thus, even if heavy smoothing of the first derivative is necessary to provide reliale discrimination against noise peaks, the peak parameters extracted y curve fitting are not distorted. !This is useful primarily for signals that have several data points in each  peak, no t for spike s that hav e only o ne or two points#. This tec hnique i s capale of measuring peak positions and heights quite accurately, ut the measurements of peak widths and areas is accurate only if the peaks are approximately 'aussian in shape. !(or the most accurate measurement of highly overlapped peaks, i)eak version * is capale of utilizing non-linear iterative curve fitting #. The routine is availale in three different versions+ !# the asic command-line findpeaks function ! findpeaks.m# !# an interactive keypress-operated function , called iPeak  !ipeak.m# for ad$usting the  peak de tection cr iteria in real-time to optimiz e for any pa rticular p eak type and !*# an older script using mouse-controlled sliders  for interactive control, which works only in &atla /.0 ut not in more recent versions. These are all detailed elow. 1lick here to download the 23) file ")eak(inder.zip" , which includes findpeaks.m, ipeak.m, and a sample data file and demo scripts for testing. 4ou can also download i)eak and other programs of mine from the &atla (ile 5xchange . The findpeaks function (findpeaks.m) function P=findpeaks(x,y,SlopeThreshold,AmpThreshold,SmoothWidth,FitWidth,smoothtype) This is the asic command-line function to locate and measure the positive peaks in a noisy data sets. 3t detects peaks y looking for downward zero-crossings in the smoothed first derivative that exceed 6lopeThreshold and peak amplitudes that exceed AmpThreshold, and determines the position, height, and approximate width of each  peak y least-square s curve-fitt ing the t op part of t he peak . 7eturns a list !in matrix )#

Peak Finding and Measurement

Embed Size (px)

Citation preview

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 1/21

Peak Finding and Measurement

A common requirement in signal processing is to detect peaks in a signal and tomeasure their positions, heights, and widths. A common way to do this is to make use

of the fact that the first derivative of a peak has a downward-going zero-crossing at

the peak maximum. But the presence of random noise in real experimental signal willcause many false zero-crossing simply due to the noise. To avoid this prolem, the

technique descried here first smooths the first derivative of the signal, efore looking

for downward-going zero-crossings, and then it takes only those zero crossings whoseslope exceeds a certain pre-determined minimum !called the "slope threshold"# at a

 point where the original signal exceeds a certain minimum !called the "amplitudethreshold"#. By carefully ad$usting the smoothwidth, slope threshold, and amplitude

threshold, it%s possile to detect only the desired peaks and ignore peaks that are too

small, too wide, or too narrow. &oreover, ecause smoothing can distort peak

signals, reducing peak heights and increasing peak widths, this technique estimatesthe position, height, and width of each peak y least-squares curve-fitting of a

segment of the original unsmoothed signal  in the vicinity of the zero-crossing. Thus,even if heavy smoothing of the first derivative is necessary to provide reliale

discrimination against noise peaks, the peak parameters extracted y curve fitting arenot distorted. !This is useful primarily for signals that have several data points in each

 peak, not for spikes that have only one or two points#. This technique is capale of

measuring peak positions and heights quite accurately, ut the measurements of peak

widths and areas is accurate only if the peaks are approximately 'aussian in shape.

!(or the most accurate measurement of highly overlapped peaks, i)eak version * is

capale of utilizing non-linear iterative curve fitting#.

The routine is availale in three different versions+!# the asic command-line findpeaks function !findpeaks.m#

!# an interactive keypress-operated function, called iPeak  !ipeak.m# for ad$usting the

 peak detection criteria in real-time to optimize for any particular peak type and

!*# an older script using mouse-controlled sliders for interactive control, which works

only in &atla /.0 ut not in more recent versions. These are all detailed elow.

1lick here to download the 23) file ")eak(inder.zip", which includes findpeaks.m,ipeak.m, and a sample data file and demo scripts for testing. 4ou can also download

i)eak and other programs of mine from the &atla (ile 5xchange.

The findpeaks function (findpeaks.m)

function

P=findpeaks(x,y,SlopeThreshold,AmpThreshold,SmoothWidth,FitWidth,smoothtype)

This is the asic command-line function to locate and measure the positive peaks in a

noisy data sets. 3t detects peaks y looking for downward zero-crossings in the

smoothed first derivative that exceed 6lopeThreshold and peak amplitudes that exceedAmpThreshold, and determines the position, height, and approximate width of each

 peak y least-squares curve-fitting the top part of the peak. 7eturns a list !in matrix )#

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 2/21

containing the peak numer and the estimated position, height, and width of each

 peak. 3t can find and measure over 888 peaks per second in very large signals.

The data are passed to the findpeaks funciton in the vectors x and y !x 9 independent

variale, y 9 dependent variale#. The other parameters are user-ad$ustale+

SlopeThreshold - 6lope of the smoothed first-derivative that is taken toindicate a peak. This discriminates on the asis of peak width. :arger values ofthis parameter will neglect road features of the signal. A reasonale initial

value for 'aussian peaks is 8.;<=idth)oints>-, where =idth)oints is the

numer of data points in the half-width of the peak.

AmpThreshold - ?iscriminates on the asis of peak height. Any peaks with

height less than this value are ignored.

SmoothWidth - =idth of the smooth function that is applied to data efore theslope is measured. :arger values of 6mooth=idth will neglect small, sharp

features. A reasonale value is typically aout equal to @ of the number of

data points in the half-width of the peaks.FitWidth - The numer of points around the "top part" of the !unsmoothed#

 peak that are taken to estimate the peak heights, positions, and widths. A

reasonale value is typically aout equal to @ of the number of data points in

the half-width of the peaks. The minimum value is *.

Smoothtype !added in ersion , 6ept. 8# determines the smoothingalgorithm !see http+@@terpconnect.umd.edu@Ctoh@[email protected] #

  3f smoothtype9, rectangular !sliding-average or oxcar#3f smoothtype9, triangular ! passes of sliding-average#

  3f smoothtype9*, pseudo-'aussian !* passes of sliding-average#

Basically, higher values yield greater reduction in high-frequency noise, at the

expense of slower execution.

There is also a similar function for finding valleys !minima#, called findvalleys.m,

which works the same way as findpeaks.m, except that it locates minimainstead of maxima. 7ight-click the link and select "6ave link as...."

!amples"

>> x=!"#!$"%!&'y=cos(x)'findpeaks(x,y,!,$,%,%)ans =

  $ #*+* $ *#%-

  * $*#% $ *#%-

  $+#+% $ *#%+

  . *%#$ $ *#%-

  % $#.$ $ *#%-

  /#-- $ *#%+

  / .#-+* $ *#%-

>> x=!"#!$"%!&'y=cos(x)'find0alleys(x,y,!,$,%,%)ans =

  $ #$.$ $ *#%/$

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 3/21

  * -#.*.+ $ *#%/$

  $%#/!+ $ *#%/$

  . *$#--$ $ *#%/$

  % *+#*/. $ *#%/$

  .#%%+ $ *#%/$

  / .!#+.$ $ *#%/$

#ote+ The accuracy of the measurements of peak position, height, and width y the

findpeaks function depends on the shape of the peaks, the extent of peak overlap, and

signal-to-noise ratio. The width measurements particularly are strongly influenced y

 peak overlap, noise, and the choice of (it=idth. 3solated peaks of 'aussian shape are

measured most accurately. 6ee "ipeakdemo" !elow# for an accuracy trial. (or themost accurate measurements of highly overlapping peaks of various shapes, use the

3nteractive )eak (itter  !ipf.m#. 

$emoFindPeak ($emoFindPeak.m)

1lick to view enlarged figure

A simple demonstration script using the

findpeaks function on noisy synthetic data.

 Dumers the peaks and prints out the )matrix in the &atla command window+

Peak # Position Height

 Width

P =

  1.0000 10.0235 0.18141.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  ......

The iPeak Function (ipeak.m)% &ersion '. $onload as a

*+P file ith sample data.

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 4/21

Peaks in annual sunspot num,ers from -// to 0//1 (donload th

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 5/21

Press 2 key to sitch ,eteen peak and valley mode.

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 6/21

  !ample 0

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 7/21

34 data (normal and inverted)

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 8/21

!ample '

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 9/21

!ample 5. Pressing 676 toggles 8# and 8FF the peak la,els in the u

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 10/21

!ample . The peak identification function applied to a high9resolution

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 11/21

!ample . Three peaks near 01: nm isolated and identified. Press the + key to d

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 12/21

#ormal Peak Fit (# key)

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 13/21

iPeak '.0 and later% shoing log scale (; key) and Auto<ero mo

3lick to vie larger figures.

iPeak $emo scripts

The 23) file at http+@@terpconnect.umd.edu@Ctoh@spectrum@ipeak*.zip  contains several

demo scripts !ipeakdemo.m, ipeakdemo.m, etc# that illustrate various aspects of the

i)eak function and how it can e used effectively. ?ownload the zip file, right-clickand select "5xtract all", then put the resulting files in the &atla path and run them y

typing their names at the &atla command window prompt or y opening them in the&atla editor and clicking the green "7un" utton on the editor toolar.

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 14/21

ipeakdemo"

effect of the

peak  

detection

parameters

(our  'aussian peak s with the

same heights ut

different widths

!8, *8, 08 and

;8 units# This

demonstrates

the effect of

6lopeThreshold

and

6mooth=idth

on peak

detection.

3ncreasing

6lopeThreshold

!S key# will

discr iminate

against the

 roader peaks.

3ncreasing

6mooth=idth

!$ key# will

discriminate

against thenarrower peaks

and noise.

(it=idth !F@& 

keys# controls

the numer of

 points around

the "top part"

of the

!unsmoothed#

 peak that are

taken toestimate the

 peak heights,

 positions, and

widths. A

reasonale

value is

ordinarily

aout equal to

@ of the

number of

data points inthe half-width

of the peaks. 3n

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 15/21

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 16/21

ipeakdemo0"

peak  overlap

and the curve

fitting

fuctions.

?emonstrationof er ror caused

 y overlapping

 peak s on a large

offset aseline.

5ach time you

run this demo,

you will get a

different set of

 peak s and noise.

A tale of the

actual peak

 positions,

heights, widths,

and areas is

 printed out in

the command

window. Eump

to the

next@previous

 peaks using the

Space,ar=Ta, 

keys.

Fint+ Gse the > 

key and click on

the aseline

 points, then

 press the P key

to display the

 peak tale. Hr

turn on the

Autozero mode

!T key# and use

the Dormal

curve fit !# key#or &ultiple

curve fit !M 

key#.

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 17/21

ipeakdemo'+

#on9

4aussian

peak shapes

?emonstration

of overlapping

:orentzian

 peak s, without

an added

 ack ground.

Hver lap of

 peak s causes

significant

error s in peak

height, width,

and area. Eump

to thenext@ previous

 peak s using the

Space,ar=Ta, 

keys. 5ach time

you r un this

demo, you will

get a different

set of noise. A

tale of the

actual peak

 positions,

heights, widths,and areas is

 printed out in

the command

window.

Fint+ turn H((

the Autozero

mode !T key#

and use the

 Dormal curve fit

!# key# or

&ultiple curve

fit !M key# with

 peak shape

!:orentzian#.

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 18/21

ipeakdemo?"

dealing ith

very noisy

signals

?etection and

measurement offour peaks in a

very noisy

signal. The

signal-to-noise

ratio of first

 peak  is . 5ach

time you run

this demo, you

will get a

different set of

noise. A tale of

the actual peak

 positions,

heights, widths,

and areas is

 printed out in

the command

window. Eump

to the

next@previous

 peaks using the

Space,ar=Ta, 

keys. The peakat x988 is

usually detected,

 ut the accuracy

of peak

 parameter

measurement is

 poor ecause of

the low signal-

to-noise ratio.

Fint+ =ith very

noisy signals itis usually est to

increase

6mooth=idth

and (it=idth to

help reduce the

effect of the

noise.

FindPeakSliders% for Matla, :.5 (does not ork relia,ly in more recent versionsof Matla,@ use iPeak instead.)

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 19/21

1hromatogram, efore aseline correction

After aseline correction

3nteractive findpeaks script using mouse-

controlled sliders for interactive control. 7equires

&atla /.0. This can e used to determine what

values of the parameters give the most reliale

 peak detection. :oad your data set into the vectors

x and y !x 9 independent variale, y 9 dependentvariale#, then run this m-file and ad$ust the

sliders to change the four arguments of the

 peakfind function. The four sliders correspond to

the arguments of the findpeaks function descried

aove+ SlopeThreshold (SlopeT),

AmpThreshold (AmpT), SmoothWidth

(Smooth), and FitWidth (Fit). The range of these

sliders is easily changed in lines /0 - ;8 to suit a

wide range of data types. The >4 utton is used

for aseline !ackground# sutraction+ click once

on the >4 utton, then click on the aseline atfive points starting to the left of the lowest x-value

and ending to the right of the higest x-value. The

 ackground will e sutracted. 4ou can repeat as

needed. !4ou can also change the numer of

 aseline points y changing Baseline)oints in the

function B'.m#. )eak numer and the estimated

 position, height, and width of each peak is

returned in the matrix )+>> P

P =

  $#!!!! .%#!!-% !#$*+ .#!$!*

  *#!!!! -!#%!$ !#%% .#/$*/

  #!!!! -.#-/ $#.!/% .#!-/

  ######

$emoFindPeakSliders

1lick to view enlarged figure

A self-contained interactive demonstration of(ind)eak6liders applied to noisy synthetic data set

consisting of a random numer of narrow peaks

superimposed on a gently curved ackground.

7equires &atla /.0. Gse the sliders to explore the

effect of the variales SlopeThreshold (SlopeT),

AmpThreshold (AmpT), SmoothWidth

(Smooth), and FitWidth (Fit), and the aseline

correct !>4# utton. )eak numer and the

estimated position, height, and width of each peak

is returned in the matrix ).

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 20/21

$emoFindPeakSliders0

1lick to view enlarged figure

A self-contained interactive demonstration of

(ind)eak6liders applied to a data set containing

four simple peaks with increasing peak height and

 peak width. Gse this to understand the difference etween the variales 6lopeThreshold !6lopeT#,

which discriminates on the asis of peak width,

and AmpThreshold !AmpT#, which discriminates

on the asis of peak amplitude. )eak numer and

the estimated position, height, and width of each

 peak is returned in the matrix ).>> P

P =

  $#!!!! .-#-!- $#-+-% *!#$-!

  *#!!!! $*#$!. #!%+% .*#%!+

  #!!!! *!$#-./ .#!/%* #%.

  .#!!!! *--#-*.* .#--*% +*#*!!!

FindPeakSliders4

1lick to view enlarged figure 1lick to view enlarged figure

3nteractive findpeaks script with peak-zoom feature, for pre-defined data in x,y. 7equires &atla

/.0. :oad a typical data set into the vectors x,y, then run this m-file and ad$ust the sliders to

determine what values of the parameters give the most reliale peak detection. )eak numer and

 position, height, and width of each peak is returned in the matrix ). 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 !(it=idth# as a lue curve. To see all the peaks, set the )eaks slider to zero !all

the way down#.

 Dote+ 3f the slider ranges are not appropriate for your data, change them in lines /*-/I.

$emoFindPeakSliders4

A self-contained interactive demonstration of (ind)eak6liders'. 7equires &atla /.0.

8/13/2019 Peak Finding and Measurement

http://slidepdf.com/reader/full/peak-finding-and-measurement 21/21

&ideo $emonstration of FindPeakSliders

This is a /-second, . &Byte video !)eak(ind.wmv# of (ind)eak6liders !version .#,

showing the effect of varying the four parameters SlopeThreshold (SlopeT), AmpThreshold

(AmpT), SmoothWidth, and FitWidth !laeled ")eak=idth" in this video#.

Tom H%Faver )rofessor 5meritus

?epartment of 1hemistry and Biochemistry

The Gniversity of &aryland at 1ollege )ark 

tohJumd.edu

http+@@www.wam.umd.edu@Ctoh 

:ast updated, Hctoer, 8