home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / DATAFUN.DI$ / UNWRAP.M < prev   
Encoding:
Text File  |  1993-03-07  |  1.2 KB  |  31 lines

  1. function q = unwrap(p, cutoff)
  2. %UNWRAP Unwrap phase angle in radians.
  3. %    UNWRAP(P) unwraps radian phases P by changing absolute
  4. %    jumps greater than pi to their 2*pi complement.  It
  5. %    unwraps columnwise with matrices.
  6. %
  7. %    UNWRAP(P,TOL) uses a jump tolerance of TOL rather
  8. %    than the default TOL = pi.
  9. %
  10. %    See also ANGLE, ABS.
  11.  
  12. %    Original: J.N. Little, 4-1-87.
  13. %    Revised:  C R. Denham, 4-29-90.
  14. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  15.  
  16. if nargin < 2, cutoff = pi; end   % Original UNWRAP used pi*170/180.
  17.  
  18. [m, n] = size(p); oldm = m;
  19. if m == 1, p = p(:); [m, n] = size(p); end   % Column orientation.
  20.  
  21. pmin = min(p); pmin = pmin(ones(m, 1), :);   % To force REM to behave.
  22. p = rem(p - pmin, 2 .* pi) + pmin;           % Phases modulo 2*pi.
  23.  
  24. b = [p(1, :); diff(p)];                      % Differentiate phases.
  25. c = -(b > cutoff); d = (b < -cutoff);        % Locations of jumps.
  26. e = (c + d) .* 2 .* pi;                      % Array of 2*pi jumps.
  27. f = cumsum(e);                               % Integrate to get corrections.
  28.  
  29. q = p + f;                                   % Phases + corrections.
  30. if oldm == 1, q = q.'; end                   % Reorient.
  31.