zl程序教程

您现在的位置是:首页 >  其它

当前栏目

LMS自适应滤波

适应 滤波
2023-09-11 14:15:33 时间

1.问题描述:

 LMS自适应滤波

2.部分程序:

 

clear all;
t=0:0.0001:1.9999;
N=20000;

%生成有用信号s
s=3*sin(2*pi*100*t);
figure(1);
subplot(3,1,1);
plot(t,real(s));
title('有用信号s');
xlabel('n');
ylabel('s');

%生成两个相关的噪声n1,n2
n1=wgn(1,N,3);
n2=zeros(1,N);
n2(1:18000)=n1(1:18000);
n3=wgn(1,N,3);
n2(18001:N)=n3(18001:N);
figure(1);
subplot(3,1,2);
plot(t,real(n2));
title('噪声参考输入');
xlabel('n');
ylabel('n2');

%输入端期望信号d=s+n1
d=s+n1;
subplot(3,1,3);
plot(t,real(d));
title('含有噪声的信号d');
xlabel('n');
ylabel('d');


%初始化各参量
M=8;  %滤波器阶数
w=zeros(M,1); %滤波器权系数
mu=0.01;  %更新步长
iter=2000; %迭代次数
x=zeros(M,1); %输入矢量

%LMS循环算法
for i=1:iter
    i
   x(1)=n2(i);   
   y(i)=dot(w,x);
   e=d(i)-y(i);
   w=w+mu*e*x;
   
    for j=M:-1:2
        x(j)=x(j-1);    
    end

    error(i)=e; %保存输出误差
   cost(i)=e*e;  
end

   

figure(2);
subplot(1,1,1);
plot(error);
title('除噪后的信号');
xlabel('n');
ylabel('error');

3.仿真结论:

 

B0025