%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% GENERATE A SIGNAL AND PLOT ITS SPECTRUM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

N=8;         % number of samples; should be a power of 2 
fs = N;      % sampling frequency

freqA =  2;  % the first frequency
freqB =  3;  % the second frequency

A = 1;       % Amplitude for freqA
B = 1;       % Amplitude for freqB

% Create time interval from 0 to 1 second
t = 0 : 1/fs : 1;
	
% Calculate the two waves and add them
waveA = A*sin(2 * pi * freqA * t);
waveB = B*cos(2 * pi * freqB * t);

waveMixture = waveA + waveB;

% Plot the sampled wave
figure;
stem(t(1:N), waveMixture(1:N),'b','filled', 'LineWidth', 2);
xlabel('Time (seconds)');
ylabel('Amplitude');
title('The sampled signal');

% Sample at a higher frequency (for drawing purposes only)
Nd = N*N;            % number of drawing samples
fd = Nd;             % sampling frequency for drawing
td = 0 : 1/fd : 1;
waveAD = A*sin(2 * pi * freqA * td); % recompute the waves
waveBD = B*cos(2 * pi * freqB * td);
waveMixtureD = waveAD + waveBD;
hold on;  plot(td, waveMixtureD, 'k');

PlotSpectrum(waveMixture(1:N), N);