Assignment 1: Recursive least square method parameter identification
Suppose the mathematical model of the identified system is described by the following formula:
Where x ( k ) is white noise with a variance of 0.1. Claim:
-
When the input signal u ( k ) is a white noise sequence with variance 1 , use the input and output data of the system to identify the parameters of the above model online;
-
When the input signal u ( k ) is an inverse M sequence with an amplitude of 1 , use the input and output data of the system to identify the parameters of the above model online;
-
When the input signal u ( k ) is a unit step signal , use the input and output data of the system to identify the parameters of the above model online;
Analyze and compare the effects of different input signals on the identification accuracy of system model parameters.
solution:
The code needs to be improved and has not been modified yet
【Reference Code】
① White noise sequence with variance 1
%递推最小二乘参数估计(RLS)
clear all; close all;
a=[1 -1.5 0.7 0.1]';
b=[1 2 1.5]'; d=2; %对象参数
na=length(a)-1; nb=length(b)-1; %na=3、nb=2为A、B阶次
L=400; %仿真长度
uk=zeros(d+nb,1); %输入初值:uk(i)表示u(k-i)
yk=zeros(na,1); %输出初值
u=randn(L,1); %输入采用白噪声序列
xi=sqrt(1)*randn(L,1); %白噪声序列 方差=1
theta=[a(2:na+1);b]; %对象参数真值
thetae_1=zeros(na+nb+1,1); %thetae初值
P=10^6*eye(na+nb+1);
for k=1:L
phi=[-yk;uk(d:d+nb)]; %此处phi为列向量
y(k)=phi'*theta+xi(k); %采集输出数据
%递推最小二乘法
K=P*phi/(1+phi'*P*phi);
thetae(:,k)=thetae_1+K*(y(k)-phi'*thetae_1);
P=(eye(na+nb+1)-K*phi')*P;
%更新数据
thetae_1=thetae(:,k);
for i=d+nb:-1:2
uk(i)=uk(i-1);
end
uk(1)=u(k);
for i=na:-1:2
yk(i)=yk(i-1);
end
yk(1)=y(k);
end
plot([1:L],thetae); %line([1,L],[theta,theta]);
xlabel('k'); ylabel('参数估计a、b');
legend('a_1','a_2','a_3','b_0','b_1','b_2'); axis([0 L -2 1.5]);
②Inverse M sequence with amplitude 1
%递推最小二乘参数估计(RLS)
clear all; close all;
a=[1 -1.5 0.7 0.1]';
b=[1 2 1.5]'; d=2; %对象参数
na=length(a)-1; nb=length(b)-1; %na=3、nb=2为A、B阶次
L=400; %仿真长度
uk=zeros(d+nb,1); %输入初值:uk(i)表示u(k-i)
yk=zeros(na,1); %输出初值
%u=randn(L,1); %输入采用白噪声序列
xi=sqrt(1)*randn(L,1); %白噪声序列 方差=1
theta=[a(2:na+1);b]; %对象参数真值
thetae_1=zeros(na+nb+1,1); %thetae初值
P=10^6*eye(na+nb+1);
%M序列及逆M序列的产生
%M序列长度 L=400; %仿真长度
x1=1; x2=1; x3=1; x4=0; %移位寄存器初值xi-1、xi-2、xi-3、xi-4
S=1; %方波初值
for k=1:L
M(k)=xor(x3,x4); %进行异或运算,产生M序列
IM=xor(M(k),S); %进行异或运算,产生逆M序列
if IM==0
u(k)=-1;
else
u(k)=1;
end
S=not(S); %产生方波
x4=x3; x3=x2; x2=x1; x1=M(k); %寄存器移位
phi=[-yk;uk(d:d+nb)]; %此处phi为列向量
y(k)=phi'*theta+xi(k); %采集输出数据
%递推最小二乘法
K=P*phi/(1+phi'*P*phi);
thetae(:,k)=thetae_1+K*(y(k)-phi'*thetae_1);
P=(eye(na+nb+1)-K*phi')*P;
%更新数据
thetae_1=thetae(:,k);
for i=d+nb:-1:2
uk(i)=uk(i-1);
end
uk(1)=u(k);
for i=na:-1:2
yk(i)=yk(i-1);
end
yk(1)=y(k);
end
plot([1:L],thetae); %line([1,L],[theta,theta]);
xlabel('k'); ylabel('参数估计a、b');
legend('a_1','a_2','a_3','b_0','b_1','b_2'); axis([0 L -2 4]);
③Unit step signal
%递推最小二乘参数估计(RLS)
clear all; close all;
a=[1 -1.5 0.7 0.1]';
b=[1 2 1.5]'; d=2; %对象参数
na=length(a)-1; nb=length(b)-1; %na=3、nb=2为A、B阶次
L=400; %仿真长度
uk=zeros(d+nb,1); %输入初值:uk(i)表示u(k-i)
yk=zeros(na,1); %输出初值
u=ones(L,1);%输入采用单位阶跃信号
xi=sqrt(1)*randn(L,1); %白噪声序列 方差=1
theta=[a(2:na+1);b]; %对象参数真值
thetae_1=zeros(na+nb+1,1); %thetae初值
P=10^6*eye(na+nb+1);
for k=1:L
phi=[-yk;uk(d:d+nb)]; %此处phi为列向量
y(k)=phi'*theta+xi(k); %采集输出数据
%递推最小二乘法
K=P*phi/(1+phi'*P*phi);
thetae(:,k)=thetae_1+K*(y(k)-phi'*thetae_1);
P=(eye(na+nb+1)-K*phi')*P;
%更新数据
thetae_1=thetae(:,k);
for i=d+nb:-1:2
uk(i)=uk(i-1);
end
uk(1)=u(k);
for i=na:-1:2
yk(i)=yk(i-1);
end
yk(1)=y(k);
end
plot([1:L],thetae); %line([1,L],[theta,theta]);
xlabel('k'); ylabel('参数估计a、b');
legend('a_1','a_2','a_3','b_0','b_1','b_2'); axis([0 L -2 1.5]);
Homework 2 Minimal variance self-tuning control experiment
Assuming that the mathematical model parameters of the controlled object with second-order pure lag are unknown or slowly time-varying, the following models are used in the simulation experiment:
Where x ( k ) is white noise with a variance of 0.1. Claim:
-
When the input yr( k ) is set as a step signal with an amplitude of 10 , the minimum variance direct self-correction control algorithm is designed to perform closed-loop control of the above objects;
-
When the input yr( k ) is set as a square wave signal with an amplitude of 10 , a direct self-correcting control algorithm with minimum variance is designed to perform closed-loop control of the above objects;
-
If the accused object model is changed to:
Repeat the above experiments (1) and (2), what is the control result? Analyze the reasons.
【Reference Code】
%最小二乘参数估计
clear all;
Homework 3 Model reference adaptive control experiment
Suppose the model parameters of the controlled object are unknown or slowly time-varying, but its state variables are fully observable,
In the simulation, the state equation is taken as:
Select reference model:
The model reference adaptive control system with fully observable state is shown in the figure below:
The controller adaptive law is:
【Reference Code】
%最小二乘参数估计
clear all;