You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何Kalman滤波器在非零输入下失效?MATLAB实现求助

卡尔曼滤波器非零输入下估计状态偏离问题

我实现了一个简易卡尔曼滤波器,当输入为零时,从绘图结果可见估计状态相比带噪声测量值更接近真实状态:
卡尔曼滤波器零输入下有效

但使用正弦输入向量运行同一脚本时,估计状态完全偏离真实状态:
卡尔曼滤波器非零输入下失效

我已经核对方程并查阅示例脚本,仍毫无头绪,请问有人知道原因吗?

以下是我的代码:

clear all;

clf;
close all;

Phi = [0.5,1.0;-0.5,0.5];
Psi = eye(2);%zeros(2,2);
Gamma = eye(2);
H = eye(2);

dt = 0.01;
t = 0:dt:5;
f = 0.2;
%u = [sin(2*pi*f*t); cos(2*pi*f*t)];
u = zeros(2,length(t)); %Works if input is 0s

%Initial values
x0 = [0; 0];
P0 = eye(2);

%process noise
Q = [0.01 0; 0 0.02];
w = sqrtm(Q)*randn(2,length(t));
%sensor noise
R = [0.2 0; 0 0.2];
v = sqrtm(R)*randn(2,length(t)); %We use randn since it generates 0-mean normally distributed values

%Initialise true state and measured output vectors
x_true = lsim(ss(Phi,Psi,eye(2),zeros(2,2)),u,t,x0)' + w;
z_measured =  zeros(2,length(t));

x_estimates = zeros(2,length(t));

%Kalman filter loop
x_estimate = x0;
P_estimate = P0;

for i = 1:length(t)
   z_measured(:,i) = H*x_true(:,i) + v(:,i);

   x_predict = Phi*x_estimate + Psi*u(:,i);
   P_predict = Phi*P_estimate*Phi' + Gamma*Q*Gamma';

   K = P_predict*H'/(H*P_predict*H'+R);

   x_estimate = x_predict + K*(z_measured(:,i) - H*x_predict); 
   P_estimate = (eye(2) - K*H)*P_predict;

   x_estimates(:,i) = x_estimate;
end


% Plot the results
subplot(2,1,1)
plot(t, x_true(1,:), 'g', 'DisplayName', 'True State 1');
hold on;
plot(t, z_measured(1,:), 'r', 'DisplayName', 'Noisy Measurements 1');
plot(t, x_estimates(1,:), 'b', 'DisplayName', 'Estimated State 1');
xlabel('Time');
ylabel('State 1');
title('Kalman Filter Estimation State 1');
legend;


subplot(2,1,2)
plot(t, x_true(2,:), 'g', 'DisplayName', 'True State 2');
hold on;
plot(t, z_measured(2,:), 'r', 'DisplayName', 'Noisy Measurements 2');
plot(t, x_estimates(2,:), 'b', 'DisplayName', 'Estimated State 2');
xlabel('Time');
ylabel('State 2');
title('Kalman Filter Estimation State 2');
legend;

内容的提问来源于stack exchange,提问作者DuffRumkins

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 23:00:06