Skip to content

Commit d9d3a7a

Browse files
authored
Update Kalman3D_Wave.h
1 parent eab0ce8 commit d9d3a7a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

bbn_wave_freq_m5atomS3/Kalman3D_Wave.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,21 +394,34 @@ class EIGEN_ALIGN_MAX Kalman3D_Wave {
394394
const Eigen::Matrix<T,3,1>& r,
395395
const Eigen::Matrix<T,3,3>& R)
396396
{
397+
// Innovation covariance
397398
Eigen::Matrix<T,3,3> S = C * P * C.transpose() + R;
399+
400+
// Factorization (with fallback regularization)
398401
Eigen::LDLT<Eigen::Matrix<T,3,3>> ldlt(S);
402+
bool used_reg = false;
399403
if (ldlt.info() != Eigen::Success) {
400404
Eigen::Matrix<T,3,3> S_reg = S + Eigen::Matrix<T,3,3>::Identity() *
401405
std::max(std::numeric_limits<T>::epsilon(), T(1e-6) * R.norm());
402406
ldlt.compute(S_reg);
403407
if (ldlt.info() != Eigen::Success) return;
408+
S = S_reg; // <- make sure Joseph uses the SAME S that produced K
409+
used_reg = true; (void)used_reg;
404410
}
405411

412+
// Gain
406413
Eigen::Matrix<T,NX,3> K = P * C.transpose() * ldlt.solve(Eigen::Matrix<T,3,3>::Identity());
414+
415+
// State
407416
x.noalias() += K * r;
408417

409-
Eigen::Matrix<T,3,NX> CP = C * P;
410-
Eigen::Matrix<T,NX,NX> KC = K * CP;
411-
P.noalias() = P - KC - KC.transpose() + K * R * K.transpose();
418+
// Rank-3 Joseph covariance update:
419+
// P' = P - KCP - (KCP)ᵀ + K S Kᵀ with K = P Cᵀ S⁻¹
420+
Eigen::Matrix<T,3,NX> CP = C * P; // 3×NX
421+
Eigen::Matrix<T,NX,NX> KC = K * CP; // NX×NX (rank ≤ 3)
422+
P.noalias() = P - KC - KC.transpose() + K * S * K.transpose();
423+
424+
// Symmetrize
412425
P = T(0.5) * (P + P.transpose());
413426
}
414427
};

0 commit comments

Comments
 (0)