Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kalman Filter Design and State Estimation

Continues from → Project 11: LQR Optimal Control

Modern Control | State Estimation | Predict–Correct Recursion | Q/R Sensitivity Studies | MATLAB | Aerospace Engineering

This repository contains my twelfth independent control systems project — the first in the series that drops the assumption every prior controller relied on: full access to the state vector. Projects 10 (Pole Placement) and 11 (LQR) both required x(t) itself for feedback. Project 12 asks whether that state can instead be reconstructed from a single noisy sensor.


Engineering Question

"If only one noisy, mixed-state output is available, can a Kalman filter reconstruct the complete internal state vector — including a state that never appears in the measurement equation at all?"

Answer: Yes. With a baseline configuration matched to the simulated sensor noise (Q = 10⁻³I, R = 0.0025), the aircraft estimator reconstructed all three states with RMSE values of 0.003678, 0.000449, and 0.000616 — over an order of magnitude below the raw measurement RMSE of 0.051019 — including x₃, which is absent from the output equation entirely.


Overview

Projects 10 and 11 proved that state feedback could dominate classical compensation — but both assumed x(t) was directly measurable. In a real aerospace system that assumption fails: sensors are noisy and typically measure only a linear combination of states. Project 12 closes that gap:

  1. Build the estimator on a known plant — mass-spring-damper, with velocity deliberately withheld from measurement
  2. Validate two independent implementations — a manual discrete predict-correct loop vs. MATLAB's kalman() command
  3. Quantify the Q/R trade-off — sweep process-noise and measurement-noise covariance independently, score with RMSE
  4. Extend to the aircraft pitch plant — reconstruct all three states from one noisy, mixed-state output
  5. Explain a counter-intuitive result — the directly-measured state is not the best-estimated state
  6. Lock in a physically justified baseline — matched to actual simulated sensor noise, not cherry-picked for lowest error

Stage 1 — Mass-Spring-Damper Validation Platform

A = [0  1;  -1  -1],  B = [0; 1],  C = [1  0],  D = 0

Only position (x₁) is measured; velocity (x₂) is withheld entirely so the filter must reconstruct a genuinely hidden state.

Check Result
Manual predict-correct loop vs. MATLAB kalman() ✅ Visually consistent estimates
Hidden velocity reconstruction ✅ Tracks true velocity throughout, including the peak near t ≈ 1.3 s

Stage 2 — Kalman Filter Theory

Predict (time update):

x̂(k|k-1) = Ad·x̂(k-1|k-1) + Bd·u(k-1)
P(k|k-1)  = Ad·P(k-1|k-1)·Adᵀ + Q

Correct (measurement update):

K(k)      = P(k|k-1)·Cᵀ·(C·P(k|k-1)·Cᵀ + R)⁻¹
x̂(k|k)    = x̂(k|k-1) + K(k)·(y(k) − C·x̂(k|k-1))

Q represents trust in the model; R represents trust in the sensor. MATLAB's kalman() solves the equivalent continuous algebraic Riccati equation for a fixed steady-state gain, and was benchmarked directly against the manual recursion.


Stage 3 — Q/R Sensitivity (Mass-Spring-Damper)

Sweep Trend
Q ↑ (distrust model) Estimate tracks noisy sensor more closely — jitterier
Q ↓ (trust model) Estimate smoother, more model-driven
R ↑ (distrust sensor) Estimate smooths toward the model
R ↓ (trust sensor) Estimate tracks raw measurement, error near zero

RMSE, representative configurations (R = 0.01 fixed, matched to σ = 0.1):

Case Q Position RMSE (t > 5s) Improvement over raw sensor
Low Q (trust model) 10⁻⁶ 0.0000012 m 100.00%
Honest (Q matches noise) 10⁻³ 0.001076 m 99.03%
High Q (trust sensor) 1 0.022622 m 77.89%

Raw measurement RMSE = 0.099841 m. Every configuration — even a poorly tuned one — dominates unfiltered sensor data. The near-perfect low-Q result was flagged as an artifact of the filter's internal model being identical to the true plant; on real hardware, driving Q toward zero would instead bias the estimate toward an imperfect model. The "honest" configuration (Q matched to actual simulated noise) was carried forward as the defensible choice.


Stage 4 — Aircraft Pitch State Estimation

A = [0  1  0;  0  0  1;  -0.179  -0.987  -1.935]
B = [0; 0; 1]
C = [1.282  -1.282  0]

The core challenge: the single output is y = 1.282x₁ − 1.282x₂ — a mix of two states. The third, x₃, appears in neither the output nor any indirect combination.

Parameter Value
Sensor noise σ 0.05 → R = 0.0025
Baseline process noise Q = 10⁻³I
Simulation window 30 s
State Full RMSE Steady-State RMSE (t > 5s)
x₁ 0.003678 0.003810
x₂ 0.000449 0.000474
x₃ 0.000616 0.000631

Raw measurement RMSE = 0.051019. All three states are reconstructed at least an order of magnitude more accurately than the raw sensor — including x₃, never present in the measurement equation, evidence the system is fully observable from this single channel.


Stage 5 — Sensitivity Sweeps (Aircraft)

