// LMS algorithm adaptive filtering for the Caltech 40m -- Sept. 2011 by M. Prijatelj #define nDOF 8 #define nWIT 21 #define nTAPS 1000 void ADAPT_XFCODE(double *in, int inSize, double *out, int outSize) { //First the DOFs and their switches //int nDOF=8; //int nTAPS=2000; //int nWIT=21; static double DOFctrl[nDOF]; //EPICS controls to switch the channels on/off static double DOF[nDOF][nTAPS]; //Actual DOF error signals //Then the seismometers static double WIT[nWIT][nTAPS]; //Then the parameters for the adaptive filtering //double nTAPS=in[nDOF+nWIT+1]; double mu; double decay; double reset; static double FILTER[nDOF][nTAPS]; //Filter coefficients static double AUXFILT[nDOF][nWIT][nTAPS]; //Aux. variable to hold 3D filter coeff matrix before it gets flattened into 2D [i][j] array static double OLDAUXFILT[nDOF][nWIT][nTAPS]; //Aux. variable to hold 3D filter coeff matrix before it gets flattened into 2D [i][j] array static double OUTPUT[nDOF][nTAPS]; double OUTPUTAUX[nDOF][nWIT][nTAPS]; static double timer; /* mu=in[nDOF+nWIT-1+1]; decay=in[nDOF+nWIT-1+2]; reset=in[nDOF+nWIT-1+3]; int i=0; int j=0; int k=0; int m=0; int n=0; if(reset != 0) timer=0; if(timer < 10) //Initialize the filter to 1, output to 0 { for(i=0;i