
function[w,y,e,J,w1]=aalms1(x,dn,mu,M)
%function[w,y,e,J,w1]=aalms1(x,dn,mu,M);
%this function provides also the changes of filter coefficients
%versus iterations;
%all quantities are real-valued;
%x=input data to the filter; dn=desired signal;
%M=order of the filter;
%mu=step size; x and dn must be of the same length;
%each column of the matrix w1 contains the history of each 
%filter coefficient;
N=length(x);
y=zeros(1,N);
w=zeros(1,M); %initialized filter coefficient vector;
for n=M:N
	xl=x(n:-1:n-M+1); %for each n the vector xl is produced
	                 %of length M with elements from x in reverse order;
	y(n)=w*xl';
    e(n)=dn(n)-y(n);
	w=w+2*mu*e(n)*xl;
	w1(n-M+1,:)=w(1,:);
end;
J=e.^2;%J is the learning curve of the adaptive process;
%each column of the matrix w1 depicts the history of each filter
%coefficient;