function RespObj = phasewrap(RespObj);
%PHASEWRAP  Wrap/Unwrap phase data of Response Object.

%   Authors: A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.3 $  $Date: 2000/06/14 20:11:36 $

allProps = get(RespObj.response,'Undocumented');
LTIdisplayAxes = allProps.PlotAxes;

%---Find all phase lines
AllLines = findobj(LTIdisplayAxes(2:2:end,:),'Tag','LTIresponseLines');
AllYdata = get(AllLines,{'Ydata'});

%---Update YData of each phase line
for ctLines=1:length(AllYdata)
   AllYdata{ctLines} = unitconv(AllYdata{ctLines},RespObj.PhaseUnits,'rad');
   if strcmpi(RespObj.UnwrapPhase,'on')
      AllYdata{ctLines} = unwrap(AllYdata{ctLines});
   else
      AllYdata{ctLines} = mod(AllYdata{ctLines}+pi,2*pi)-pi;
   end
   AllYdata{ctLines} = unitconv(AllYdata{ctLines},'rad',RespObj.PhaseUnits);
end
set(AllLines,{'Ydata'},AllYdata);

%---Delete all linescan markers in phase axes
linescan('deleteall',LTIdisplayAxes);

%---Redraw stability margins (if on)
if strcmp(RespObj.StabilityMargin,'on')
   RespObj = pvset(RespObj,'StabilityMargin','off','StabilityMargin','on');
end
if strcmp(RespObj.AllStabilityMargin,'on')
   RespObj = pvset(RespObj,'AllStabilityMargin','off','AllStabilityMargin','on');
end

%---Rescale axes (must be done after redraw of plot options)
set(RespObj,'YlimMode','auto');
