%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% GENERATE A COSINE AND PLOT ITS SPECTRUM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A = 1;          % amplitude
phi = 0;        % phase offset (in radians)
f = 3;          % frequency
N=16;            % number of samples; should be a power of 2 
%N =16;       % try this next

x = linspace(0, 2*pi*f*(N-1)/N, N); 
y = A*cos(x+phi);

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

% Plot the samples as vertical stems
stem(x,y,'b','filled', 'LineWidth', 2);
xlabel('x');
ylabel('y');
title('The Signal and the Samples');


% Plot only the Samples
figure; 
stem(0:N-1, y, 'b', 'filled', 'LineWidth', 2);
xlabel('Sample Number');
ylabel('Amplitude');
title('The Samples');


PlotSpectrum(y,N);
PlotSpectrumMagnitude(y,N);