# how twiddles are calculated in the code snippet below from ti.com?

I am trying to port a C code for fft/ifft to a DSP (TMDSEVM6678LE) from ti.com. In one part of the code it tries to calculate the twiddle coefficients as you can see below; however, I can't understand why the matlab code is so different ...

void tw_gen_cn (double *w, int n)
{
int i, j, k;
const double PI = 3.141592654;

for (j = 1, k = 0; j <= n >> 2; j = j << 2)
{
for (i = 0; i < n >> 2; i += j)
{
w[k]     = cos (2 * PI * i / n);
w[k + 1] = sin (2 * PI * i / n);
w[k + 2] = cos (4 * PI * i / n);
w[k + 3] = sin (4 * PI * i / n);
w[k + 4] = cos (6 * PI * i / n);
w[k + 5] = sin (6 * PI * i / n);
k += 6;
}
}
}


The matlab code for twiddle coeffs. are as below:

% Program for generating n-length FFT's twiddle factor
% By: Denny Hermawanto
% Puslit Metrologi LIPI, INDONESIA
function [real_twiddle, im_twiddle] = tw_gen_cn(fft_length)
if nargin < 1
[real_twiddle, im_twiddle] = tw_gen_cn(8);
return;
end
% fft_length = input('Enter FFT length:');
for mm = 0:1:(fft_length-1)
theta = (-2*pi*mm*1/fft_length);
%   Twiddle factor equation
%   twiddle = exp(1i*theta);
%   Euler equation for complex exponential
%   e^(j*theta) = cos(theta) + j(sin(theta))

twiddle(mm+1) = cos(theta) + (1i*(sin(theta)));
real_twiddle = real(twiddle);
real_twiddle = real_twiddle';
im_twiddle = imag(twiddle);
im_twiddle = im_twiddle';

end;
end


These are similar and provide the same result. In the c code every other sample: w[k+1], w[k+3], etc, are the imaginary twiddle factors in the MATLAB code:

For instance the lines in C:

w[k]     = cos (2 * PI * i / n);
w[k + 1] = sin (2 * PI * i / n);


Corresponds to this line in MATLAB :

twiddle(mm+1) = cos(theta) + (1i*(sin(theta)));


Where "theta" in MATLAB is "2*PI*i/n" in c.