% sampledRotatingPhasor - effect of sampling on rotating phasor

%% parameters
fs  = 10;     % sampling rate in frames per second
dur = 10;    % signal duration in seconds

ff  = 9.5;  % frequency of rotating phasor
phi = 0;     % initial phase of phasor
A   = 1;     % amplitude

%% Prepare for plot
TitleString = sprintf('Rotating Phasor: f_d = %5.2f', ff/fs);
figure(1)

% unit circle (plotted for reference)
cc = exp(1j*2*pi*(0:0.01:1));
ccx = A*real(cc);
cci = A*imag(cc);

%% Animation
for tt = 0:1/fs:dur
    tic; % establish time-reference
    plot(ccx, cci, ':', ...
        [0 A*cos(2*pi*ff*tt+phi)], [0 A*sin(2*pi*ff*tt+phi)], '-ob');
    axis('square')
    axis([-A A -A A]);
    title(TitleString)
    xlabel('Real')
    ylabel('Imag')
    grid on;
 
    drawnow % force plots to be redrawn
    
    te = toc;
    
    % pause until the next sampling instant, if possible
    if ( te < 1/fs)
        pause(1/fs-te)
    end
end

