www.pudn.com > rls_rels.rar > rls_rels.m


%**********RLS-RELS改进递推增广最小二乘估计算法(例2.3.1)********** 
%**********cite为估值********* 
clear; 
 
M=600; 
randn('seed',4); 
e=sqrt(1)*randn(1,M+50); 
y(1)=0;y(2)=0; 
 
for t=1:M+20 
    y(t+2)=1.4*y(t+1)-0.45*y(t)+e(t+2)-0.3*e(t+1); 
end 
 
%********用RLS算法拟合高阶AR模型(n阶)*********** 
n=5; 
fai1(:,1)=zeros(1,n)'; B(:,1)=zeros(1,n)';P=eye(n)*9999; 
%*******递推过程******* 
for t=1:M 
    fai1(2:n,t+1)=fai1(1:n-1,t); 
    fai1(1,t+1)=-y(t); 
     
    r=1/(1+fai1(:,t+1)'*P*fai1(:,t+1)); 
    B(:,t+1)=B(:,t)+r*P*fai1(:,t+1)*(y(t+1)-fai1(:,t+1)'*B(:,t)); 
    P=P-r*(P*fai1(:,t+1))*(P*fai1(:,t+1))'; 
end 
 
%********RLS-RELS改进递推增广最小二乘估计算法********* 
fai(:,1)=[0,0,0]';cite(:,1)=[0,0,0]';P=eye(3)*9999;efang(1)=0; 
 
for t=1:M 
    ej(t)=y(t)-fai1(:,t)'*B(:,t+1); 
    efang(t+1)=efang(t)+1/(t+1)*(ej(t)^2-efang(t)^2); 
    if t-1<=0 
       fai(:,t+1)=[-y(t),0,ej(t)]';    
      else  
          fai(:,t+1)=[-y(t),-y(t-1),ej(t)]'; 
    end 
    cite(:,t+1)=cite(:,t)+P*fai(:,t+1)*(y(t+1)-fai(:,t+1)'*cite(:,t))/(1+fai(:,t+1)'*P*fai(:,t+1)); 
    P=P-(P*fai(:,t+1))*(P*fai(:,t+1))'/(1+fai(:,t+1)'*P*fai(:,t+1)); 
end 
t=1:M; 
a(1:M)=-1.4; 
b(1:M)=0.45; 
c(1:M)=-0.3; 
e(1:M)=1; 
subplot(2,2,1) 
title('参数a的收敛图'); 
plot(t,a(t),t,cite(1,t),'r'); 
subplot(2,2,2) 
title('参数b的收敛图'); 
plot(t,b(t),t,cite(2,t),'r'); 
figure; 
subplot(2,2,1) 
title('参数c的收敛图'); 
plot(t,c(t),t,cite(3,t),'r'); 
subplot(2,2,2) 
title('方差e的收敛图'); 
plot(t,e(t),t,efang(t),'r');