📄 yunxing2c.m
字号:
%***********加上x4,x5,x6后,sWfx,sWfy,sWfz扩充为状态变量的情况下匀速运动下的常微分方程曲线图**********
clc
clear all
[t,y]=ode45('observability2c',[0:2:35*3600],[3*pi/(60*180);3*pi/(60*180);5*pi/(60*180);5*pi/(60*180);5*pi/(60*180);6*pi/(60*180);0.1;0.1;2*pi/(60*180);0;0;0]);
yy=zeros(501,12);
%每隔126点保存一次,放在矩阵yy
yy(1,:)=y(1,:);
for j=1:500
for i=2:127
yy(j+1,:)=y(126*j+1,:);
end
end
x1=yy(:,1)*180*60/pi;
x2=yy(:,2)*180*60/pi;
x3=yy(:,3)*180*60/pi;
x4=yy(:,4)*180*60/pi;
x5=yy(:,5)*180*60/pi;
x6=yy(:,6)*180*60/pi;
x7=yy(:,7);
x8=yy(:,8);
x9=yy(:,9)*180*60/pi;
x10=yy(:,10);
x11=yy(:,11);
x12=yy(:,12);
t=0:252/3600:35;
%舰体姿态误差角
figure(1)
subplot(3,4,1)
plot(t,x1,'b');
xlabel('时间t');
grid on;
subplot(3,4,2)
plot(t,x2,'r');
xlabel('时间t');
grid on;
subplot(3,4,3)
plot(t,x3,'y');
xlabel('时间t');
grid on;
%弹体误差角
subplot(3,4,4)
plot(t,x4,'b');
xlabel('时间t');
grid on;
subplot(3,4,5)
plot(t,x5,'b');
xlabel('时间t');
grid on;
subplot(3,4,6)
plot(t,x6,'b');
xlabel('时间t');
grid on;
%速度误差
subplot(3,4,7)
plot(t,x7,'g');
xlabel('时间t');
grid on;
subplot(3,4,8)
plot(t,x1,'m');
xlabel('时间t');
grid on;
%经度误差角
subplot(3,4,9)
plot(t,x9,'c');
xlabel('时间t');
grid on;
%扩充的状态变量
subplot(3,4,10)
plot(t,x10,'b');
xlabel('时间t');
grid on;
subplot(3,4,11)
plot(t,x11,'b');
xlabel('时间t');
grid on;
subplot(3,4,12)
plot(t,x12,'b');
xlabel('时间t');
grid on;
%重力加速度
g=9.80;
%各轴向的地速分量
Vx=8.0;
Vy=8.0;
Vz=0.0;
%地球的半径
R=6371020;
%当地的纬度角
angle=pi/4;
%地球自转角速度
Wie=7.2921158e-5;
%所测到各轴向的比力信息
fx=(2*Wie*cos(angle)+Vx/R)*Vz-(2*Wie*sin(angle)+Vx*tan(angle)/R)*Vy;
fy=(2*Wie*sin(angle)+Vx*tan(angle)/R)*Vx+Vy*Vz/R;
fz=-(2*Wie*cos(angle)+Vx/R)*Vx-Vy^2/R+g;
%系统的状态矩阵A阵
A1=zeros(17);
A1(1,2)= Vx*tan(angle)/R+Wie*sin(angle);
A1(1,3)=-Vx/R-Wie*cos(angle);
A1(1,8)=-1/R;
A1(1,10)=-1;
A1(2,1)=-Vx*tan(angle)/R-Wie*sin(angle);
A1(2,3)=-Vy/R;
A1(2,7)=1/R;
A1(2,9)=-Wie*sin(angle);
A1(2,11)=-1;
A1(3,1)=Vx/R+Wie*cos(angle);
A1(3,2)=Vy/R;
A1(3,7)=tan(angle)/R;
A1(3,9)=Wie*cos(angle)+Vx*sec(angle)^2/R;
A1(3,12)=-1;
A1(4,10)=1;
A1(4,13)=1;
A1(5,11)=1;
A1(5,14)=1;
A1(6,12)=1;
A1(6,15)=1;
A1(7,2)=-fz;
A1(7,3)=fy;
A1(7,7)=(Vy*tan(angle)-Vz)/R;
A1(7,8)=2*Wie*sin(angle)+Vx*tan(angle)/R;
A1(7,9)=2*Wie*sin(angle)*Vz+(2*Wie*cos(angle)+Vx*sec(angle)^2/R)*Vy;
A1(7,16)=1;
A1(8,1)=fz;
A1(8,3)=-fx;
A1(8,7)=-2*Wie*sin(angle)-2*Vx*tan(angle)/R;
A1(8,8)=-Vz/R;
A1(8,9)=-2*Wie*cos(angle)*Vx-Vx^2*sec(angle)^2/R;
A1(8,17)=1;
A1(9,8)=1/R;
%系统的观测矩阵C阵
C=zeros(5,17);
C(1,7)=1;
C(2,8)=1;
C(3,1)=-1;
C(3,4)=1;
C(4,2)=-1;
C(4,5)=1;
C(5,3)=-1;
C(5,6)=1;
%系统方程离散化
B=zeros(17,1);
D=zeros(5,1);
[a,b,c,d]=c2dm(A1,B,C,D,2);
%kalman滤波方程的定义
estX=zeros(17,127);
realX=zeros(17,127);
PP=zeros(17,17,126);
P=zeros(17,17,127);
K=zeros(17,5,127);
Z=zeros(5,127);
estXX=zeros(17,501);
CP=zeros(17,17,501);
%系统的观测噪声的协方差强度阵
RR=zeros(5);
RR(1,1)=0.01;
RR(2,2)=0.01;
RR(3,3)=(pi/(60*180))^2;
RR(4,4)=(pi/(60*180))^2;
RR(5,5)=(3*pi/(60*180))^2;
%系统噪声方差阵Q阵
Q=zeros(17);
Q(1,1)=(0.01*pi/(180*3600))^2;
Q(2,2)=(0.01*pi/(180*3600))^2;
Q(3,3)=(0.01*pi/(180*3600))^2;
Q(4,4)=(0.01*pi/(180*3600))^2;
Q(5,5)=(0.01*pi/(180*3600))^2;
Q(6,6)=(0.01*pi/(180*3600))^2;
Q(7,7)=(1e-5*g)^2;
Q(8,8)=(1e-5*g)^2;
%系统噪声
w=[0.01*pi/(180*3600)*randn(1);0.01*pi/(180*3600)*randn(1);0.01*pi/(180*3600)*randn(1);0.01*pi/(180*3600)*randn(1);0.01*pi/(180*3600)*randn(1);0.01*pi/(180*3600)*randn(1);(1e-5*g)*randn(1);(1e-5*g)*randn(1);0;0;0;0;0;0;0;0;0];
%量测噪声
v=[0.1*randn(1) 0.1*randn(1) pi/(60*180)*randn(1) pi/(60*180)*randn(1) 3*pi/(60*180)*randn(1)]';
%状态变量的初始值
estX(:,1)=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]';
realX(:,1)=[3*pi/(60*180) 3*pi/(60*180) 5*pi/(60*180) 5*pi/(60*180) 5*pi/(60*180) 6*pi/(60*180) 0.1 0.1 2*pi/(60*180) 0.1*pi/(180*3600) 0.1*pi/(180*3600) 0.1*pi/(180*3600) 0 0 0 1e-4*g 1e-4*g]';
%协方差矩阵的初始值
P(1,1,1)=(3*pi/(60*180))^2;
P(2,2,1)=(3*pi/(60*180))^2;
P(3,3,1)=(5*pi/(60*180))^2;
P(4,4,1)=(5*pi/(60*180))^2;
P(5,5,1)=(5*pi/(60*180))^2;
P(6,6,1)=(6*pi/(60*180))^2;
P(7,7,1)=0.01;
P(8,8,1)=0.01;
P(9,9,1)=(2*pi/(60*180))^2;
P(10,10,1)=(0.1*pi/(180*3600))^2;
P(11,11,1)=(0.1*pi/(180*3600))^2;
P(12,12,1)=(0.1*pi/(180*3600))^2;
P(13,13,1)=0.01;
P(14,14,1)=0.125^2;
P(15,15,1)=0.001^2;
P(16,16,1)=((1e-4)*g)^2;
P(17,17,1)=((1e-4)*g)^2;
CP(:,:,1)=P(:,:,1);
for j=1:500
for i=2:127
PP(:,:,i)=a*P(:,:,i-1)*a'+Q;
K(:,:,i)=PP(:,:,i)*c'*inv(c*PP(:,:,i)*c'+RR);
realX(:,i)=a*realX(:,i-1)+w;
Z(:,i)=c*realX(:,i)+v;
estX(:,i)=a*estX(:,i-1)+K(:,:,i)*(Z(:,i)-c*a*estX(:,i-1));
P(:,:,i)=PP(:,:,i)-K(:,:,i)*c*PP(:,:,i);
end
P(:,:,1)=P(:,:,127);
realX(:,1)=realX(:,127);
estX(:,1)=estX(:,127);
estXX(:,j+1)=estX(:,127);
CP(:,:,j+1)=P(:,:,127);
end
for i=1:501
est1(i)=estXX(1,i)*180*60/pi;
est2(i)=estXX(2,i)*180*60/pi;
est3(i)=estXX(3,i)*180*60/pi;
est4(i)=estXX(4,i)*180*60/pi;
est5(i)=estXX(5,i)*180*60/pi;
est6(i)=estXX(6,i)*180*60/pi;
est7(i)=estXX(7,i);
est8(i)=estXX(8,i);
est9(i)=estXX(9,i)*180*60/pi;
est10(i)=estXX(10,i)*180*3600/pi;
est11(i)=estXX(11,i)*180*3600/pi;
est12(i)=estXX(12,i)*180*3600/pi;
est13(i)=estXX(13,i);
est14(i)=estXX(14,i);
est15(i)=estXX(15,i);
est16(i)=estXX(16,i)/(1e-6*g);
est17(i)=estXX(17,i)/(1e-6*g);
PPP1(i)=CP(1,1,i)*(180*60/pi)^2;
PPP2(i)=CP(2,2,i)*(180*60/pi)^2;
PPP3(i)=CP(3,3,i)*(180*60/pi)^2;
PPP4(i)=CP(4,4,i)*(180*60/pi)^2;
PPP5(i)=CP(5,5,i)*(180*60/pi)^2;
PPP6(i)=CP(6,6,i)*(180*60/pi)^2;
PPP7(i)=CP(7,7,i);
PPP8(i)=CP(8,8,i);
PPP9(i)=CP(9,9,i)*(180*60/pi)^2;
PPP10(i)=CP(10,10,i)*(180*3600/pi)^2;
PPP11(i)=CP(11,11,i)*(180*3600/pi)^2;
PPP12(i)=CP(12,12,i)*(180*3600/pi)^2;
PPP13(i)=CP(13,13,i);
PPP14(i)=CP(14,14,i);
PPP15(i)=CP(15,15,i);
PPP16(i)=CP(16,16,i)/(1e-6*g)^2;
PPP17(i)=CP(17,17,i)/(1e-6*g)^2;
end
%画出状态变量的估计值的曲线图
t=0:252/3600:35;
figure(2)
subplot(3,1,1)
plot(t,est1,'b');
xlabel('time/h');
grid on;
subplot(3,1,2)
plot(t,est2,'b');
xlabel('time/h');
grid on;
subplot(3,1,3)
plot(t,est3,'b');
xlabel('time/h');
grid on;
figure(3)
subplot(3,1,1)
plot(t,est4,'b');
xlabel('time/h');
grid on;
subplot(3,1,2)
plot(t,est5,'b');
xlabel('time/h');
grid on;
subplot(3,1,3)
plot(t,est6,'b');
xlabel('time/h');
grid on;
figure(4)
subplot(3,1,1)
plot(t,est7,'b');
xlabel('time/h');
grid on;
subplot(3,1,2)
plot(t,est8,'b');
xlabel('time/h');
grid on;
subplot(3,1,3)
plot(t,est9,'b');
xlabel('time/h');
grid on;
figure(5)
subplot(3,1,1)
plot(t,est13,'b');
xlabel('time/h');
grid on;
subplot(3,1,2)
plot(t,est14,'b');
xlabel('time/h');
grid on;
subplot(3,1,3)
plot(t,est15,'b');
xlabel('time/h');
grid on;
t=0:252/3600:35;
figure(6)
subplot(3,3,1)
plot(t,est1'-x1,'b');
xlabel('time/h');
grid on;
subplot(3,3,2)
plot(t,est2'-x2,'b');
xlabel('time/h');
grid on;
subplot(3,3,3)
plot(t,est3'-x3,'b');
xlabel('time/h');
grid on;
subplot(3,3,4)
plot(t,est4'-x4,'b');
xlabel('time/h');
grid on;
subplot(3,3,5)
plot(t,est5'-x5,'b');
xlabel('time/h');
grid on;
subplot(3,3,6)
plot(t,est6'-x6,'b');
xlabel('time/h');
grid on;
subplot(3,3,7)
plot(t,est7'-x7,'b');
xlabel('time/h');
grid on;
subplot(3,3,8)
plot(t,est8'-x8,'b');
xlabel('time/h');
grid on;
subplot(3,3,9)
plot(t,est9'-x9,'b');
xlabel('time/h');
grid on;
figure(7)
subplot(3,3,1)
plot(t,est13'-x10,'b');
xlabel('time/h');
grid on;
subplot(3,3,2)
plot(t,est14'-x11,'b');
xlabel('time/h');
grid on;
subplot(3,3,3)
plot(t,est15'-x12,'b');
xlabel('time/h');
grid on;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -