Problem with Kalman Filter and state space model

조회 수: 11 (최근 30일)
Tobias Weinmann
Tobias Weinmann 2023년 6월 14일
댓글: Tobias Weinmann 2023년 6월 14일
I'm currently designing a Kalman Filter to filter my noisy active power measurement data, which are dependent of the inputs frequency and voltage. Therefore i tried to recreate the system behaviour using transfer functions and i converted them into a space model with A,B and C using the Parameter Estimator App in SIMULINK. These matrices are used as follwing for my state space model:
A=[-55.6,0.0485;0.4125,-39.3134];
B=[7.3617,-0.0139,-1.5236,4.3344];
C=[7.3780,-11.0682];
If i compare the created state space model data with the measurement data, i get the following plot or results, which looks good:
blue is measurement data, orange is model data;
My Kalman Filter is based on the follwing work: http://bilgin.esme.org/BitsAndBytes/KalmanFilterforDummies
function [y_dachk,K_k,xk_1]=Kalman_Filtering(A,B,C,R,Q,z_k,Input_Voltage,Input_Frequency)
% Initialisation
I = eye(2);
Q_M = I.*Q;
xk_1=[0;0];
P_kmin1=[0.01,0;0,0.01];
for k = 1:length(Input_Voltage)
% Time Update (prediction)
%1. Project the state ahead
x_k = A*xk_1+B*[Input_Voltage(k);Input_Frequency(k)];
%1. prediction state
%P_k=A*P_kmin1*transpose(A)+Q_M;
% Correction Step
%1. Kalman Gain
K_k=P_k*transpose(C)*((C*P_k)*transpose(C)+R)^(-1);
%2. Update states
delta=z_k(k)-C*x_k;
xk_1 = x_k+K_k*delta;
%3. uptade covariance
P_kmin1=(I-K_k*C)*P_k;
y_dachk(k)=C*xk_1;
end
end
The problem i have at the moment is, it doesnt correct the noisy data, instead it recreates the measurement signal if i run the code above:
This means it's two times the same signal. This is the first thing what confuses me.
The second one is the fact, if i set the Kalman Gain K_k to zero, i would expect to always get the predicted state and therefore also the output of my state space model in the first graphic. But this is not the case. I can't plot it, because after a few steps the values of y_dach are NaN. I'm struggling to understand where my laplace integration takes place here, because if i interpret the equations of http://bilgin.esme.org/BitsAndBytes/KalmanFilterforDummies my x_k before the integration is my next xk_1 used by the measurement function. The integration just gets neglected.
I would be happy to get some help or advice on the aspect since i'm struggling to solve the problem. Thanks for your help.

채택된 답변

Paul
Paul 2023년 6월 14일
Hi Tobias,
It looks like the state space model is defined in continuous time, but the Kalman filter is a discrete-time implementation. So you'll have to discretize the plant model based on the sampling period of the measurements and use the A,B,C matrices from the discretized model in the Kalman filter. Also, if the Q and R matrices are continous time spectral densities, you'll have to discretize those as well to get the discrete-time covariance matrices. Presumbably the sampling period is small enough that it captures the dynamics of the plant. I don't have a reference handy, but I'm sure one can easily be found that shows how to formally, and/or approximately, discretize a continuous time model for use with a discrete-time Kalman filter.
  댓글 수: 1
Tobias Weinmann
Tobias Weinmann 2023년 6월 14일
Okay, this makes a lot of things clear. Thanks a lot for your help:) I will try it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by