14 Software Examples
14 – 12
FFT, you change the value of these constants and the twiddle factors.
The data buffers twid_real and twid_imag in program memory hold the
twiddle factor cosine and sine values. The inplacereal, inplaceimag,
inputreal and inputimag buffers in data memory store real and imaginary
data values. Sequentially ordered input data is stored in inputreal and
inputimag. This data is scrambled and written to inplacereal and
inplaceimag. A four-location buffer called padding is placed at the end of
inplaceimag to allow data accesses to exceed the buffer length. This buffer
assists in debugging but is not necessary in a real system. Variables (one-
location buffers) named groups, bflys_per_group, node_space and
blk_exponent are declared last.
The real parts (cosine values) of the twiddle factors are stored in the buffer
twid_real. This buffer is initialized from the file twid_real.dat. Likewise,
twid_imag.dat values initialize the twid_imag buffer that stores the sine
values of the twiddle factors. In an actual system, the hardware would be
set up to initialize these memory locations.
The variable called groups is initialized to N_div_2, and bflys_per_group
and node_space are each initialized to 2 because there are two butterflies
per group in the second stage of the FFT. The blk_exponent variable is
initialized to zero. This exponent value is updated when the output data is
scaled.
After the initializations are complete, two subroutines are called. The first
subroutine places the input sequence in bit-reversed order. The second
performs the FFT and calls the block floating-point scaling routine.
.MODULE/ABS=4
dit_fft_main;
.CONST
N=1024, N_div_2=512; {For 1024 points}
.VAR/PM/RAM/CIRC
twid_real [N_div_2];
.VAR/PM/RAM/CIRC
twid_imag [N_div_2];
.VAR/DM/RAM/ABS=0
inplacereal [N], inplaceimag [N], padding
[4];
.VAR/DM/RAM/ABS=H#1000
inputreal [N], inputimag [N];
.VAR/DM/RAM
groups, bflys_per_group, node_space,
blk_exponent;
.INIT
twid_real: <twid_real.dat>;
.INIT
twid_imag: <twid_imag.dat>;
.INIT
inputreal: <inputreal.dat>;
.INIT
inputimag: <inputimag.dat>;