/*ADAPTSH.C - ADAPTIVE FILTER WITH SHIFTED INPUT */ #include "math.h" #define beta 0.005 /*rate of convergence */ #define N 30 /*# of coefficients */ #define NS 128 /*# of output samples */ #define pi 3.1415926 #define shift 90 /*desired amount of shift*/ #define Fs 8000 /*sampling frequency */ #define inp 1000*sin(2*pi*T*1000/Fs) /*input signal*/ main() { int I, T; double xin, x, ys, D, E, Y1; double W[N+1]; double Delay[N+1]; volatile int *IO_OUTPUT = (volatile int*) 0x809d00; ys = 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; /*input between 1 and -1 */ if (ys >= xin) /*is signal rising or falling */ x = acos(xin); /*signal is falling */ else /*otherwise */ x=asin(xin)-(pi/2); /*signal is rising */ x = x - (shift); /*shift */ Delay[0]=cos(x); /*shifted output=filter's input*/ D = inp; /*input data */ Y1 = 0; /*init output */ ys = xin; /*store input value */ for (I=0; I 0; I--) { W[I]=W[I]+(beta*E*Delay[I]); /*update weights */ if (I != 0) Delay[I] = Delay[I-1]; /*update delays */ } *IO_OUTPUT++ = Y1; /*overall output */ } }