为何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
相关产品推荐
相关产品推荐

