% EXTRA DEMO:   POLAR PLOTS ON THE COMPLEX PLANE
%
% Program:      polar_plots_both.m
% Written by:   
% For:          EE 311
%               Extra Demo Computer Lab 1
% Date:         5-31-2001
% Purpose:      This program plots:  
%               cos(n*theta)*exp(j*theta) vs. theta for n=1:10; 
%               on the complex plane in both cartesian coordinates and
%               polar coordinates. The subplot command is used to show
%               both polar and cartesian plots on the same figure for 
%               each value of n.
clear all, close all

j=sqrt(-1);
theta=(0:pi/100:2*pi);

for n=1:10
   figure               % Creates a new figure window
   % Cartesian plot
   subplot(211)
   hold on              % Changes the hold property from off to on
   axis square
   grid                 % Puts a grid on the current figure
   if n~=1
      s=['cos(' num2str(n) '\theta) * \it{e}^{(j\theta)}'];
   else
      s=['cos(\theta) * \it{e}^{(j\theta)}'];
   end
   title(s)             
   xlabel('real axis')
   ylabel('imag axis')
   plot(cos(n*theta).*exp(j*theta))
                        % Plot function for current value of n
   % Polar plot
   subplot(212)
   polar(0,0)           % To keep the polar coordinates
   hold on              % Changes the hold property from off to on
   grid                 % Puts a grid on the current figure
   axis([-1.3 1.3 -1.3 1.3])   % Leave room for a title
   if n~=1
       s=['cos(' num2str(n) '\theta) * \it{e}^{(j\theta)}'];
    else
       s=['cos(\theta) * \it{e}^{(j\theta)}'];
   end
   title(s)
   xlabel('real axis'), ylabel('imag axis')
   z=cos(n*theta).*exp(j*theta);
   polar(angle(z),abs(z))      % Polar plot of the function
end
