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 ...
I would appreciate any comments.
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
% Copyright 2015
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