File Exchange

image thumbnail

Fast array peak finder

version (1.22 KB) by George Zipfel
Finds locations of all maxima and corresponding maximum values in a 1D array.

1 Download

Updated 20 Jul 2009

View License

Fast peak finder returns 2xN array containing peak values and peak locations. End point maxima are not included.

Comments and Ratings (2)

Here is the file. Definitely leaves room for improvement. No H1 line, bare-bones help and no example. The use of the return variable is poor. The syntax should follow max() i.e.
maxima = zipeaks(y);
[maxima,ind] = zipeaks(y);

function peak=zipeaks(y)
%Usage: peak=zipeaks(y);
%Returns 2x(number of maxima) array
%peak(1,:) = value at maximum
%peakloc(2,:) = index value for maximum

%Find locations of local maxima
%yD=1 at maxima, yD=0 otherwise, end point maxima excluded
yD=[0 (sign(sign(y(2:N+1)-y(3:N+2))-sign(y(1:N)-y(2:N+1))-.1)+1) 0];
%Indices of maxima and corresponding values of y

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor