Search code examples
javakalman-filter

Kalman filter matrix dimensions mismatch


I have created following dimensional matrices for a Kalman Filter:

  • Matrix X, the state matrix: 4x1, which has: [X; dX; Y; dY]

    • X: x-coordinate
    • dX: rate of changing x-coordinate
    • Y: x-coordinate
    • dY: rate of changing y-coordinate.
  • Matrix H, the observation matrix: 2x4
  • Matrix R, the measurement noise covariance matrix: 2x4.
  • Matrix Z, the measurement matrix: 4x1 since there are 4 measurements for states.

But apparently there is a mismatch of matrix dimensions as apache Kalman filter throws matrix dimension mismatch exception.

I'm slightly confused with creating matrices suitable to a measurement matrix (Z) of 4x1 and state matrix of 4x1.


Solution

  • From the documentation it's either your control vector or your measurement vector, which has an incorrect size.

    There are 2 cases where that exception can be thrown.

    Case predict: DimensionMismatchException - if the dimension of the control vector does not match

    Case correct: DimensionMismatchException - if the dimension of the measurement vector does not fit

    There are few cases, but here it is due to number of rows of matrix R being not equal to number of rows of z.