% Script to compute cfft32 twiddle factor table
%
% 10apr2004 .. initial version .. K.Metzger

clear all;

M = 13;
MB = M-1;

N = 2^M;
ang = pi/N;      % table values use this step size
sf = 2^31-1;
fid = fopen('twiddle32.asm','w');
fprintf(fid, ';***************************************\n');
fprintf(fid, '; EECS 452 V1.0  10Apr2004 .. KM\n');
fprintf(fid, ';***************************************\n');
fprintf(fid, '  .sect "SARAM2"\n');
fprintf(fid, '  .def _twiddle32\n');
fprintf(fid, '_twiddle32:\n');

for idx = 0:N-1
    ridx = 0;
    test = idx;
    for idx2 = 0:M-1           % bit reverse the index value
        if mod(test,2) == 1
            ridx = 2*ridx+1;
        else
            ridx = 2*ridx;
        end
        test = floor(test/2);
    end
    c = cos(ang*ridx);
    chex = round(sf*c);
    if chex < 0 chex = chex+2^32; end
    fprintf(fid, '  .long 0x%08x  ; [%d]; %.6f\n', chex, ridx, c);

    s = sin(ang*ridx);
    shex = round(sf*s);
    if shex < 0 shex = shex+2^32; end
    fprintf(fid, '  .long 0x%08x  ; [%d]; %.6f\n', shex, ridx, s);
    
end

fclose(fid);