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

📄 yunxing2c2.m

📁 这些程序都是经过本人和许许多多工作过学习过的老师同学
💻 M
📖 第 1 页 / 共 2 页
字号:
%***********加上x4,x5,x6后,且观测值y1,y2,y3,y4,y5为已知,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,'b');
xlabel('时间t');
grid on;

subplot(3,4,3)
plot(t,x3,'b');
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,'b');
xlabel('时间t');
grid on;

subplot(3,4,8)
plot(t,x1,'b');
xlabel('时间t');
grid on;

%经度误差角

subplot(3,4,9)
plot(t,x9,'b');
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阵

C1=zeros(5,17);

C1(1,7)=1;
C1(2,8)=1;
C1(3,1)=-1;
C1(3,4)=1;
C1(4,2)=-1;
C1(4,5)=1;
C1(5,3)=-1;
C1(5,6)=1;

%系统方程离散化

B1=zeros(17,1);
D1=zeros(5,1);

[a1,b1,c1,d1]=c2dm(A1,B1,C1,D1,2);

%kalman滤波方程的定义

estX1=zeros(17,127);
realX1=zeros(17,127);
PP1=zeros(17,17,126);
P1=zeros(17,17,127);
K1=zeros(17,5,127);
Z1=zeros(5,127);
estXX1=zeros(17,501);
CP1=zeros(17,17,501);

%系统的观测噪声的协方差强度阵

RR1=zeros(5);

RR1(1,1)=0.01;
RR1(2,2)=0.01;
RR1(3,3)=(pi/(60*180))^2;
RR1(4,4)=(pi/(60*180))^2;
RR1(5,5)=(3*pi/(60*180))^2;

%系统噪声方差阵Q阵

Q1=zeros(17);

Q1(1,1)=(0.01*pi/(180*3600))^2;
Q1(2,2)=(0.01*pi/(180*3600))^2;
Q1(3,3)=(0.01*pi/(180*3600))^2;
Q1(4,4)=(0.01*pi/(180*3600))^2;   
Q1(5,5)=(0.01*pi/(180*3600))^2;
Q1(6,6)=(0.01*pi/(180*3600))^2;
Q1(7,7)=(1e-5*g)^2;              
Q1(8,8)=(1e-5*g)^2; 

%系统噪声

w1=[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];

%量测噪声

v1=[0.1*randn(1) 0.1*randn(1) pi/(60*180)*randn(1) pi/(60*180)*randn(1) 3*pi/(60*180)*randn(1)]';

%状态变量的初始值

estX1(:,1)=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]';

realX1(:,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]';

%协方差矩阵的初始值

P1(1,1,1)=(3*pi/(60*180))^2;
P1(2,2,1)=(3*pi/(60*180))^2;
P1(3,3,1)=(5*pi/(60*180))^2;
P1(4,4,1)=(5*pi/(60*180))^2;
P1(5,5,1)=(5*pi/(60*180))^2;
P1(6,6,1)=(6*pi/(60*180))^2;
P1(7,7,1)=0.01;
P1(8,8,1)=0.01;
P1(9,9,1)=(2*pi/(60*180))^2;
P1(10,10,1)=(0.1*pi/(180*3600))^2;
P1(11,11,1)=(0.1*pi/(180*3600))^2;
P1(12,12,1)=(0.1*pi/(180*3600))^2;
P1(13,13,1)=0.01;
P(14,14,1)=0.125^2;
P1(15,15,1)=0.001^2;
P1(16,16,1)=((1e-4)*g)^2;
P1(17,17,1)=((1e-4)*g)^2;

CP1(:,:,1)=P1(:,:,1);

for j=1:500
    
    for i=2:127
        
        PP1(:,:,i)=a1*P1(:,:,i-1)*a1'+Q1;
        K1(:,:,i)=PP1(:,:,i)*c1'*inv(c1*PP1(:,:,i)*c1'+RR1);
        realX1(:,i)=a1*realX1(:,i-1)+w1;
        Z1(:,i)=c1*realX1(:,i)+v1;
        estX1(:,i)=a1*estX1(:,i-1)+K1(:,:,i)*(Z1(:,i)-c1*a1*estX1(:,i-1));
        P1(:,:,i)=PP1(:,:,i)-K1(:,:,i)*c1*PP1(:,:,i);
        
    end
    
    P1(:,:,1)=P1(:,:,127);
    realX1(:,1)=realX1(:,127);
    estX1(:,1)=estX1(:,127);
    estXX1(:,j+1)=estX1(:,127);
    CP1(:,:,j+1)=P1(:,:,127);
    
