Code covered by the BSD License  

Highlights from
1D Non-derivative Peak Finder


5.0 | 2 ratings Rate this file 25 Downloads (last 30 days) File Size: 3.82 KB File ID: #30490
image thumbnail

1D Non-derivative Peak Finder



21 Feb 2011 (Updated )

Up-sample and filter noisy data to find peaks without using derivatives.

| Watch this File

File Information

PEAKFIND general 1D peak finding algorithm
Tristan Ursell, 2013.



This function finds peaks without taking first or second derivatives, rather it uses local slope features in a given data set. The function has four basic modes.

   Mode 1: peakfind(x_data,y_data) simply finds all peaks in the data
   given by 'xdata' and 'ydata'.

   Mode 2: peakfind(x_data,y_data,upsam) finds peaks after up-sampling
   the data by the integer factor 'upsam' -- this allows for higher
   resolution peak finding. The interpolation uses a cubic spline that
   does not introduce fictitious peaks.

   Mode 3: peakfind(x_data,y_data,upsam,gsize,gstd) up-samples and then
   convolves the data with a Gaussian point spread vector of length
   gsize (>=3) and standard deviation gstd (>0).

   Mode 4: peakfind(x_data,y_data,upsam,htcut,'cuttype') up-samples the
   data (upsam=1 analyzes the data unmodified). The string 'cuttype' can
   either be 'abs' (absolute) or 'rel' (relative), which specifies a peak
   height cutoff which is either:

       'abs' - finds peaks that lie an absolute amount 'htcut' above the
       lowest value in the data set.

            for (htcut > 0) peaks are found if

            peakheights > min(yout) + htcut
       'rel' - finds peaks that are an amount 'htcut' above the lowest
       value in the data set, relative to the full change in y-input

           for (0 < htcut < 1) peaks are found if

           (peakheights-min(yout))/(max(yout)-min(yout)) > htcut

Upsampling and convolution allows one to find significant peaks in noisy data with sub-pixel resolution. The algorithm also finds peaks in data where the peak is surrounded by zero first derivatives, i.e. the peak is actually a large plateau.

The function outputs the x-position of the peaks in 'xpeaks' or the processed input data in 'xout' and 'yout' with 'peakspos' as the indices of the peaks, i.e. xpeaks = xout(peakspos).

If you want the algorithm to find the position of minima, simply input '-y_data'. Peaks within half the convolution box size of the boundary will be ignored (to avoid this, pad the data before processing).

 Example 1:

 x_data = -50:50;
 y_data =(sin(x_data)+0.000001)./(x_data+0.000001)+1+0.025*(2*rand(1,length(x_data))-1);

 hold on
 title(['Found ' num2str(length(peakspos)) ' peaks.'])
 box on

 Example 2:

 x_data = -50:50;
 y_data =(sin(x_data)+0.000001)./(x_data+0.000001)+1+0.025*(2*rand(1,length(x_data))-1);


 hold on
 title(['Found ' num2str(length(peakspos)) ' peaks.'])
 box on

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
06 Dec 2011 Tristan Ursell

No longer uses fspecial. Bug pointed out by Andrew has been fixed.

06 Dec 2011 Tristan Ursell

Hsueh-Hsin -- I will look into that, agreed it would be preferable to not call it.

16 Nov 2011 Hsueh-Hsin

'fspecial' from Image Processing Toolbox: could it be removed/replaced

15 Nov 2011 Tristan Ursell

Andrew -- thank you -- I will fix that!

08 Nov 2011 Andrew Davis

Thanks for posting this, it works well, and the code is nicely laid out. One small bug, in order for the fourth method of calling the function to work, line 264 should be:
if and(npeaks>1,exist('cuttype'))

08 Nov 2011 Andrew Davis  
07 Sep 2011 Kiran  
15 Nov 2011

This update fixes two small bugs in the code.

06 Dec 2011

Replaced the use of 'fspecial', which requires the image processing toolbox, with a simple calculation.

09 Jul 2013

fixed small bug, expanded functionality

Contact us