%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% THIS PLOTS A 3D VERSION OF THE COMPLEX SPECTRUM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A = 2;          % amplitude
phi = 0;        % phase
f = 2;          % frequency
N=8;            % number of samples; should be a power of 2 
%N = 256;       % try this next

n = 0:N-1;      % index
x = linspace(0,2*pi*f,N); 
y = A*sin(x+phi);

% Finer discretization for plotting purposes only
xF=linspace(0,2*pi*f,10*N);
yF = A*sin(xF+phi);
figure; plot(xF,yF,'k');
hold on;

% Plot the samples as vertical stems
stem(x,y,'filled');

% Shuffle the frequencies returned by the FFT
% to order them from negative to positive
Y=fftshift(fft(y,N));

% Plot the complex spectrum
figure; bar(n-N/2,abs(Y));
quiver3(n-N/2, zeros(1,N), zeros(1,N), zeros(1,N), real(Y), imag(Y), '.', 'LineWidth', 2)
xlabel('Frequency');
ylabel('Re');
zlabel('Im');
axis equal

% Plot only the magnitude of the spectrum
figure; bar(n-N/2,abs(Y));

