plot(1:N, z, '.'); hold on; plot(1:N, x_hist, '-r'); yline(true_x,'-k'); legend('measurements','estimate','true value');
Before diving into the book, it's helpful to understand the core idea at a high level. The Kalman filter is a that operates in two stages: prediction and update . During the prediction stage, the filter projects the current state estimate forward in time based on the system's dynamics. During the update stage, it incorporates a new measurement to refine the estimate. This cycle continues recursively, honing the estimate with each new measurement.
Estimating the movement of an object (e.g., using sonar) by combining position data with a constant-velocity model. plot(1:N, z, '
% --- Kalman Filter for a Stationary Scalar --- clear all; close all; clc;
% Parameters dt = 0.1; t = 0:dt:10; real_val = 14.4; % The "True" voltage z_noise = randn(size(t)); % Random noise z = real_val + z_noise; % Measured voltage % Initialization x_est = 10; % Initial guess P = 1; % Initial error covariance Q = 0.01; % Process noise covariance R = 1; % Measurement noise covariance for i = 1:length(t) % 1. Prediction (Time Update) x_pred = x_est; P_pred = P + Q; % 2. Kalman Gain K = P_pred / (P_pred + R); % 3. Estimation (Measurement Update) x_est = x_pred + K * (z(i) - x_pred); P = (1 - K) * P_pred; output(i) = x_est; end plot(t, z, 'r.', t, output, 'b-', 'LineWidth', 2); legend('Noisy Measurement', 'Kalman Estimate'); Use code with caution. Key Takeaways for Beginners This is the "trust factor." If your sensor is great ( is small), During the update stage, it incorporates a new
Alternative versions of the book's examples, sometimes modified for GNU Octave, can be found on GitHub (arthurbenemann) PDF Access:
Phil Kim's book, "Kalman Filter for Beginners: with MATLAB Examples", provides a comprehensive introduction to the Kalman filter algorithm, including its mathematical formulation, implementation, and applications. The book covers topics such as: % --- Kalman Filter for a Stationary Scalar
To give you a preview of the MATLAB examples highlighted in Phil Kim's book, here is a simple script demonstrating a 1D Kalman Filter estimating a constant voltage contaminated by severe measurement noise.