⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yaoyao3.m

📁 自适应的LMS算法和RLS算法的实现 以及其比较
💻 M
字号:
clear all
clc

W=rls_2(100,1,1.6,-0.95);
[temp_W1,temp_W2,mean_W1,mean_W2]=lms_2(2500,0.001,1.6,-0.95);

figure(1)
subplot(2,1,1)
plot(W(1,:),'b');
hold on
plot(W(2,:),'r');
xlabel( '迭代次数 n' );
ylabel( '权向量 幅度' );
title('RLS算法λ =1');
legend('权值w1收敛曲线','权值w2收敛曲线');

subplot(2,1,2)
plot(temp_W1(1,:),'b--');
hold on
plot(temp_W2(1,:),'r--');
hold on
plot(mean_W1,'r');
hold on
plot(mean_W2,'b');
xlabel( '迭代次数 n' );
ylabel( '权向量 幅度' );
title('LMS算法μ=0.001');
legend('单次权值w1收敛曲线','单次权值w2收敛曲线','平均权值w1收敛曲线','平均权值w2收敛曲线');

W=rls_2(100,1,1.8,-0.95);
[temp_W1,temp_W2,mean_W1,mean_W2]=lms_2(2500,0.001,1.8,-0.95);

figure(2)
subplot(2,1,1)
plot(W(1,:),'b');
hold on
plot(W(2,:),'r');
xlabel( '迭代次数 n' );
ylabel( '权向量 幅度' );
title('RLS算法λ =1');
legend('权值w1收敛曲线','权值w2收敛曲线');

subplot(2,1,2)
plot(temp_W1(1,:),'b--');
hold on
plot(temp_W2(1,:),'r--');
hold on
plot(mean_W1,'r');
hold on
plot(mean_W2,'b');
xlabel( '迭代次数 n' );
ylabel( '权向量 幅度' );
title('LMS算法μ=0.001');
legend('单次权值w1收敛曲线','单次权值w2收敛曲线','平均权值w1收敛曲线','平均权值w2收敛曲线');

u=0.005;
lende=1-u;
W=rls_2(100,lende,1.6,-0.95);
[temp_W1,temp_W2,mean_W1,mean_W2]=lms_2(2500,u,1.6,-0.95);
figure(3)
subplot(2,1,1)
plot(W(1,:),'b');
hold on
plot(W(2,:),'r');
xlabel( '迭代次数 n' );
ylabel( '权向量 幅度' );
title('RLS算法λ =1-μ=0.995');
legend('权值w1收敛曲线','权值w2收敛曲线');

subplot(2,1,2)
plot(temp_W1(1,:),'b--');
hold on
plot(temp_W2(1,:),'r--');
hold on
plot(mean_W1,'r');
hold on
plot(mean_W2,'b');
xlabel( '迭代次数 n' );
ylabel( '权向量 幅度' );
title('LMS算法μ=0.005');
legend('单次权值w1收敛曲线','单次权值w2收敛曲线','平均权值w1收敛曲线','平均权值w2收敛曲线');
lms_2.m
function [temp_W1,temp_W2,mean_W1,mean_W2]=lms_2(N,u,a1,a2)
for M=1:10
x=zeros(1,N); 
V=randn(1,N);         %输入信号
W=zeros(2,N);
e=zeros(1,N);    
for n=3:N
    x(n)=a1*x(n-1)+a2*x(n-2)+V(n);  %期望信号
    X=[x(n-1) x(n-2)]';
    e(n)=x(n)-W(:,n)'*X;                 %误差
    W(:,n+1)=W(:,n)+u*e(n)*X;         %迭代公式
    e(n)=e(n)*e(n);
end

temp_W1(M,:)=W(1,:);
temp_W2(M,:)=W(2,:);
temp_e(M,:)=e(:);

end 
mean_W1=mean(temp_W1(1:M,:));
mean_W2=mean(temp_W2(1:M,:));
mean_e=mean(temp_e(1:M,:));
rls_2.m
function W=rls_2(N,lende,a1,a2)
x=zeros(1,N); 
V=randn(1,N);         %输入信号
m=2;                  %阶数
W=zeros(m,N);
C=1000*eye(m); 
for n=3:N
    x(n)=a1*x(n-1)+a2*x(n-2)+V(n);  %期望信号
    X=[x(n-1) x(n-2)]';                        %%像预测
    u(n)=X'*C*X;                 
    gm=C*X/(lende+u(n));
    W(:,n)=W(:,n-1)+gm*[x(n)-X'*W(:,n-1)];
    C=(1/lende)*[C-gm*X'*C];
End

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -