function q = rozbal(p, cutoff)
%UNWRAP Unwrap phase angle in radians.
%	UNWRAP(P) unwraps radian phases P by changing absolute
%	jumps greater than pi to their 2*pi complement.  It
%	unwraps columnwise with matrices.
%
%	UNWRAP(P,TOL) uses a jump tolerance of TOL rather
%	than the default TOL = pi.
%
%	See also ANGLE, ABS.

%	Original: J.N. Little, 4-1-87.
%	Revised:  C R. Denham, 4-29-90.
%	Copyright (c) 1984-94 by The MathWorks, Inc.

if nargin < 2, cutoff = pi; end   % Original UNWRAP used pi*170/180.

[m, n] = size(p); oldm = m;
if m == 1, p = p(:); [m, n] = size(p); end   % Column orientation.

pmin = min(p); pmin = pmin(ones(m, 1), :);   % To force REM to behave.
%POZOR moje zmena pridal jsem tam to real
p = rem(real(p - pmin),  pi) + pmin;           % Phases modulo pi.
%p = rem((p - pmin),  pi) + pmin;           % Phases modulo pi.

b = [p(1, :); diff(p)];                      % Differentiate phases.
c = -(b > cutoff); d = (b < -cutoff);        % Locations of jumps.
e = (c + d) .*  pi;                      % Array of pi jumps.
f = cumsum(e);                               % Integrate to get corrections.

q = p + f;                                   % Phases + corrections.
if oldm == 1, q = q.'; end                   % Reorient.
