% Richard Duncan
% ECE 3133 - 01
%
% 
% Matlab Assignment No. 7:
% 
%  - A discrete signal is defined as a collection of the following points:
% 
%     x(n) = {0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0}
% 
%    Compute and display the frequency response using the discrete Fourier
%    transform (DFT) to compute the spectrum.
% 
%  - A system impulse response is defined by:
% 
%     h(n) = {1, 2, 1, 0, -1, -2}
% 
%    Compute and display the frequency response using the DFT.
% 
%  - Multiply these two frequency responses together, and compare to
%    the frequency response of the signal computed in Assignment No. 6.
% 
%  - Generate a 1 kHz sinewave and sample it at a sample frequency of 8 kHz.
% 
%    Plot the magnitude spectrum of the signal using 256 points of signal data.
% 
% All frequency response plots should show the magnitude in dB, phase
% in radians on a [-PI/2, PI/2] scale, and frequency on a linear scale.
% 
% This assignment is due by 04/10/98.
%

% define the data (zero pad h)
%

xt = [0 1 2 3 4 5 4 3 2 1 0];
ht0 = [1 2 1 0 -1 -2];
ht = [1 2 1 0 -1 -2 0 0 0 0 0];

% take the discrete fourier transform of both data sets
%
xf = fft(xt);
hf = fft(ht);

% display the frequency response of both signals
%
close;
plot(20*log10(abs(xf)),'r*');
hold;
plot(20*log10(abs(hf)),'b*');

figure;
plot(angle(xf),'r*');
hold;
plot(angle(hf),'b*');

% multiply the frequency responses together. In analog, this would be
% equivalent to convolution in the time domain. In digital, the range
% is limited so it will not be exactly the same answer.

for i = 1:size(xf,2)
	yf(i) = xf(i) * hf(i);
end	

figure;
plot(20*log10(abs(yf)),'k*');
figure;
plot(angle(yf),'k*');





