%% Correct Phase Angle of Spiral
% Define the x- and y-coordinates of a spiral with phase angle from 0 to 6\pi. Plot the spiral.

t = linspace(0,6*pi,201);
x = t/pi.*cos(t);
y = t/pi.*sin(t);
plot(x,y)

% Find the phase angle of the spiral from the x- and y-coordinates using the atan2 function. The atan2 function returns the angle values within the closed interval from -\pi to \pi.

P = atan2(y,x);
plot(t,P)

% Note that this plot has discontinuities. Use unwrap to eliminate the discontinuities. unwrap adds multiples of \pm 2\pi when the phase difference between consecutive elements of P are greater than or equal to the jump threshold \pi radians. The shifted phase angle Q lies in the interval from 0 to 6\pi.

Q = unwrap(P);
plot(t,Q)

%
% Copyright 2019 The MathWorks, Inc.