source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/local_ext_mod/lmax.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.0 KB
Line 
1function [lmval,indd]=lmax(xx,filt)
2%LMAX   [lmval, indd]=lmax(xx,filt). Find local maxima in vector XX,where
3%       LMVAL is the output vector with maxima values, INDD  is the
4%       corresponding indexes, FILT is the number of passes of the small
5%       running average filter in order to get rid of small peaks.  Default
6%       value FILT =0 (no filtering). FILT in the range from 1 to 3 is
7%       usially sufficient to remove most of a small peaks
8%       For example:
9%       xx=0:0.01:35; y=sin(xx) + cos(xx ./3);
10%       plot(xx,y); grid; hold on;
11%       [b,a]=lmax(y,2)
12%        plot(xx(a),y(a),'r+')
13%       see also LMIN, MAX, MIN
14       
15%**************************************************|
16%       Serge Koptenko, Guigne International Ltd., |
17%       phone (709)895-3819, fax (709)895-3822     |
18%--------------06/03/97----------------------------|
19
20x=xx;
21len_x = length(x);
22        fltr=[1 1 1]/3;
23  if nargin <2, filt=0;
24        else
25x1=x(1); x2=x(len_x);
26        for jj=1:filt,
27        c=conv(fltr,x);
28        x=c(2:len_x+1);
29        x(1)=x1; 
30        x(len_x)=x2;
31        end
32  end
33lmval=[]; indd=[];
34i=2;            % start at second data point in time series
35    while i < len_x-1,
36        if x(i) > x(i-1)
37           if x(i) > x(i+1)     % definite max
38lmval =[lmval x(i)];
39indd = [ indd i];
40           elseif x(i)==x(i+1)&x(i)==x(i+2)     % 'long' flat spot
41%lmval =[lmval x(i)];   %1   comment these two lines for strict case
42%indd = [ indd i];      %2 when only  definite max included
43i = i + 2;              % skip 2 points
44           elseif x(i)==x(i+1)  % 'short' flat spot
45%lmval =[lmval x(i)];   %1   comment these two lines for strict case
46%indd = [ indd i];      %2 when only  definite max included
47i = i + 1;              % skip one point
48           end
49        end
50        i = i + 1;
51    end
52if filt>0 & ~isempty(indd),
53        if (indd(1)<= 3)|(indd(length(indd))+2>length(xx)),
54           rng=1;       %check if index too close to the edge
55        else rng=2;
56        end
57          for ii=1:length(indd),        % Find the real maximum value
58            [val(ii) iind(ii)] = max(xx(indd(ii) -rng:indd(ii) +rng));
59            iind(ii)=indd(ii) + iind(ii)  -rng-1;
60          end
61  indd=iind; lmval=val;
62else
63end
64
65
Note: See TracBrowser for help on using the repository browser.