Kalman Filter with log(x) as a state variable

6 vues (au cours des 30 derniers jours)
Etienne Vaccaro-Grange
Etienne Vaccaro-Grange le 6 Sep 2023
Modifié(e) : Rahul le 23 Juil 2025
I'm trying to estimate an (extended) Kalman Filter where one of the state variables (say x_{3}) would be modeled as log(x_{3}). In my model, I need x_{3} to remain positive and one trick commonly used is to model log(x3) instead of x3.
Here is the code for a plain extended Kalman Filter:
% Loop over time
for t = 1:T
% Predict state vector
Xt_1(:, t) = muP + thetaP * Xt(:, t);
% MSE matrix state equation
Pt_1(:, :, t) = thetaP * Pt(:, :, t) * thetaP' + Sigmae;
% Measurement equation
y_hat = A + B' * Xt_1(:, t);
% fitting errors
errors = yields(t, :) - y_hat';
% estimate Jacobian
H = compute_jacobian(Xt_1, t);
% compute F
F = H * Pt_1(:, :, t) * H' + Sigmaz;
% Kalman gain
K = Pt_1(:, :, t) * B / F;
% state vector
Xt(:, t + 1) = Xt_1(:, t) + K * errors;
% MSE matrix state equation
Pt(:, :, t + 1) = (eye(3) - K * B') * Pt_1(:, :, t);
end
Basically I don't know what to modify, outside modifying the Jacobian and providing a log(x_{3}) initial value, if I want to model Xt=(x_{1},x_{2},log(x_{3})) instead of Xt=(x_{1},x_{2},x_{3}).
Do I need to amend the state equation at the predict and update stages?
Any idea? 🙏

Réponses (1)

Rahul
Rahul le 23 Juil 2025
Modifié(e) : Rahul le 23 Juil 2025
Hi Etienne,
I understand that you are trying to implement an Extended Kalman Filter in MATLAB, where you are facing an issue while enforcing the positivity of the third state variable by modeling it as 'log(x₃)' instead of 'x₃' directly.
To accommodate this transformation, there are a few modifications that can be implemented in the state transition and measurement update stages, as follows:
  • State Vector Definition: The state vector 'Xt' could be defined as 'Xt = [x₁; x₂; log(x₃)]', and its initialization should reflect the log-transformed value of 'x₃'. So, if you have an initial guess for 'x₃', say 'x3_0', then initialize with 'Xt(3, 1) = log(x3_0)';.
  • Prediction Step Adjustments:When computing the predicted state, it is important to ensure that 'x₃' is recovered from its log representation wherever needed. For instance, if the transition matrix 'thetaP' is written in terms of the original state 'x₃', it will need to be adjusted to operate on 'log(x₃)' instead. Similarly, if 'x₃' affects the dynamics non-linearly, a transformation would need to applied in the state function used for prediction i.e., if a dynamic equation expects 'x₃', you can compute it as shown below:
x3 = exp(Xt(3, t));
  • Jacobian Computation: Since you are already computing the Jacobian using a custom function 'compute_jacobian', you’ll need to reflect the transformation here as well. Specifically, derivatives with respect to 'log(x₃)' will differ from those with respect to 'x₃', so chain rule adjustments will be necessary as shown below:
d(log(x)) = d/dx* dx/d(log(x)) = d/dx* x
  • Update Step (Measurement Equation): When evaluating the measurement model 'y_hat', the state variable 'x₃' can be exponentiated in case it is involved in the process, as shown below:
x3 = exp(Xt_1(3, t));
y_hat = A + B' * [Xt_1(1:2, t); x3];
Similarly, in the Kalman gain and state update computation, any operations involving 'x₃' can be applied correctly in its transformed form.
By consistently maintaining 'log(x₃)' as the state and applying the exponential transformation where the model expects 'x₃', this approach should ensure positivity while maintaining EKF correctness.
For more examples regarding the usage of Kalman FIlters in MATLAB, you can refer to the following documentation link:

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by