%	Problem 6.22

%
%	N = 512

UTP = 1e-3;
for k = 1:512
   t(k) = (k-1)*UTP/512;
   x(k)= cos(2*pi*(k-1)/512) + cos(2*pi*(k-1)*11/512) + cos(2*pi*(k-1)*5/512);
   f(k) = (k-1)/UTP;
end
plot(t,x),xlabel('time (sec)'),ylabel('x'),Title('Multitone Signal'),legend('Hit any key to continue')
disp('Hit any key to continue')
pause

%	z is the fast fourier transform of the signal x

z=fft(x,512);

%	The amplitudes of the cosin and sin components are a and b respectively
a0 = z(1)/512;

for k=2:512
a(k)=2*real(z(k))/512;
b(k)=-2*imag(x(k))/512;
end

%	The magnitude at each frequency is c(k)= sqrt[(a+jb)*(a-jb)]

c = (2/512)*sqrt(z.*conj(z));
c(1) = c(1)/2;

%	plotting only the first 15 frequency bins

stem(f(1:15),c(1:15)), xlabel('Frequency (Hz)'), ylabel('Amplitude'), title('Frequency Components')

