mherb/kalman

how to set initial covariance matrix for system f, and measurement h

QingweiLau opened this issue · 4 comments

Dear mherb,

Thank you for your work and sharing this. I have a question for implementing the ukf, which is, how can I set the initial covariance matrix for system f, and measurement h?

I noticed you declared via this->V/H in the measurement model, then what is V and H? And can I set similarly for the system process in system model?

Best wishes.
Qingwei

mherb commented

Dear @Charvelau,

H/V are the jacobians of the linearized measurement model (used only for linearized filters, e.g. EKF, not UKF), not covariances, see

//! Measurement model jacobian

Your system/measurement model should (transitively) derive from a CovarianceBase, which is typically either "StandardBase" or "SquareRootBase" depending on whether you want to use a regular covariance or a square-root filter (Please have a look at the inheritance hierarchy in the example to understand the principle).
In both cases, you can set the covariance of the system/measurement model at any time using setCovariance()

bool setCovariance(const Covariance<StateType>& covariance)

Dear @mherb, thank you for your reply.

So the W and V are not covariances matrices. Say my regular covariance matrices are Q(m,m) and R(m,n) declared with Eigen, where m and n are numbers of state variables and measurement variables, then I can set them with
SystemModel.setCovariance(Q) and MeasurementModel.setCovariance(R) in my main function, right?

Or I need to declare Q and R to be type of StandardBase? Could you please give me a basic example?

And also, if I need to use UKF for a nonlinear case, then I can ignore H/V/F/W jacobians in the system model and measurement model definition, right?

Thank you very much.

Best regards.
Qingwei

mherb commented

Q and R can be regular Eigen Matrices representing your covariances and can the set using the the way you mention.

For the UKF, your system/measurement models can derive directly from SystemModel/MeasurementModel, you do not need to provide linearizations in the form of jacobians.

Note for UKF: I just discovered that @jwdinius comitted a weight-fix for ukf in his fork, see e553832
You may want to double-check the implementation w.r.t. the formulas derived in papers.

Closing this for now, please feel free to re-open.

Dear @mherb, sure, thank you very much!!!