% M04-dtftconv.diary
% 2007-09-25

% Convolution in the DTFT domain
% We can't directly represent X(e^jw) in Matlab because it 
% is a continuous function, not a discrete function.  But 
% by sampling on a dense grid, we can come close enough
x = [8 5 4 3 2 2 1 1];
y = [-1 2 -1];
% Check the answer we're looking for
conv(x,y)
%ans =
%    -8    11    -2     0     0    -1     1    -1     1    -1
% Calculate the DTFT (actually, 128 samples via the DFT)
X = fft(x,128);
Y = fft(y,128);
% Multiply in the Fourier domain to effect convolution in the time domain
R = X.*Y;
% Convert back to time domain
r = ifft(R);
max(abs(imag(r))) 
%ans =
%   0
% matlab automatically detects it's a pure-real signal
% So what'd we get?
r(1:14)
%ans =
%  Columns 1 through 7 
%   -8.0000   11.0000   -2.0000   -0.0000    0.0000   -1.0000    1.0000
%  Columns 8 through 14 
%   -1.0000    1.0000   -1.0000    0.0000    0.0000   -0.0000    0.0000
% it's the same.  It has a lot of zeros on the end, though
