function test_lms_rls
clear all;
N=5000;
L=32;
x=randn(1,N);
for(i = 1:length(x))
x(i) = x(i) + 1i*(randn(1,1));
end
b=0.1;
a=[1 -0.9];
%[b,a]=cheby1(2,12,0.8);
h=filter(b,a,[1 zeros(1,L-1)]);
y=filter(b,a,x);
[z1,h1]=mrls(x,y,0.9999,10000,L);
[z2,h2]=nlms(x,y,L,1);
yy=resample(y,2,1);
[zz1,hh1]=mrls2x(x,yy,0.9999,10000,L);
[zz2,hh2]=nlms2x(x,yy,L,0.5);
figure(1);
mmm=max(abs(x));
plot(abs(x-z1)/mmm);
hold on;
plot(abs(x-zz1)/mmm,'r');
title('Normalized error for rls (blue) and oversampled rls (red)');
grid on;
figure(2);
plot(abs(x-z2)/mmm);
hold on;
plot(abs(x-zz2)/mmm,'r');
title('Normalized error for lms (blue) and oversampled lms (red)');
grid on;
figure(3);
plot(hh1,'r');
hold on;
plot(hh2,'g');
title('Pulse responce of oversampled lms (green) and rls (red)');
grid on;
figure(4);
plot(abs(freqz(hh1,1,10000)),'r');
hold on;
plot(abs(freqz(hh2,1,10000)),'g');
title('Magnitude responce of oversampled lms (green) and rls (red)');
grid on;
return;
function [y,h]=mrls(t,r,lambda,delta,N);
P=delta*eye(N,N);
linv=1/lambda;
mem=zeros(1,N);
h=zeros(N,1);
y=[];
for k=1:length(r)
mem=[r(k) mem(1:end-1)];
y=[y mem*h];
e=t(k)-y(end);
gamma=1+linv*mem*P*mem';
P=linv*(P-(linv*P*mem'*mem*P/gamma));
h=h+P*mem'*e;
end;
return;
function [y,h]=mrls2x(t,r,lambda,delta,N);
P=delta*eye(N,N);
linv=1/lambda;
mem=zeros(1,N);
h=zeros(N,1);
y=[];
for k=2:2:length(r)
mem=[r(k) r(k-1) mem(1:end-2)];
y=[y mem*h];
e=t(k/2)-y(end);
gamma=1+linv*mem*P*mem';
P=linv*(P-(linv*P*mem'*mem*P/gamma));
h=h+P*mem'*e;
end;
return;
function [cs,coeff] = nlms(t,r,N,mu)
mem=zeros(1,N);
coeff=zeros(N,1);
p=1e-8;
cs=[];
for i=1:length(r)
p=p-abs(mem(end))^2;
mem=[r(i) mem(1:end-1)];
p=p+abs(mem(1))^2;
ms=mem*coeff;
e=t(i)-ms;
cs=[cs ms];
coeff=coeff+mem'*mu*e/p;
end;
return;
function [cs,coeff] = nlms2x(t,r,N,mu)
mem=zeros(1,N);
coeff=zeros(N,1);
p=1e-8;
cs=[];
for i=2:2:length(r)
p=p-abs(mem(end))^2-abs(mem(end-1))^2;
mem=[r(i) r(i-1) mem(1:end-2)];
p=p+abs(mem(1))^2+abs(mem(2))^2;
ms=mem*coeff;
e=t(i/2)-ms;
cs=[cs ms];
coeff=coeff+mem'*mu*e/p;
end;
return;