/***************************************************************** * ale_fixpt_intr.c - Fixed-point C program for ALE using * C5000 intrinsics and tested on CCS ****************************************************************** * System configuration: * * d(n) --------------------------- * | / | * d(n-1)|----------------| out(n) V * ---->| ALE (LMS-FIR) |-----> |+|--------> * |----------------| - | * /________________________| * ****************************************************************** * System simulation configuration: * * 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]; /*************************************************************** * Start of main program ***************************************************************/ while(TRUE) { /* read in x(n) from data file and processing it */ dataIO(); aleproc(input, output, error); } } /* C aleproc function for ALE 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 filter */ int xnbuf[16]; int w[16]; int i,j,k; int mu = 338; /* 33(0.001); 338(0.01); 655(0.02) */ int mu_err,err; int dn = 0; int size = 500; long temp = 0; /*************************************************************** * 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++) { temp = _lsmpy(xnbuf[j],w[j])>>16; yn = _lsadd(yn,temp); } err = dn-yn; /* e(n) = d(n) - y(n) */ mu_err = (int)(_lsmpy(2*mu,err)>>16); /* update filter coefficient */ for (k=0; k< NL; k++) { temp = (int)(_lsmpy(mu_err,xnbuf[k])>>16); w[k] = _lsadd(w[k],temp); } *output++ = (int)(yn); /* save output signal y(n) */ *error++ = (int)(err); /* save error signal e(n) */ } return(TRUE); } /* Function for dataIO */ static void dataIO() { return; }