/*ADAPTTB.C - ADAPTIVE FILTER USING ASIN, ACOS TABLE*/ #define beta 0.005 /*rate of adaptation */ #define N 30 /*order of filter */ #define NS 128 /*number of samples */ #define Fs 8000 /*sampling frequency */ #define pi 3.1415926 #define inp 1000*sin(2*pi*T*1000/Fs) /*input */ #include "scdat" /*table for asin, acos */ #include "math.h" main() { int I, J, T, Y; double E, yo, xin, out_data; double W[N+1]; double Delay[N+1]; volatile int *IO_OUTPUT = (volatile int*) 0x809d00; yo=0; for (T=0; T < N; T++) { W[T] = 0.0; Delay[T] = 0.0; } for (T=0; T < NS; T++) /*# of output samples */ { xin = inp/1000; /*scale for range between 1 and -1*/ Y = ((xin)+1)*100; /*step up array between 0 and 200 */ if (yo > xin) /*is signal falling or rising */ Delay[0] = yc[Y]; /*signal is falling, acos domain */ else /*otherwise */ Delay[0] = ys[Y]; /*signal is rising, asin domain */ out_data = 0; /*init filter output to zero */ yo = xin; /*store input */ for (I=0; I<=N; I++) out_data +=(W[I]*Delay[I]); /*filter output */ E = xin - out_data; /*error signal */ for (J=N; J > 0; J--) { W[J]=W[J]+(beta*E*Delay[J]); /*update coefficients */ if (J != 0) Delay[J] = Delay[J-1]; /*update data samples */ } *IO_OUTPUT++ = out_data*1000; /* output signal */ } }