Table 4.5 (continued )
fid fopen(`input.dat', `w'); % Open file input.dat for write
fprintf(fid, `int input [128] {\n');
fprintf(fid, `%5d, \n', round(x(1:127)*32767));
fprintf(fid, `%5d }; \n', round(x(128)*32767));
fclose(fid);
% Close file input.dat
fid fopen(`input.inc', `w'); % Open file input.inc for write
fprintf(fid, ` .word %5d\n', round(x*32767));
fclose(fid);
% Close file input.inc
This program generates 128 data samples. The data is then represented using the
Q15 format for the experiments. They are stored in the data files input.dat and
input.inc,and are included in the software package. The data file input.dat is
used by the C program exp4a.c for Experiment 4A,and the data file input.inc
is used by the assembly routine exp4b.asm for Experiment 4B.
4.6.1 Experiment 4A ± Twiddle Factor Generation
The sine±cosine generator we implemented for the experiments in Chapter 3 can be used
to generate the twiddle factors for comparing the DFT. Recall the assembly function
sine_cos.asm developed in Section 3.8.5. This assembly routine is written as a C-
callable function that follows the C55x C-calling convention. There are two arguments
passed by the function as sine_cos(angle, Wn). The first argument is passed
through the C55x temporary register T0 containing the input angle in radians. The
second argument is passed by the auxiliary register AR0 as a pointer Wn to the memory
locations,where the results of sin(angle) and cos(angle) will be stored upon return.
The following C example shows how to use the assembly sine±cosine generator inside
nested loops to generate the twiddle factors:
#define N128
#define TWOPIN0x7FFF)6 /* 2pkn/N, N 128
*/
int n, k, angle;
int Wn [2];
/* Wn [0] cos(angle), Wn [1] sin(angle) */
for(k 0; k < N ; k)
{
for(n 0; n < N ; n)
{
angle TWOPIN*k*n;
sine_cos(angle, Wn);
}
}
EXPERIMENTS USING THE TMS320C55X
167