//FastConvo.c FIR filter implemented using overlap-add fast convolution #include #include "coeffs.h" //time domain FIR coefficients #define PI 3.14159265358979 #define PTS 256 //number of points for FFT #define SQRT_PTS 16 //used in twiddle factor calc. #define RADIX 2 //passed to TI FFT routines #define DELTA (2*PI)/PTS typedef struct Complex_tag {float real, imag;} COMPLEX ; #pragma DATA_ALIGN(W, sizeof(COMPLEX)) #pragma DATA_ALIGN(samples, sizeof(COMPLEX)) #pragma DATA_ALIGN(h, sizeof(COMPLEX)) COMPLEX W[PTS/RADIX] ; //twiddle factor array COMPLEX samples[PTS]; //processing buffer COMPLEX h[PTS]; //FIR filter coefficients short buffercount = 0; //buffer count for iobuffer samples float iobuffer[PTS/2]; //primary input/output buffer float overlap[PTS/2]; //intermediate result buffer short i; //index variable short flag = 0; //set to indicate iobuffer full float a, b; //variables used in complex multiply short NUMCOEFFS = sizeof(coeffs)/sizeof(float); short iTwid[SQRT_PTS] ; //PTS/2 + 1 > sqrt(PTS) interrupt void c_int11(void) //ISR { output_sample((int)(iobuffer[buffercount])); iobuffer[buffercount++] = (float)(input_sample()); if (buffercount >= PTS/2) //for overlap-add method iobuffer { //is half size of FFT used buffercount = 0; flag = 1; } } main() { //set up array of twiddle factors digitrev_index(iTwid, PTS/RADIX, RADIX); for(i = 0 ; i < PTS/RADIX ; i++) { W[i].real = cos(DELTA*i); W[i].imag = sin(DELTA*i); } bitrev(W, iTwid, PTS/RADIX); //bit reverse order W for (i = 0 ; i