N=500;
M=20;
n=1;
a1=-0.8;
h=zeros(M,n+1,3);
e=zeros(M,n,3);
for d=1:3
if d==1 delta=0.01;
else delta=0.05*(d-1);
end;
for k=1:M
b=0.2*randn(1,N);
y(1)=1;
for i=2:N
y(i)=-a1*y(i-1)+b(i);
end
for i=n+1:N
e(k,i,d)=y(i)-h(k,i,d)*y(i-1);
h(k,i+1,d)=h(k,i,d)+delta*y(i-1)*e(k,i,d);
end
end
end
for d=1:3
for i=1:N
em(i,d)=0;
hm(i,d)=0;
for j=1:M
em(i,d)=em(i,d)+e(j,i,d)^2;
hm(i,d)=hm(i,d)+h(j,i,d);
end
end
end
figure(1)
semilogy(1:150,em(1:150,1)),hold on
semilogy(1:150,em(1:150,2),'r'),hold on
semilogy(1:150,em(1:150,3),'g'),hold off
axis([0 150 0.01 1]),grid
title('Mean square error ')
xlabel('Samples')
gtext('\leftarrowd=0.01');
gtext('\leftarrowd=0.05');
gtext('\leftarrowd=0.1');
figure(2),plot(1:N,hm(1:N,1)),hold on
plot(1:N,hm(1:N,2),'r'),hold on
plot(1:N,hm(1:N,3),'g'),hold off,grid
title('Filter coeffcient evalution')
xlabel('Samples'),
gtext('d=0.01'), gtext('d=0.05'), gtext('d=0.1')
(2)从噪声中提取信号的程序如下:
N=1000;
n=200;
k=12;
Ts=1e-1
b=0.8*randn(1,N);
for i=1:N
xr(1,i)=sin(k*2*pi*i/N);
x(1,i)=xr(1,i)+b(i);
end
Cxx=10000*eye(n);
g=zeros(N,n);
h=zeros(N,n);
e=zeros(1,N);
y=zeros(1,N);
tr=zeros(1,N);
for i=n+1:N
g(i,:)=(Cxx*x(i-n+1:i)'./(1+x(i-n+1:i)*Cxx*x(i-n+1:i)'))';
e(1,i)=xr(i)-h(i-1,:)*x(i-n+1:i)';
h(i,:)=h(i-1,:)+e(1,i)*g(i,:);
Cxx=Cxx-g(i,:)'*x(i-n+1:i)*Cxx;
y(1,i)=h(i,:)*x(i-n+1:i)';
tr(1,i)=trace(Cxx);
end
figure(1)
plot(0:N-n,x(1,n:N)),grid
title('x(k) input singnal in V')
xlabel('Samples')
figure(2)
plot(0:N-n,xr(1,n:N),'r'),grid
axis([0 800 -1.2 1.2])
title('xr(k) reference singnal in V')
xlabel('Samples')
figure(3)
plot(0:N-n,e(1,n:N)),hold on
plot(0:N-n,y(1,n:N),'r'),hold on
grid
title('e(k) error and y(k) output in V')
xlabel('Samples')
gtext('e(k)'),gtext('y(k)')
figure(4)
plot(0:N-n,h(n:N,1)),hold on
plot(0:N-n,h(n:N,2),'r'),hold off
grid
title('a(n-1) and a(n-2) coeffcients evolution')
xlabel('Samples')
figure(5)
num1=fliplr(h(N,:));
sys1=tf(num1,1,Ts);
bode(sys1),hold off
title('Synthesized filter')
xlabel('Frequency in rad/s')
ylabel('Phase in degree;Module in dB')
figure(6)
semilogy(0:N-n,tr(n:N)),grid
title('Cxx matrix trace')
xlabel('Samples')
2022-04-01 16:56:03
1.67MB
自适应滤波器
1