Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!news.belwue.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail
From: Lothar Schmidt <vapooroop@gmx.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: peak detection
Date: Fri, 25 Jul 2008 13:53:29 +0200
Organization: T-Online
Lines: 76
Message-ID: <g6cerv$uc0$01$1@news.t-online.com>
References: <g6catb$7oe$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.t-online.com 1216986815 01 31104 K1XwOvaJZzpo3Vy 080725 11:53:35
X-Complaints-To: usenet-abuse@t-online.de
X-ID: JrsqFYZcZeRP52gbK6yO78YwLFQHHDF8aqQQ+PjNEIao6vvlhd2IYo
User-Agent: Thunderbird 2.0.0.16 (Windows/20080708)
In-Reply-To: <g6catb$7oe$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:481796



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