Home > wafo > onedim > findcross.m

findcross   SunOS, Alpha, Linux x86, Windows

PURPOSE ^

Finds indices to level v up and downcrossings of a vector

SYNOPSIS ^

ind=findcross(x,v)

DESCRIPTION ^

 FINDCROSS Finds indices to level v up and downcrossings of a vector
 
   CALL: ind = findcross(x,v);
 
         x  = vector with sampled values.
 
         v  = level v. (Default 0). 
 
     ind = indices to the crossings in the original sequence x.
 
  Example 
   v = 0.75
   t = linspace(0,7*pi,250); x = sin(t);
   ind = findcross(x,v)
   plot(t,x,'.',t(ind),x(ind),'r.', t, ones(size(t))*v)
 
  See also dat2crossind, crossdef

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function ind=findcross(x,v)
002 %FINDCROSS Finds indices to level v up and downcrossings of a vector
003 %
004 %  CALL: ind = findcross(x,v);
005 %
006 %        x  = vector with sampled values.
007 %
008 %        v  = level v. (Default 0). 
009 %
010 %    ind = indices to the crossings in the original sequence x.
011 %
012 % Example 
013 %  v = 0.75
014 %  t = linspace(0,7*pi,250); x = sin(t);
015 %  ind = findcross(x,v)
016 %  plot(t,x,'.',t(ind),x(ind),'r.', t, ones(size(t))*v)
017 %
018 % See also dat2crossind, crossdef
019 
020 % there is also a mex version of this which is much faster,
021 % which is run instead if compiled and located before this file 
022 % in the MATLAB search path.
023 
024 % Tested on: Matlab 5.3, 5.2 5.1
025 
026 % History: 
027 % revised pab Feb2004
028 % revised pab 13.06.2001
029 % -Added example
030 % - fixed a bug: this .m file previosly only returned zero crossings.
031 % by pab 17.07.1997
032 
033 if nargin<2|isempty(v),
034   v=0;
035 end
036 xn = x(:);
037 n  =length(xn);
038 
039 % Trick to avoid turning points on the crossinglevel.
040 ind = find(xn(2:(n-1))==v);
041 for ix=ind.',
042    xn(ix+1)=xn(ix);
043 end
044 
045 % indices to local level crossings ( without turningpoints)
046 ind = find( (((xn(1:(n-1))>=v) .* (xn(2:n)<v)) | ...
047       ((xn(1:(n-1))<=v) .* (xn(2:n) > v))) )  ;
048 
049 
050 return
051 
052 
053

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003