Digital Signal Processing Reference
In-Depth Information
#include "dsk6713_aic23.h"
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;
#include <math.h>
#define PTS 256
//# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float x1[PTS]; //intermediate buffer
short i; //general purpose index variable
short buffercount = 0; //number of new samples in iobuffer
short flag = 0;
//set to 1 by ISR when iobuffer full
COMPLEX w[PTS];
//twiddle constants stored in w
COMPLEX samples[PTS];
//primary working buffer
main()
{
for (i = 0 ; i<PTS ; i++)
// set up twiddle constants in w
{
w[i].real = cos(2*PI*i/512.0); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/512.0); //Im component of twiddle constants
}
comm_intr();
//init DSK, codec, McBSP
while(1)
//infinite loop
{
while (flag == 0) ; //wait until iobuffer is full
flag = 0; //reset flag
for (i = 0 ; i < PTS ; i++) //swap buffers
{
samples[i].real=iobuffer[i]; //buffer with new data
iobuffer[i] = x1[i]; //processed frame to iobuffer
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0
FFT(samples,PTS); //call function FFT.c
for (i = 0 ; i < PTS ; i++) //compute magnitude
{
x1[i] = sqrt(samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag)/16;
}
x1[0] = 32000.0; //negative spike for reference
} //end of infinite loop
}
//end of main
interrupt void c_int11()
//ISR
{
output_sample((short)(iobuffer[buffercount]));//output from iobuffer
iobuffer[buffercount++]=(float)((short)input_sample());//input>iobuffer
if (buffercount >= PTS)
//if iobuffer full
{
buffercount = 0;
//reinit buffercount
flag = 1;
//set flag
}
}
FIGURE 6.13. FFT program of real-time input calling a C-coded FFT function
( FFT256c.c ).
Search WWH ::




Custom Search