
function[w,J]=aaaveragenoiselms(a,b,mu,M,N,I)
%noise reduction lms filter with sine function as desired signal;
%function[w,J]=aaaveragelms(a,b,mu,M,N,I);a=controls the noise variance;
%b=controls the amplitude of the sine function;d=desired sine 
%function;M=number of filter coefficients;I=number of times to be averaged;
%N=number of data;
J=zeros(1,N);
w=zeros(1,M);
k=0:N-1;
for m=1:I
    x=a*randn(1,N)+b*sin(0.1*pi*k);
    d=b*sin(0.1*pi*k);
    for n=M:N
        x1=x(n:-1:n-M+1);
        y(n)=w*x1';
        e(n)=d(n)-y(n);
        w=w+2*mu*e(n)*x1;
    end;
    E(m,:)=e.^2;
end;
J=sum(E,1)/I;
