Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: peak detection
Date: Fri, 25 Jul 2008 13:17:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 89
Message-ID: <g6cjod$de9$1@fred.mathworks.com>
References: <g6catb$7oe$1@fred.mathworks.com> <g6cerv$uc0$01$1@news.t-online.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1216991821 13769 172.30.248.35 (25 Jul 2008 13:17:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 25 Jul 2008 13:17:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1338633
Xref: news.mathworks.com comp.soft-sys.matlab:481817



Lothar Schmidt <vapooroop@gmx.net> wrote in message
<g6cerv$uc0$01$1@news.t-online.com>...
> Dave Brackett schrieb:
> > I have been using a peak detection m file from
> > http://www.billauer.co.il/peakdet.html. The code is
shown below.
> > 
> > Does anyone know if its possible to vectorise this function
> > as it currently uses for loops? and if it is, could you show
> > me how please? thanks. more info can be found at the
above link.
> > 
> > 
> > 
> > function [maxtab, mintab]=peakdet(v, delta)
> > %PEAKDET Detect peaks in a vector
> > %        [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the
local
> > %        maxima and minima ("peaks") in the vector V.
> > %        A point is considered a maximum peak if it has the
> > maximal
> > %        value, and was preceded (to the left) by a value
> > lower by
> > %        DELTA. MAXTAB and MINTAB consists of two columns.
> > Column 1
> > %        contains indices in V, and column 2 the found
values.
> > 
> > % Eli Billauer, 3.4.05 (Explicitly not copyrighted).
> > % This function is released to the public domain; Any use is
> > allowed.
> > 
> > maxtab = [];
> > mintab = [];
> > 
> > v = v(:); % Just in case this wasn't a proper vector
> > 
> > if (length(delta(:)))>1
> >   error('Input argument DELTA must be a scalar');
> > end
> > 
> > if delta <= 0
> >   error('Input argument DELTA must be positive');
> > end
> > 
> > mn = Inf; mx = -Inf;
> > mnpos = NaN; mxpos = NaN;
> > 
> > lookformax = 1;
> > 
> > for i=1:length(v)
> >   this = v(i);
> >   if this > mx, mx = this; mxpos = i; end
> >   if this < mn, mn = this; mnpos = i; end
> >   
> >   if lookformax
> >     if this < mx-delta
> >       maxtab = [maxtab ; mxpos mx];
> >       mn = this; mnpos = i;
> >       lookformax = 0;
> >     end  
> >   else
> >     if this > mn+delta
> >       mintab = [mintab ; mnpos mn];
> >       mx = this; mxpos = i;
> >       lookformax = 1;
> >     end
> >   end
> > end
> > 
> > 
> 
> index=2:length(v)-1;
> MAX_pos=find(v(i-1)+delta<v(i) & v(i+1)+delta<v(i))+1;
> 
> for finding the minima you'll shurely find a similar
solution :-)
> 
> Lothar
> 
> 

so those 2 lines do the same as most of that code? nice.

I am keen to get it to handle an arbitrary number of vectors
in matrix form as currently it can only handle single
vectors. As such I have been looping the whole function for
each vector which is slow. could you show me how to adapt
your vectorised version to allow this please? thanks.