function ang_ret=unwrap2(ang_in)
%UNWRAP2  Perform phase unwrapping.
%	ANG_OUT = UNWRAP2(ANG_IN) unwraps radian phase response ANG_IN
%	so that all phase discontinuities are minimized.
%
%	See also UNWRAP.

%	T Kite February 1997

angdiff=diff(ang_in);				% find angle jumps
ang_temp=angdiff-pi*floor(angdiff/pi);		% nearer to +/- pi?
f=find(abs(ang_temp-pi)<abs(ang_temp));
ang_temp(f)=ang_temp(f)-pi;
ang_ret=cumsum([ang_in(1) ang_temp']);		% reconstruct
