g=100;%统计仿真次数为gN=1024;%输入信号抽样点数k=128;%滤波器阶数pp=zeros(g,N-k);%将每次独立循环的误差结果存于矩阵pp中,以便后面对其平均u=0.00026;%滤波器收敛因子forq=1:gt=1:N;a=1;s=a*sin(0.05*pi*t);%输入单信号sfigure(1);subplot(311)plot(s);%信号s时域波形title('信号s时域波形');xlabel('n');axis([0,N,-a-1,a+1]);xn=awgn(s,5);%加入均值为零的高斯白噪声%设置初值y=zeros(1,N);%输出信号yy(1:k)=xn(1:k);%将输入信号xn的前k个值作为输出y的前k个值w=zeros(1,k);%设置抽头加权初值e=zeros(1,N);%误差信号%用LMS算法迭代滤波fori=(k+1):NXN=xn((i-k+1):(i));y(i)=w*XN';e(i)=s(i)-y(i);w=w+u*e(i)*XN;endpp(q,:)=(e((k+1):N)).^2;endsubplot(312)plot(xn);%信号s时域波形title('信号s加噪声后的时域波形');subplot(313)plot(y);%信号s时域波形title('自适应滤波后的输出时域波形');forb=1:N-kbi(b)=sum(pp(:,b))/g;%求误差统计平均endfigure(2);%算法收敛曲线t=1:N-k;plot(t,bi,'r');title('收敛曲线');holdon%将每次循环的图形显示结果保存下来01002003004005006007008009001000-202信号s时域波形ns020040060080010001200-505信号s加噪声后的时域波形020040060080010001200-505自适应滤波后的输出时域波形010020030040050060070080090000.10.20.30.40.50.60.70.80.91算法收敛曲线