資源簡介
卡爾曼濾波器 matlab程序 ,起到了平滑濾波的作用

代碼片段和文件信息
clear
clc;
N=300;
CON?=?25;%房間溫度,假定溫度是恒定的
%%%%%%%%%%%%%%%kalman?filter%%%%%%%%%%%%%%%%%%%%%%
x?=?zeros(1N);
y?=?2^0.5?*?randn(1N)?+?CON;%加過程噪聲的狀態(tài)輸出
x(1)?=?1;
p?=?10;
Q?=?cov(randn(1N));%過程噪聲協(xié)方差
R?=?cov(randn(1N));%觀測噪聲協(xié)方差
for?k?=?2?:?N
????x(k)?=?x(k?-?1);%預(yù)估計k時刻狀態(tài)變量的值
????p?=?p?+?Q;%對應(yīng)于預(yù)估值的協(xié)方差
????kg?=?p?/?(p?+?R);%kalman?gain
????x(k)?=?x(k)?+?kg?*?(y(k)?-?x(k));
????p?=?(1?-?kg)?*?p;
end
%%%%%%%%%%%Smoothness?Filter%%%%%%%%%%%%%%%%%%%%%%%%
Filter_Wid?=?10;
smooth_res?=?zeros(1N);
for?i?=?Filter_Wid?+?1?:?N
????tempsum?=?0;
????for?j?=?i?-?Filter_Wid?:?i?-?1
????????tempsum?=?tempsum?+?y(j);
????end
????smooth_res(i)?=?tempsum?/?Filter_Wid;
end
%?figure(1);
%?hist(y);
t=1:N;
figure(1);
expValue?=?zeros(1N);
for?i?=?1:?N
???expValue(i)?=?CON;
end
plot(texpValue‘r‘tx‘g‘ty‘b‘tsmooth_res‘k‘);
legend(‘expected‘‘estimate‘‘measure‘‘smooth?result‘);
axis([0?N?20?30])
xlabel(‘Sample?time‘);
ylabel(‘Room?Temperature‘);
title(‘Smooth?filter?VS?kalman?filter‘);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1098??2010-03-17?21:30??Kalman.m
-----------?---------??----------?-----??----
?????????????????1098????????????????????1
評論
共有 條評論