In this section from Wikipedia about IDFT, three methods are given for expressing the Inverse Discrete Fourier Transform in terms of the direct transform.
Being curious, I implemented the three methods in Octave:
% define TD signal N = 1024; n = [1:N]-1; f = [4 8]; x0 = sin(2*pi*n'*f/N); x0 = sum(x0'); % calculate FD spectrum y0 = fft(x0); % trick #1 y1 = fliplr(y0); x1 = fft(y1) / N; % trick #2 y2 = conj(y0); x2 = conj(fft(y2)) / N; % trick #3 y3 = imag(y0) + i*real(y0); x3 = fft(y3) / N; x3 = imag(x3) + i*real(x3); % plot results plot(n,x0,'m-o', n,x1,'r-*', n,x2,'g-^', n,x3,'bxo'); axis tight
If happens that tricks #2 and #3 work well, while trick #1 fails to generate the correct result.
Am I missing something in the explanation, or is there an error in Wikipedia?
UPDATE: It seems like the magnitude of the
y1 result is actually OK, it is just that the angle is doing funny things. Replacing the
plot line with:
plot(n,abs(x0),'m-o', n,abs(x1),'r-*', n,abs(x2),'g-^', n,abs(x3),'bxo');
shows the overlap.