DLQE
The discrete-time linear quadratic estimator (DLQE) calculates the optimal estimator gain matrix L for discrete-time systems with process and measurement noise.
It minimizes the expected squared error of the state estimate x_e[n] using sensor measurements y[n].
Excel Usage
=DLQE(A, G, C, QN, RN, NN)
A(list[list], required): The discrete state dynamics matrix A (NxN).G(list[list], required): The discrete process noise input matrix G (NxNw).C(list[list], required): The output matrix C (Ny x N).QN(list[list], required): Process noise covariance matrix (Nw x Nw).RN(list[list], required): Sensor noise covariance matrix (Ny x Ny).NN(list[list], optional, default: null): Optional cross-covariance matrix (Nw x Ny).
Returns (list[list]): The discrete Kalman estimator gain matrix L.
Example 1: Discrete LQE design
Inputs:
| A | G | C | QN | RN | ||||
|---|---|---|---|---|---|---|---|---|
| 0.5 | 0 | 1 | 0 | 1 | 1 | 0.1 | 0 | 1 |
| 0 | 0.3 | 0 | 1 | 0 | 0.1 |
Excel formula:
=DLQE({0.5,0;0,0.3}, {1,0;0,1}, {1,1}, {0.1,0;0,0.1}, {1})
Expected output:
| Result |
|---|
| 0.0514686 |
| 0.0260185 |
Example 2: Single-state discrete estimator
Inputs:
| A | G | C | QN | RN |
|---|---|---|---|---|
| 0.6 | 1 | 1 | 0.2 | 0.5 |
Excel formula:
=DLQE({0.6}, {1}, {1}, {0.2}, {0.5})
Expected output:
0.206232
Example 3: Coupled-state measurement model
Inputs:
| A | G | C | QN | RN | ||||
|---|---|---|---|---|---|---|---|---|
| 0.9 | 0.2 | 1 | 0 | 1 | -1 | 0.03 | 0 | 0.4 |
| 0.1 | 0.8 | 0 | 1 | 0 | 0.03 |
Excel formula:
=DLQE({0.9,0.2;0.1,0.8}, {1,0;0,1}, {1,-1}, {0.03,0;0,0.03}, {0.4})
Expected output:
| Result |
|---|
| 0.273274 |
| 0.0608544 |
Example 4: Partially observed discrete estimator
Inputs:
| A | G | C | QN | RN | ||||
|---|---|---|---|---|---|---|---|---|
| 0.7 | 0.1 | 1 | 0 | 1 | 0 | 0.05 | 0 | 0.3 |
| 0 | 0.6 | 0 | 1 | 0 | 0.02 |
Excel formula:
=DLQE({0.7,0.1;0,0.6}, {1,0;0,1}, {1,0}, {0.05,0;0,0.02}, {0.3})
Expected output:
| Result |
|---|
| 0.151352 |
| 0.00438577 |
Python Code
Show Code
import control as ct
import numpy as np
def dlqe(A, G, C, QN, RN, NN=None):
"""
Linear quadratic estimator (Kalman filter) for discrete-time systems.
See: https://python-control.readthedocs.io/en/latest/generated/control.dlqe.html
This example function is provided as-is without any representation of accuracy.
Args:
A (list[list]): The discrete state dynamics matrix A (NxN).
G (list[list]): The discrete process noise input matrix G (NxNw).
C (list[list]): The output matrix C (Ny x N).
QN (list[list]): Process noise covariance matrix (Nw x Nw).
RN (list[list]): Sensor noise covariance matrix (Ny x Ny).
NN (list[list], optional): Optional cross-covariance matrix (Nw x Ny). Default is None.
Returns:
list[list]: The discrete Kalman estimator gain matrix L.
"""
try:
def to_np(x):
if x is None:
return None
if not isinstance(x, list):
return np.array([[float(x)]])
if len(x) > 0 and not isinstance(x[0], list):
x = [x]
return np.array([[float(v) if v is not None and str(v) != "" else 0.0 for v in row] for row in x])
a_np = to_np(A)
g_np = to_np(G)
c_np = to_np(C)
qn_np = to_np(QN)
rn_np = to_np(RN)
nn_np = to_np(NN)
if nn_np is None:
L, P, E = ct.dlqe(a_np, g_np, c_np, qn_np, rn_np)
else:
L, P, E = ct.dlqe(a_np, g_np, c_np, qn_np, rn_np, nn_np)
return L.tolist()
except Exception as e:
return f"Error: {str(e)}"Online Calculator
The discrete state dynamics matrix A (NxN).
The discrete process noise input matrix G (NxNw).
The output matrix C (Ny x N).
Process noise covariance matrix (Nw x Nw).
Sensor noise covariance matrix (Ny x Ny).
Optional cross-covariance matrix (Nw x Ny).