%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% GENERATE A SINE AND PLOT ITS SPECTRUM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A = 1;          % amplitude
phi = 0;        % phase offset (in radians)
f = 2;          % frequency
N = 8;          % 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*sin(x+phi);

% Finer discretization for plotting purposes only
xF=linspace(0,2*pi*f,20*N);
yF = A*sin(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('Amplitude');
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');

% Plot the spectrum and its magnitude
PlotSpectrum(y,N);
PlotSpectrumMagnitude(y,N);