# Finding the twiddle factors for FFT algorithm I am trying to calculate the twiddle factors for the FFT algorithm and the iFFT algorithm, but i am unsure if i have it correctly calculated and was hoping some one could tell me if i have gone wrong as currently i get the wrong output for my FFT and i believe the twiddle factors might be the reason.

This is my code (in C#) to calculate them:

For `_N = 4` and `_passes = log(_N)/log(2) = 2`

``        //twiddle factor buffer creation         _twiddlesR = new Vector2[_N*_passes]; //inverse FFT twiddles         _twiddlesF = new Vector2[_N*_passes]; //forward FFT twiddles                  for (int stage = 0; stage < _passes; stage++)         {             int span = (int)Math.Pow(2, stage); // 2^n              for (int k = 0; k < _N; k++) // for each index in series             {                 int arrIndex = stage * _N + k; // get index for 1D array                                  // not 100% sure if this is correct for theta ???                 float a = pi2 * k / Math.Pow(2,stage+1);                  //inverse FFT has exp(i * 2 * pi * k / N )                 Vector2 twiddle = new Vector2(Math.Cos(a), Math.Sin(a));                  //forward FFT has exp(-i * 2 * pi * k/ N ) which is the conjugate                 Vector2 twiddleConj = twiddle.ComplexConjugate();                  /*this ternary checks if the k index is top wing or bottom wing                 the bottom wing requires -T top wing requires +T*/                  float coefficient = k % Math.Pow(2, stage + 1) < span ? 1 : -1;                  _twiddlesR[arrIndex] = coefficient * twiddle;                 _twiddlesF[arrIndex] = coefficient * twiddleConj;             }         } ``

My debug data:

For inverse FFT twiddles:

``First pass 1 + 0i 1 + 0i 1 + 0i 1 + 01 Second pass: 1 + 0i 0 + i 1 + 0i 0 + i ``

For forward FFT twiddles:

``First pass 1 + 0i 1 + 0i 1 + 0i 1 + 01 Second pass 1 + 0i 0 - i 1 + 0i 0 - i ``

I am not convinced i have it right, but i am unsure what i have got wrong. Hoping some one who has a better understanding of this algorithm can spot my math error. Posted on Categories proxies