cboboc 发表于 2010-5-7 09:58

extr函数

请问各位高手,在这个函数中,带红色的部分
是什么意思呢?通过x1=x(1:m-1);
x2=x(2:m);
indzer = find(x1.*x2<0);
这几个语句,不是可以求出来极值点的位置吗?

function = extr(x,t);
% = EXTR(x,t) finds extrema and zero-crossings
%
% inputs : - x : analyzed signal
%          - t (optional) : sampling times, default 1:length(x)
%
% outputs : - indmin = indices of minima
%         - indmax = indices of maxima
%         - indzer = indices of zero-crossings
if(nargin==1)
t=1:length(x);
end
m = length(x);
x1=x(1:m-1);
x2=x(2:m);
indzer = find(x1.*x2<0);
if any(x == 0)
iz = find( x==0 );
indz = [];
if any(diff(iz)==1)
    zer = x == 0;
    dz = diff();
    debz = find(dz == 1);
    finz = find(dz == -1)-1;
    indz = round((debz+finz)/2);
else
    indz = iz;
end
indzer = sort();
end

d = diff(x);
n = length(d);
d1 = d(1:n-1);
d2 = d(2:n);
indmin = find(d1.*d2<0 & d1<0)+1;
indmax = find(d1.*d2<0 & d1>0)+1;
if any(d==0)

imax = [];
imin = [];
   
bad = (d==0);
dd = diff();
debs = find(dd == 1);
fins = find(dd == -1);
if debs(1) == 1
    if length(debs) > 1
      debs = debs(2:end);
      fins = fins(2:end);
    else
      debs = [];
      fins = [];
    end
end
if length(debs) > 0
    if fins(end) == m
      if length(debs) > 1
      debs = debs(1:(end-1));
      fins = fins(1:(end-1));
      else
      debs = [];
      fins = [];
      end      
    end
end
lc = length(debs);
if lc > 0
    for k = 1:lc
      if d(debs(k)-1) > 0
      if d(fins(k)) < 0
          imax = ;
      end
      else
      if d(fins(k)) > 0
          imin = ;
      end
      end
    end
end

if length(imax) > 0
    indmax = sort();
end
if length(imin) > 0
    indmin = sort();
end

end

dzkt 发表于 2010-5-8 15:45

if any(diff(iz)==1) % find nonconsecutive zeros
    zer = x == 0;
    dz = diff();
    debz = find(dz == 1); % find peak-side of a zero
    finz = find(dz == -1)-1; % find trough-side of a zero
    indz = round((debz+finz)/2); % avg peaks and troughs to get zero crossings
页: [1]
查看完整版本: extr函数