MATLAB: Discrete Fourier Transform a dumthe approach

fft

I'm trying to understand how DFT works exactly. However, when experimenting around, I compared both Matlab generated FFT result with a dummy approach result and I get similar result. However, the Imaginary part of both result are negated. The code below is my implementation. The dummy approach is based on http://en.wikipedia.org/wiki/Discrete_Fourier_transform#Definition
Fs = 500; % Sampling frequency
T = 1/Fs; % Sample time
L = 1000; % Length of signal
x = cos(2*pi*100*t)+randn(size(t));
% Calculate by using Matlab build-in FFT
fdft = fft(x);
% A dummy way to calculate DFT
n = 0:L-1;
k = 0:L-1;
table = bsxfun(@times, n.', k);
dummydft = x * exp(-i * 2 * pi .* table ./ L )';
Is there anything I miss? Thank you.

Best Answer

Yes, the only problem you have is the use of the transpose operator. The transpose operator with complex-valued data returns the conjugate transpose by default, you want to use .'
Fs = 500; % Sampling frequency
T = 1/Fs; % Sample time
L = 1000; % Length of signal
t = 0:T:(1000*T)-T;
x = cos(2*pi*100*t)+randn(size(t));
x = x(:);
n = 0:L-1;
k = 0:L-1;
table = bsxfun(@times, n.', k);
dftmatrix = exp(-i * 2 * pi .* table ./ L ).';
dft1 = dftmatrix*x;
dft2 = fft(x);
Related Question