1.0

1.0 | 1 rating Rate this file 2 Downloads (last 30 days) File Size: 1.22 KB File ID: #24797

Fast array peak finder

by George Zipfel

 

20 Jul 2009

Finds locations of all maxima and corresponding maximum values in a 1D array.

| Watch this File

File Information
Description

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

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
22 Jul 2009 Darren Rowland

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
    N=length(y)-2;
    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
    Y=logical(yD);
    I=1:length(Y);
    peak(1,:)=I(Y);
    peak(2,:)=y(Y);

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
time series George Zipfel 21 Jul 2009 10:35:57
array George Zipfel 21 Jul 2009 10:35:57
peak finder George Zipfel 21 Jul 2009 10:35:57
linear array George Zipfel 21 Jul 2009 10:35:57
maximum values George Zipfel 21 Jul 2009 10:35:57
maxima George Zipfel 21 Jul 2009 10:35:57
time series victor CastaƱeda 04 Aug 2009 20:51:33

Contact us at files@mathworks.com