pub struct KalmanFilter { /* private fields */ }Expand description
A discrete linear Kalman filter for tracking state estimates through noisy measurements.
The state evolves as: x(k) = F * x(k-1) + B * u(k) + w(k), w ~ N(0, Q) Measurements are: z(k) = H * x(k) + v(k), v ~ N(0, R)
Implementations§
Source§impl KalmanFilter
impl KalmanFilter
Sourcepub fn new(state_dim: usize, measure_dim: usize) -> Self
pub fn new(state_dim: usize, measure_dim: usize) -> Self
Creates a new Kalman filter with the given state and measurement dimensions.
All matrices are initialized to sensible defaults:
F= identityH= identity (top-left sub-block) or zero-paddedQ,R= small diagonal noisex= zero vectorP= identity (high initial uncertainty)
Sourcepub fn set_transition(&mut self, f: Vec<Vec<f64>>) -> Result<()>
pub fn set_transition(&mut self, f: Vec<Vec<f64>>) -> Result<()>
Sets the state transition matrix F.
Sourcepub fn set_measurement(&mut self, h: Vec<Vec<f64>>) -> Result<()>
pub fn set_measurement(&mut self, h: Vec<Vec<f64>>) -> Result<()>
Sets the measurement matrix H.
Sourcepub fn set_process_noise(&mut self, q: Vec<Vec<f64>>) -> Result<()>
pub fn set_process_noise(&mut self, q: Vec<Vec<f64>>) -> Result<()>
Sets the process noise covariance Q.
Sourcepub fn set_measurement_noise(&mut self, r: Vec<Vec<f64>>) -> Result<()>
pub fn set_measurement_noise(&mut self, r: Vec<Vec<f64>>) -> Result<()>
Sets the measurement noise covariance R.
Sourcepub fn update(&mut self, z: &[f64]) -> Result<()>
pub fn update(&mut self, z: &[f64]) -> Result<()>
Update step incorporating a measurement z.
Computes:
- y = z - H * x̂ (innovation)
- S = H * P * H^T + R (innovation covariance)
- K = P * H^T * S^{-1} (Kalman gain)
- x̂ = x̂ + K * y (updated state)
- P = (I - K * H) * P (updated covariance)
Sourcepub fn covariance_flat(&self) -> Vec<f64>
pub fn covariance_flat(&self) -> Vec<f64>
Returns the current error covariance matrix (flattened row-major).
Sourcepub fn covariance(&self) -> &[Vec<f64>]
pub fn covariance(&self) -> &[Vec<f64>]
Returns a reference to the covariance matrix.
Auto Trait Implementations§
impl Freeze for KalmanFilter
impl RefUnwindSafe for KalmanFilter
impl Send for KalmanFilter
impl Sync for KalmanFilter
impl Unpin for KalmanFilter
impl UnsafeUnpin for KalmanFilter
impl UnwindSafe for KalmanFilter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more