# fft result order compared to direct implementation of DTFS using text book

To find the complex Fourier coefficients of this sequence, then The $k^{th}$ coeff. $c[k]$ is given by the DTFS formula

$$c[k]=% %TCIMACRO{\dsum \limits_{n=0}^{N-1}}% %BeginExpansion {\displaystyle\sum\limits_{n=0}^{N-1}} %EndExpansion x[n]\exp(-in\frac{2\pi}{N}k)$$

(Lets forget about the $1/N$ scaling for now). My question is on the ordering of the result.

For example, given $x=[1,1,0,0]$, hence $N=4$. Then applying the above gives

$c=2,c=1-i,c=0,c=1+i$

but Matlab's fft gives

c=fft([1 1 0 0]);


$c=2,c=1+i,c=0,c=1-i$

So matlab's $c$ is the formulas $c$ and Matlab's $c$ is the formulas $c$. So the order seems to be swapped around.

Ofcourse they are still complex conjugate of each others. So both answers are correct.

My question is on the order of terms and why they come out this way.

Any thought on what that is, and why the result is not in the same order as the formula gives? And if it is possible to make fft give the same order as the formula?

I found the problem. I used transpose to change row result from fft to column to make it easy to see. But I did not use the correct tranpose.

When I transposed the result, which was a row, to a column to easier to see, the terms got switch around. Here is an example

z=[1 2+1i 3 4+1i];
z'

1.0000 + 0.0000i
2.0000 - 1.0000i
3.0000 + 0.0000i
4.0000 - 1.0000i


I should have used non-conjugate tranpose:

z=[1 2+1i 3 4+1i];
z.'

1.0000 + 0.0000i
2.0000 + 1.0000i
3.0000 + 0.0000i
4.0000 + 1.0000i


So, terms are in correct order all along.

User error. sorry.

• Nope. Matlab produces the correct result: 2.0000 1.0000-1.0000i 0 1.0000+1.0000i. Be careful using the transpose operator when looking at the results – Hilmar Mar 17 '13 at 23:34
• yes, just noticed it myself. I was using transpose on the row result to see it better. I should have used non-conjugate transpose. my error. fft result is same order as formula. all ok. – Robert H Mar 17 '13 at 23:40

octave-3.2.3:1> fft([1 1 0 0])

While 4*ifft([1 1 0 0]) results in what you claim is Matlab's result.