LQG Analysis
The LQG analysis is used to design optimal controllers that minimize a quadratic cost function while accounting for process and measurement noise. The analysis combines optimal state feedback (LQR) with optimal state estimation (steady-state Kalman filter) using the separation principle, providing a systematic approach to controller design under uncertainty.
LQG Theory and Matrix Interpretation
Cost Function
The LQG controller minimizes the infinite-horizon quadratic cost:
Noise Model
The system is subject to process and measurement noise:
where w₁ ~ N(0, R₁)
is process noise and w₂ ~ N(0, R₂)
is measurement noise. In this implementation,
Matrix Meanings
Q₁ (controlled output penalty): Higher values → tighter tracking of controlled outputs, more aggressive control
Q₂ (control input penalty): Higher values → smoother control signals, reduced actuator effort
R₁ (disturbance noise): Models uncertainty in disturbance inputs (
w=u
), affects Kalman filter designR₂ (measurement noise): Models sensor uncertainty, affects how much the estimator trusts measurements
Separation Principle
The optimal LQG controller separates into:
LQR design: Compute optimal state feedback gain L assuming perfect state knowledge
Kalman filter: Compute optimal state estimator gain K assuming the control law is given
Combine: Use u = -L*x̂ where x̂ is the Kalman filter estimate
Example Definition
The following example demonstrates LQG controller design for a DC motor system with load control:
analysis LQGControllerAnalysis
extends DyadControlSystems.LQGAnalysis(
measurement = ["y"],
controlled_output = ["y"],
control_input = ["u"],
loop_openings = ["r"],
q1_diag = [1000.0],
q2_diag = [1.0],
r1_diag = [1.0],
r2_diag = [0.1],
duration = 1.0
)
model = DyadExampleComponents.TestDCMotorLoadControlled()
end
using DyadExampleComponents, DyadInterface
solution = LQGControllerAnalysis()
┌ Warning: Initialization system is overdetermined. 2 equations for 0 unknowns. Initialization will default to using least squares. `SCCNonlinearProblem` can only be used for initialization of fully determined systems and hence will not be used here. To suppress this warning pass warn_initialize_determined = false. To make this warning into an error, pass fully_determined = true
└ @ ModelingToolkit ~/.julia/packages/ModelingToolkit/Z9mEq/src/systems/diffeqs/abstractodesystem.jl:1522
using Plots
fig_step = artifacts(solution, :StepResponse)
fig_gang = artifacts(solution, :GangOfFour)
fig_bode = artifacts(solution, :BodePlot)
fig_pz = artifacts(solution, :PZMaps)
We can examine the optimal controller and observer gains:
L = artifacts(solution, :ControllerGain)
K = artifacts(solution, :ObserverGain)
L, K
(2×1 DataFrame
Row │ u1
│ Float64
─────┼──────────
1 │ 31.0731
2 │ 2.19099, 1×2 DataFrame
Row │ x1 x2
│ Float64 Float64
─────┼──────────────────
1 │ 94.2549 179.565)
Analysis Arguments
The following arguments define an LQG analysis:
Required Arguments
model
: The system model to be controlled.measurement::Vector{String}
: Names of measured outputs () available for state estimation. controlled_output::Vector{String}
: Names of controlled outputs () used for performance evaluation. control_input::Vector{String}
: Names of control inputs () that affect the plant.
Penalty Matrix Parameters
q1_diag::Vector{Real}
: Diagonal elements of Q₁ matrix penalizing controlled outputs (). Length must match number of controlled outputs. q2_diag::Vector{Real}
: Diagonal elements of Q₂ matrix penalizing control inputs (). Length must match number of control inputs. r1_diag::Vector{Real}
: Diagonal elements of R₁ matrix representing disturbance noise covariance (). Length must match number of control inputs. r2_diag::Vector{Real}
: Diagonal elements of R₂ matrix representing measurement noise covariance (). Length must match number of measured outputs.
Advanced Parameters
qQ::Real = 0.0
: Loop-transfer recovery parameter for output direction. Higher values recover more robustness in the output direction.qR::Real = 0.0
: Loop-transfer recovery parameter for observer dynamics. Higher values make the observer more aggressive.
System Parameters
loop_openings::Vector{String} = []
: Names of loop openings to break feedback loops during linearization.t::Real = 0.0
: The time at which to perform the linearization of the system.
Discretization Parameters
disc::String = "cont"
: Discretization method. Use "cont" for continuous-time, or "zoh", "tustin", "foh" for discrete-time.Ts::Real = -1.0
: Sampling time for discretization. Required whendisc != "cont"
. Set to -1 for automatic selection.
Integral Action Parameters
integrator_indices::Vector{Int} = []
: Indices of control inputs (matchingcontrol_input
) that are augmented with integrating disturbance models for integral action.integrator_r1_diag::Vector{Real} = []
: Diagonal elements of R₁ matrix for integrator disturbance inputs. Length must matchintegrator_indices
.
Analysis Parameters
wl::Real = -1
: The lower frequency bound for analysis plots. Set to -1 for automatic selection.wu::Real = -1
: The upper frequency bound for analysis plots. Set to -1 for automatic selection.num_frequencies::Int = 3000
: The number of frequencies to be used in frequency-domain analysis.duration::Real = -1.0
: The duration of the step-response analysis. Set to -1 for automatic selection.
LQG Algorithm
The controller design follows this systematic approach:
Linearization: The plant is linearized at the specified operating point with loop openings
Plant Augmentation: If
integrator_indices
is specified, the plant is augmented with integrating disturbances usingadd_low_frequency_disturbance
to provide integral actionOutput Partitioning: Measured outputs (
) and controlled outputs ( ) are separated using explicit vector specification ExtendedStateSpace Creation: The system is converted to the
format required for robust control design Matrix Construction: Penalty matrices
and noise covariance matrices are built from diagonal specifications LQG Problem Formulation: The optimization problem is set up with optional loop-transfer recovery parameters
Optimal Gains Computation: State feedback gain
and Kalman filter gain are computed optimally Controller Synthesis: Multiple controller forms are generated (
observer_controller
,ff_controller
,extended_controller
)Discretization: If discrete-time control is specified, the system is discretized before the design, resulting in a discrete-time controller
Design Considerations
Penalty Matrix Tuning
Q₁ Matrix (Controlled Output Penalty):
Higher values: Tighter tracking, more aggressive control
Lower values: More relaxed performance, smoother control
Relative weighting: Balance between different controlled outputs
Q₂ Matrix (Control Input Penalty):
Higher values: Reduced actuator effort, smoother signals
Lower values: More aggressive control, faster response
Physical limits: Consider actuator saturation constraints
R₁ Matrix (Disturbance Noise):
Higher values: Less trust in model, more conservative estimation
Lower values: More trust in model, more aggressive estimation
Reality matching: Should reflect actual disturbance input uncertainties
R₂ Matrix (Measurement Noise):
Higher values: Less trust in sensors, rely more on model prediction
Lower values: More trust in sensors, aggressive state correction
Sensor characteristics: Should match actual sensor noise levels
Loop-Transfer Recovery
qQ Parameter (Output Direction):
qQ = 0
: Standard LQG designqQ > 0
: Recovers robustness in the output directionHigher values: More robust but may sacrifice performance
qR Parameter (Observer Dynamics):
qR = 0
: Standard Kalman filterqR > 0
: Makes observer more aggressiveHigher values: Faster state estimation but more noise sensitivity
Tutorial Video
Artifacts
An LQGAnalysis returns the following artifacts:
Standard Plots
:StepResponse
: Step response showing reference tracking, disturbance rejection, and control input response.:GangOfFour
: Gang of four transfer functions (S, PS, CS, T) showing closed-loop sensitivity properties.:BodePlot
: Bode plot of the open-loop transfer function showing gain and phase characteristics.:MarginPlot
: Gain and phase margins indicating stability robustness.:PZMaps
: Pole-zero maps of the open-loop and closed-loop systems.
Tables
:ControllerGain
: DataFrame of the optimal state feedback gain matrix L.:ObserverGain
: DataFrame of the optimal Kalman filter gain matrix K.
Notes
- The system must be controllable and observable for LQG design to work. Use
loop_opneings
to disconnect parts of the model that are not controllable or observable given the specified inputs and outputs.