function kfStepState
extends Modelica.Icons.Function;
import Modelica;
import Modelica_LinearSystems2;
import Modelica_LinearSystems2.WorkInProgress.DiscreteStateSpace;
input DiscreteStateSpace dss;
input Real P[size(dss.A, 1), size(dss.A, 1)] "State covariance matrix of the previous instant";
input Real Q[size(dss.B, 2), size(dss.B, 2)] "Input or process noise covariance matrix of the previous instant";
input Real R[size(dss.C, 1), size(dss.C, 1)] "Output or measurement noise covariance matrix of the previous instant";
input Real x[size(dss.A, 1)] "Estimated state vector of previous instant";
input Real u[size(dss.B, 2)] "input vector";
input Real y[size(dss.C, 1)] "Measured output vector";
output Real x_new[size(dss.A, 1)];
output Real K[size(dss.A, 1), size(dss.C, 1)] "Kalman filter gain matrix";
output Real P_new[size(dss.A, 1), size(dss.A, 1)] "Updated state covariance matrix";
end kfStepState;