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

📄 ex3-5_chemical.m

📁 《Optimal State Estimation - Kalman, H Infinity, and Nonlinear Approaches》 一书的配套源码
💻 M
字号:
function Chemical

% Optimal State Estimation, by Dan Simon

N = 51;
x = [10; 5];
xhat = [8; 7];
P = eye(2);
R = 0.01;

xhatArr = xhat;
PArr(:,:,1) = P;
for k = 1 : N-1
   H = [1 0.99^(k-1)];
   y = H * x + sqrt(R) * randn;
   K = P * H' * inv(H * P * H' + R);
   xhat = xhat + K * (y - H * xhat);
   P = P - K * H * P;
   % Save data in arrays.
   xhatArr = [xhatArr xhat];
   PArr(:,:,k+1) = P;
end

% Plot the results.
close all; % close all figures
figure; % open a new figure
set(gcf,'Color','White');
k = 0 : N-1;
subplot(2,1,1); hold on;
plot(k, xhatArr(1,:), 'r-', 'LineWidth', 2);
plot(k, xhatArr(2,:), 'b:', 'LineWidth', 2);
set(gca,'FontSize',12);
ylabel('estimates');
legend('x_1', 'x_2');

subplot(2,1,2); hold on;
plot(k, squeeze(PArr(1,1,:)), 'r-', 'LineWidth', 2);
plot(k, squeeze(PArr(2,2,:)), 'b:', 'LineWidth', 2);
set(gca,'FontSize',12);
ylabel('variances');
legend('P(1,1)', 'P(2,2');
xlabel('time step');

⌨️ 快捷键说明

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