# [转载]【建模与辨识程序】递推的最小二乘辨识程序

%FLch3RLSeg3
clear%

L=15;% M

y1=1;y2=1;y3=1;y4=0;%

for i=1;%

x1=xor(y3,y4);%

x2=y1;%

x3=y2;%

x4=y3;%

y(i)=y4;%

if y(i)>0.5,u(i)=-0.03;%

else u(i)=0.03;%
M序列的值为"0",辨识的输入信号取“0.03”
end%

y1=x1;y2=x2;y3=x3;y4=x4;%

end%

figure(1);%
1个图形
stem(u),grid on%

z(2)=0;z(1)=0;%
z的前两个初始值为零
for k=3:15;%

z(k)=1.5*z(k-1)-0.7*z(k-2)+u(k-1)+0.5*u(k-2);%

end
%RLS

c0=[0.001 0.001 0.001 0.001]';%

p0=10^6*eye(4,4);%

E=0.000000005;%

c=[c0,zeros(4,14)];%

e=zeros(4,15);%

for k=3:15; %

h1=[-z(k-1),-z(k-2),u(k-1),u(k-2)]'; x=h1'*p0*h1+1; x1=inv(x); %

k1=p0*h1*x1;%

d1=z(k)-h1'*c0; c1=c0+k1*d1;%

e1=c1-c0;%

e2=e1./c0;%

e(:,k)=e2; %

c0=c1;%

c(:,k)=c1;%

p1=p0-k1*k1'*[h1'*p0*h1+1];%

p0=p1;%

if e2<=E break;%

end%

end%

c%

e%

%

a1=c(1,; a2=c(2,; b1=c(3,; b2=c(4,; ea1=e(1,; ea2=e(2,; eb1=e(3,; eb2=e(4,;
figure(2);%
2个图形
i=1:15;%

plot(i,a1,'r',i,a2,':',i,b1,'g',i,b2,':') %

title('Parameter Identification with Recursive Least Squares Method')%

figure(3); %
3个图形
i=1:15; %

plot(i,ea1,'r',i,ea2,'g',i,eb1,'b',i,eb2,'r:') %

title('Identification Precision') %

http://blog.sciencenet.cn/blog-748007-1204780.html

## 相关博文

GMT+8, 2021-6-25 14:04