PEAKDET Detect peaks in a vector [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local maxima and minima ("peaks") in the vector V. MAXTAB and MINTAB consists of two columns. Column 1 contains indices in V, and column 2 the found values. With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices in MAXTAB and MINTAB are replaced with the corresponding X-values. 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. Eli Billauer, 3.4.05 (Explicitly not copyrighted). This function is released to the public domain; Any use is allowed. Modified by Abdallah Kassir 13/12/2009
0001 function maxtab=peakdet(v) 0002 % PEAKDET Detect peaks in a vector 0003 % 0004 % [MAXTAB, MINTAB] = PEAKDET(V, DELTA) finds the local 0005 % maxima and minima ("peaks") in the vector V. 0006 % MAXTAB and MINTAB consists of two columns. Column 1 0007 % contains indices in V, and column 2 the found values. 0008 % 0009 % With [MAXTAB, MINTAB] = PEAKDET(V, DELTA, X) the indices 0010 % in MAXTAB and MINTAB are replaced with the corresponding 0011 % X-values. 0012 % 0013 % A point is considered a maximum peak if it has the maximal 0014 % value, and was preceded (to the left) by a value lower by 0015 % DELTA. 0016 % 0017 % Eli Billauer, 3.4.05 (Explicitly not copyrighted). 0018 % This function is released to the public domain; Any use is allowed. 0019 % 0020 % Modified by Abdallah Kassir 13/12/2009 0021 0022 0023 x=1:length(v); 0024 [v,x]=cadj(v,x); 0025 delta=(max(v)-min(v))/4; 0026 0027 maxtab = []; 0028 0029 if delta==0 0030 return; 0031 end 0032 0033 mn = Inf; mx = -Inf; 0034 mxpos = NaN; 0035 0036 lookformax = 0; %modified 0037 0038 for i=1:length(v) 0039 this = v(i); 0040 if this > mx, mx = this; mxpos = x(i); end 0041 if this < mn, mn = this; end 0042 0043 if lookformax 0044 if this < mx-delta 0045 maxtab = [maxtab ; mxpos mx]; 0046 mn = this; 0047 lookformax = 0; 0048 end 0049 else 0050 if this > mn+delta 0051 mx = this; mxpos = x(i); 0052 lookformax = 1; 0053 end 0054 end 0055 end