/*FFT128C.C - REAL-VALUED FFT WITH 128 POINTS. CALLS FFT_RL.ASM */ #include "math.h" /*standard library func */ #include "aiccomc.c" /*AIC comm routines */ #define N 128 /*size of FFT */ #define M 7 /*number of stages */ volatile int index = 0; /*input_output index */ float *IO_buffer, *data, *temp; /*--> array buffers */ int AICSEC[4] = {0x162C,0x1,0x3872,0x67}; /*AIC config data */ extern void fft_rl(int, int, float *); /*fft function protype */ void c_int05() /*interrupt handler func */ { PBASE[0x48] = ((int)(IO_buffer[index])) << 2; /*output data*/ IO_buffer[index] = (float)(PBASE[0x4C] << 16 >> 18); /*input data */ if (++index >= N) index = 0; /*increment index, reset = N*/ } main() { int loop; /* declare variable */ float real, img; /* declare variables */ AICSET_I(); /*config AIC for interrupt */ IO_buffer = (float *) calloc(N, sizeof(float)); /*input_out buffer */ data = (float *) calloc(N, sizeof(float)); /* fft data buffer */ while (1) /* create endless loop */ { fft_rl(N, M, (float *)data); /*call FFT function */ data[0] = sqrt(data[0]*data[0])/N; /*magnitude of X(0) */ for (loop = 1; loop < N/2; loop++) /*calculate X(1)..X(N/2-1) */ { real = data[loop]; /*real part */ img = data[N-loop]; /*imaginary part */ data[loop] = sqrt(real*real+img*img)/N; /*find magnitude */ } data[N/2] = sqrt(data[N/2]*data[N/2])/N; /*magnitude of X(N/2) */ for (loop = N/2+1; loop < N; loop++) /*X(N/2+1).. X(N-1) */ data[loop] = data[N-loop]; /*use symetry */ while (index); /*wait till IO_buffer empty */ temp = data; /*temp => data buffer */ data = IO_buffer; /*IO_buffer-->data buffer */ IO_buffer = temp; /*data buffer->new IO_buffer*/ IO_buffer[0] = -2048; /*sync pulse,negative spike */ } }