Effect of Q (R = 0.0025 fixed):

Q x₁ RMSE x₂ RMSE x₃ RMSE
10⁻⁵ 0.000541 0.000108 0.000029
10⁻⁴ 0.001768 0.000267 0.000166
10⁻³ 0.003678 0.000449 0.000616
10⁻² 0.006707 0.001113 0.001592

Effect of R (Q = 10⁻³I fixed):

R x₁ RMSE x₂ RMSE x₃ RMSE
10⁻⁴ 0.008506 0.001585 0.002196
10⁻³ 0.004690 0.000632 0.000925
2.5×10⁻³ 0.003678 0.000449 0.000616
10⁻² 0.002434 0.000317 0.000295
10⁻¹ 0.000950 0.000175 0.000060

Both sweeps mirror each other, as expected: increasing Q or decreasing R shifts the estimator toward the raw sensor; decreasing Q or increasing R shifts it toward the model.


Stage 6 — The Counter-Intuitive Result

x₁ produced the largest absolute RMSE at every single tested value of both Q and R — despite being part of the direct measurement, while x₃ (absent from the measurement entirely) consistently did better.

Why: the plant's structure is a chain, ẋ₁ = x₂, ẋ₂ = x₃. As the most-integrated state, x₁ accumulates tracking error propagating up from x₂ and x₃ over the simulation window — outweighing the benefit of appearing directly in the output. Estimation accuracy is governed by how information propagates through the state-space chain, not simply by which state the sensor happens to see.

A secondary finding: the x₂/x₃ ranking wasn't fixed — it flipped between low-R and high-R regimes, showing no single Q or R is uniformly optimal across every state.


Stage 7 — Final Configuration

Selected: Q = 10⁻³I, R = 0.0025 (σ = 0.05) — matched to the actual simulated sensor noise, not the experimental extreme with the lowest RMSE. A filter tuned to noise statistics it doesn't actually face is not a defensible design choice for hardware.

Quantity Value
Process-noise covariance, Q 10⁻³ × I₃
Measurement-noise covariance, R 0.0025 (σ = 0.05)
x₁ RMSE 0.003678
x₂ RMSE 0.000449
x₃ RMSE 0.000616
Raw measurement RMSE 0.051019

Key Engineering Conclusions

1. A Kalman filter can reconstruct a complete internal state vector — including states with zero presence in the output equation — from a single noisy measurement channel, provided the underlying system is observable.

2. Q and R form the same kind of tunable trade-off surface as LQR's Q/R, but for information trust rather than control effort: model confidence vs. sensor confidence, with mirrored, predictable effects on estimation smoothness and accuracy.

3. Estimation accuracy is not determined by whether a state appears directly in the measurement equation — it's determined by how information propagates through the plant's dynamics. x₁ was the worst-estimated state precisely because it sits at the end of the integration chain, despite being the one state the sensor "sees" directly.

4. A near-zero-error result under aggressive tuning is not automatically the best design choice — the honest configuration, matched to actual (assumed) sensor characteristics, is the physically defensible one, even when a more extreme setting scores lower on paper.

5. State estimation is the missing piece connecting Projects 10–11 to real hardware: pole placement and LQR both assumed x(t) was available; the Kalman filter is what actually supplies it from real sensors.


Aerospace Applications

  • Observer-based flight control: the Kalman-estimated state can feed directly into the pole-placement (Project 10) or LQR (Project 11) controllers already developed, forming a complete estimator-plus-controller loop.
  • Sparse instrumentation: real aircraft, UAVs, and rockets rarely instrument every state directly — this project demonstrates full-state reconstruction from a single mixed-output channel, the exact situation faced by IMU/attitude sensor fusion.
  • Sensor fusion foundations: the Q/R framework developed here generalizes directly to multi-sensor fusion (e.g., gyro + accelerometer + GPS) used in real navigation systems.
  • Teknofest VLR Rocket: this estimator is the direct prerequisite for closing the loop on the rocket's attitude controller with real, noisy onboard sensors rather than idealized full-state feedback.

Project Roadmap

✅ Project 01 — Mass-Spring-Damper Analysis
✅ Project 02 — DC Motor Modeling
✅ Project 03 — PID Speed Control
✅ Project 04 — Aircraft Pitch Control
✅ Project 05 — Root Locus Design
✅ Project 06 — Lead Compensator Investigation
✅ Project 07 — Lead–Lag Compensator Design
✅ Project 08 — Frequency Response Analysis
✅ Project 09 — State-Space Modeling
✅ Project 10 — Pole Placement Control
✅ Project 11 — LQR Optimal Control
✅ Project 12 — Kalman Filter Design & State Estimation

→ Project 13 — UAV Attitude Control
→ Project 14 — Rocket Attitude Control
→ Project 15 — Satellite Attitude Control
→ Project 16 — Missile Guidance and Control
→ Project 17 — Integrated Flight Control System

Software Used

  • MATLAB R2024b
  • Control System Toolbox

Author

Zohaib Imtiaz Aerospace Engineering Student | Teknofest VLR Team — Flight Control


License

This project is released under the MIT License.


Project Cover

Project Cover


Woeking of Kalman Filter

Kalaman.Filter.Working.mp4