end

for i=1:501
    
    est11(i)=estXX1(1,i)*180*60/pi;
    est12(i)=estXX1(2,i)*180*60/pi;
    est13(i)=estXX1(3,i)*180*60/pi;
    est14(i)=estXX1(4,i)*180*60/pi;
    est15(i)=estXX1(5,i)*180*60/pi;
    est16(i)=estXX1(6,i)*180*60/pi;
    est17(i)=estXX1(7,i);
    est18(i)=estXX1(8,i);
    est19(i)=estXX1(9,i)*180*60/pi;
    est110(i)=estXX1(10,i)*180*3600/pi;
    est111(i)=estXX1(11,i)*180*3600/pi;
    est112(i)=estXX1(12,i)*180*3600/pi;
    est113(i)=estXX1(13,i);
    est114(i)=estXX1(14,i);
    est115(i)=estXX1(15,i);
    est116(i)=estXX1(16,i)/(1e-6*g);
    est117(i)=estXX1(17,i)/(1e-6*g);
    
    PPP11(i)=CP1(1,1,i)*(180*60/pi)^2;
    PPP12(i)=CP1(2,2,i)*(180*60/pi)^2;
    PPP13(i)=CP1(3,3,i)*(180*60/pi)^2;
    PPP14(i)=CP1(4,4,i)*(180*60/pi)^2;
    PPP15(i)=CP1(5,5,i)*(180*60/pi)^2;
    PPP16(i)=CP1(6,6,i)*(180*60/pi)^2;
    PPP17(i)=CP1(7,7,i);
    PPP18(i)=CP1(8,8,i);
    PPP19(i)=CP1(9,9,i)*(180*60/pi)^2;
    PPP110(i)=CP1(10,10,i)*(180*3600/pi)^2;
    PPP111(i)=CP1(11,11,i)*(180*3600/pi)^2;
    PPP112(i)=CP1(12,12,i)*(180*3600/pi)^2;
    PPP113(i)=CP1(13,13,i);
    PPP114(i)=CP1(14,14,i);
    PPP115(i)=CP1(15,15,i);
    PPP116(i)=CP1(16,16,i)/(1e-6*g)^2;
    PPP117(i)=CP1(17,17,i)/(1e-6*g)^2;
    
end

%画出状态变量的估计值的曲线图

t=0:252/3600:35;

figure(2)

subplot(3,1,1)
plot(t,est11,'b');
xlabel('time/h');
grid on;

subplot(3,1,2)
plot(t,est12,'b');
xlabel('time/h');
grid on;

subplot(3,1,3)
plot(t,est13,'b');
xlabel('time/h');
grid on;

figure(3)

subplot(3,1,1)
plot(t,est14,'b');
xlabel('time/h');
grid on;

subplot(3,1,2)
plot(t,est15,'b');
xlabel('time/h');
grid on;

subplot(3,1,3)
plot(t,est16,'b');
xlabel('time/h');
grid on;

figure(4)
subplot(3,1,1)
plot(t,est17,'b');
xlabel('time/h');
grid on;

subplot(3,1,2)
plot(t,est18,'b');
xlabel('time/h');
grid on;

subplot(3,1,3)
plot(t,est19,'b');
xlabel('time/h');
grid on;

figure(5)

subplot(3,1,1)
plot(t,est110,'b');
xlabel('time/h');
grid on;

subplot(3,1,2)
plot(t,est112,'b');
xlabel('time/h');
grid on;

subplot(3,1,3)
plot(t,est112,'b');
xlabel('time/h');
grid on;

figure(6)
subplot(3,1,1)
plot(t,est113,'b');
xlabel('time/h');
grid on;

subplot(3,1,2)
plot(t,est114,'b');
xlabel('time/h');
grid on;

subplot(3,1,3)
plot(t,est115,'b');
xlabel('time/h');

⌨️ 快捷键说明

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