/***************************************************************** * ale_fixpt_ccs.c - Fixed-point C program for ALE, can be tested * on C5000 using CCS ****************************************************************** * System configuration: * * d(n) --------------------------- * | / | * d(n-1)|----------------| out(n) V * ---->| ALE (LMS-FIR) |-----> |+|------> * |----------------| - | * /________________________| * * * d(n) is the input data from data file "in_int_ccs.dat" * *****************************************************************/ #include #include #include int in_buffer[500]; int out_buffer[500]; int err_buffer[500]; #define TRUE 1 /* Functions */ static int aleproc(int *input, int *output, int *error); static void dataIO(void); void main() { /*************************************************************** * Declare file pointers ***************************************************************/ int *input = &in_buffer[0]; int *output= &out_buffer[0]; int *error= &err_buffer[0]; asm(" STM #0, SWWSR"); /*************************************************************** * Start of main program ***************************************************************/ while(TRUE) { /* read in x(n) from data file and processing it */ dataIO(); aleproc(input, output, error); } } /* C function aleproc for AEC processing */ static int aleproc(int *input, int *output, int *error) { /*************************************************************** * Define variable arrays, define and clear variables ***************************************************************/ #define NL 16 /* length of FIR filter */ long yn = 0; /* y(n), output from the filter */ int xnbuf[16]; int w[16]; int i,j,k; int mu = 655; /* 33(0.001); 338(0.01); 655(0.02) */ int mu_err, err; int dn = 0; int size = 500; /*************************************************************** * Start of main program ***************************************************************/ for(k=0; k0; i--) { xnbuf[i]=xnbuf[i-1]; /* refresh signal buffer */ } xnbuf[0]=dn; dn = *input++; /* delayed version of xn */ /************************************************************* * FIR filtering: * y(n) = sum[x(n-i)*w(i)] for i = 0 to NL-1 *************************************************************/ yn = 0; for (j=0; j< NL; j++) { yn += ((long)(int)xnbuf[j] * (long)(int)w[j])>>15; } err = dn-yn; /* e(n) = d(n) - y(n) */ mu_err = (int)(((long)(int)mu*(long)(int)err)>>15); /* update filter coefficients */ for (k=0; k< NL; k++) { w[k]=w[k]+(int)(((long)(int)mu_err*(long)(int)xnbuf[k])>>15); } *output++ = (int)(yn); /* output y(n) to data file */ *error++ = (int)(err); /* output e(n) to data file */ } return(TRUE); } /* Function for dataIO */ static void dataIO() { return; }