?? filter_result.m
字號(hào):
function [XER,YER]=filter_result(Ts,mon,d)
% filter_result 對(duì)觀測(cè)數(shù)據(jù)進(jìn)行卡爾曼濾波,得到預(yù)測(cè)的航跡以及估計(jì)誤差的均值和標(biāo)準(zhǔn)差
% Ts 采樣時(shí)間,即雷達(dá)的工作周期
% mon 進(jìn)行Monte-Carlo仿真的次數(shù)
% d 測(cè)量的誤差,單位m
%返回值包括濾波預(yù)測(cè)后的估計(jì)航跡,以及均值和誤差協(xié)方差
if nargin>3
error('Too many input arguments.');
end
offtime=800;
% 產(chǎn)生理論的航跡
[x,y]=trajectory(Ts,offtime);
Pv=d*d;
N=ceil(offtime/Ts);
randn('state',sum(100*clock)); % 設(shè)置隨機(jī)數(shù)發(fā)生器
for i=1:N
vx(i)=d*randn(1); % 觀測(cè)噪聲,兩者獨(dú)立
vy(i)=d*randn(1);
zx(i)=x(i)+vx(i); % 實(shí)際觀測(cè)值
zy(i)=y(i)+vy(i);
end
% 產(chǎn)生觀測(cè)數(shù)據(jù)
for n=1:mon
% 用卡爾曼濾波得到估計(jì)的航跡
XE=Kalman_filter(Ts,offtime,d,0);
YE=Kalman_filter(Ts,offtime,d,1);
%誤差矩陣
XER(1:N,n)=x(1:N)-(XE(1:N))';
YER(1:N,n)=y(1:N)-(YE(1:N))';
end
%濾波誤差的均值
XERB=mean(XER,2);
YERB=mean(YER,2);
%濾波誤差的標(biāo)準(zhǔn)差
XSTD=std(XER,1,2); % 計(jì)算有偏的估計(jì)值,flag='1'
YSTD=std(YER,1,2);
%作圖
figure
plot(x,y,'r');hold on;
plot(zx,zy,'g');hold on;
plot(XE,YE,'b');hold off;
axis([1500 5000 1000 10000]),grid on;
legend('真實(shí)軌跡','觀測(cè)數(shù)據(jù)','濾波估計(jì)');
figure
subplot(2,2,1)
plot(XERB)
axis([0 500 -50 50])
xlabel('觀測(cè)次數(shù)')
ylabel('X方向?yàn)V波誤差均值'),grid on;
subplot(2,2,2)
plot(YERB)
axis([0 500 -50 50])
xlabel('觀測(cè)次數(shù)')
ylabel('Y方向?yàn)V波誤差均值'),grid on;
subplot(2,2,3)
plot(XSTD)
axis([0 500 0 150])
xlabel('觀測(cè)次數(shù)')
ylabel('X方向?yàn)V波誤差標(biāo)準(zhǔn)值'),grid on;
subplot(2,2,4)
plot(YSTD)
axis([0 500 0 150])
xlabel('觀測(cè)次數(shù)')
ylabel('Y方向?yàn)V波誤差標(biāo)準(zhǔn)值'),grid on;
X=XER;Y=YER;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -