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

%   Authors: A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.4 $  $Date: 2000/06/14 20:09:39 $

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

%---Find all phase lines
AllLines = findobj(LTIdisplayAxes,'Tag','LTIresponseLines');
AllXdata = get(AllLines,{'Xdata'});

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

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

%---Redraw stability margin (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

%---Redraw grid (if on)
if strcmp(allProps.Grid,'on')
   RespObj = pvset(RespObj,'Grid','off','Grid','on');
end

%---Rescale
set(RespObj,'XlimMode','auto');
