Accelerating the pace of engineering and science

# lqg

Linear-Quadratic-Gaussian (LQG) design

## Syntax

reg = lqg(sys,QXU,QWV)
reg = lqg(sys,QXU,QWV,QI)
reg = lqg(sys,QXU,QWV,QI,'1dof')
reg = lqg(sys,QXU,QWV,QI,'2dof')

## Description

reg = lqg(sys,QXU,QWV) computes an optimal linear-quadratic-Gaussian (LQG) regulator reg given a state-space model sys of the plant and weighting matrices QXU and QWV. The dynamic regulator sys uses the measurements y to generate a control signal u that regulates y around the zero value. Use positive feedback to connect this regulator to the plant output y.

The LQG regulator minimizes the cost function

$J=E\left\{\underset{\tau \to \infty }{\mathrm{lim}}\frac{1}{\tau }{\int }_{0}^{\tau }\left[{x}^{T},{u}^{T}\right]{Q}_{xu}\left[\begin{array}{c}x\\ u\end{array}\right]dt\right\}$

subject to the plant equations

```dx/dt = Ax + Bu + w
y     = Cx + Du + v
```

where the process noise w and measurement noise v are Gaussian white noises with covariance:

```E([w;v] * [w',v']) = QWV
```

reg = lqg(sys,QXU,QWV,QI) uses the setpoint command r and measurements y to generate the control signal u. reg has integral action to ensure that y tracks the command r.

The LQG servo-controller minimizes the cost function

$J=E\left\{\underset{\tau \to \infty }{\mathrm{lim}}\frac{1}{\tau }{\int }_{0}^{\tau }\left(\left[{x}^{T},{u}^{T}\right]{Q}_{xu}\left[\begin{array}{c}x\\ u\end{array}\right]+{x}_{i}^{T}{Q}_{i}{x}_{i}\right)\text{ }dt\right\}$

where xi is the integral of the tracking error r - y. For MIMO systems, r, y, and xi must have the same length.

reg = lqg(sys,QXU,QWV,QI,'1dof') computes a one-degree-of-freedom servo controller that takes e = r - y rather than [r ; y] as input.

reg = lqg(sys,QXU,QWV,QI,'2dof') is equivalent to LQG(sys,QXU,QWV,QI) and produces the two-degree-of-freedom servo-controller shown previously.

## Examples

Linear-Quadratic-Gaussian (LQG) Regulator and Servo Controller Design

This example shows how to design an linear-quadratic-Gaussian (LQG) regulator, a one-degree-of-freedom LQG servo controller, and a two-degree-of-freedom LQG servo controller for the following system.

The plant has three states (x), two control inputs (u), three random inputs (w), one output (y), measurement noise for the output (v), and the following state and measurement equations.

$\begin{array}{l}\frac{dx}{dt}=Ax+Bu+w\\ y=Cx+Du+v\end{array}$

where

$\begin{array}{l}A=\left[\begin{array}{ccc}0& 1& 0\\ 0& 0& 1\\ 1& 0& 0\end{array}\right]\text{ }\text{ }B=\left[\begin{array}{cc}0.3& 1\\ 0& 1\\ -0.3& 0.9\end{array}\right]\\ \\ C=\left[\begin{array}{ccc}1.9& 1.3& 1\end{array}\right]\text{ }D=\left[\begin{array}{cc}0.53& -0.61\end{array}\right]\end{array}$

The system has the following noise covariance data:

$\begin{array}{l}{Q}_{n}=E\left(\omega {\omega }^{T}\right)=\left[\begin{array}{ccc}4& 2& 0\\ 2& 1& 0\\ 0& 0& 1\end{array}\right]\\ {R}_{n}=E\left(v{v}^{T}\right)=0.7\end{array}$

For the regulator, use the following cost function to define the tradeoff between regulation performance and control effort:

$J\left(u\right)={\int }_{0}^{\infty }\left(0.1{x}^{T}x+{u}^{T}\left[\begin{array}{cc}1& 0\\ 0& 2\end{array}\right]u\right)dt$

For the servo controllers, use the following cost function to define the tradeoff between tracker performance and control effort:

$J\left(u\right)={\int }_{0}^{\infty }\left(0.1{x}^{T}x+{x}_{i}^{2}+{u}^{T}\left[\begin{array}{cc}1& 0\\ 0& 2\end{array}\right]u\right)dt$

To design the LQG controllers for this system:

1. Create the state-space system by typing the following in the MATLAB Command Window:

```A = [0 1 0;0 0 1;1 0 0];
B = [0.3 1;0 1;-0.3 0.9];
C = [1.9 1.3 1];
D = [0.53 -0.61];
sys = ss(A,B,C,D);```
2. Define the noise covariance data and the weighting matrices by typing the following commands:

```nx = 3;    %Number of states
ny = 1;    %Number of outputs
Qn = [4 2 0; 2 1 0; 0 0 1];
Rn = 0.7;
R = [1 0;0 2]
QXU = blkdiag(0.1*eye(nx),R);
QWV = blkdiag(Qn,Rn);
QI = eye(ny);```
3. Form the LQG regulator by typing the following command:

`KLQG = lqg(sys,QXU,QWV)`

This command returns the following LQG regulator:

```a =
x1_e    x2_e    x3_e
x1_e  -6.212  -3.814  -4.136
x2_e  -4.038  -3.196  -1.791
x3_e  -1.418  -1.973  -1.766

b =
y1
x1_e   2.365
x2_e   1.432
x3_e  0.7684

c =
x1_e       x2_e       x3_e
u1   -0.02904  0.0008272     0.0303
u2    -0.7147    -0.7115    -0.7132

d =
y1
u1   0
u2   0

Input groups:
Name        Channels
Measurement       1

Output groups:
Name      Channels
Controls      1,2

Continuous-time model.```
4. Form the one-degree-of-freedom LQG servo controller by typing the following command:

`KLQG1 = lqg(sys,QXU,QWV,QI,'1dof')`

This command returns the following LQG servo controller:

```a =
x1_e    x2_e    x3_e     xi1
x1_e  -7.626  -5.068  -4.891  0.9018
x2_e  -5.108  -4.146  -2.362  0.6762
x3_e  -2.121  -2.604  -2.141  0.4088
xi1        0       0       0       0

b =
e1
x1_e   -2.365
x2_e   -1.432
x3_e  -0.7684
xi1         1

c =
x1_e     x2_e     x3_e      xi1
u1  -0.5388  -0.4173  -0.2481   0.5578
u2   -1.492   -1.388   -1.131   0.5869

d =
e1
u1   0
u2   0

Input groups:
Name     Channels
Error       1

Output groups:
Name      Channels
Controls      1,2

Continuous-time model.```
5. Form the two-degree-of-freedom LQG servo controller by typing the following command:

`KLQG2 = lqg(sys,QXU,QWV,QI,'2dof')`

This command returns the following LQG servo controller:

```a =
x1_e    x2_e    x3_e     xi1
x1_e  -7.626  -5.068  -4.891  0.9018
x2_e  -5.108  -4.146  -2.362  0.6762
x3_e  -2.121  -2.604  -2.141  0.4088
xi1        0       0       0       0

b =
r1      y1
x1_e       0   2.365
x2_e       0   1.432
x3_e       0  0.7684
xi1        1      -1

c =
x1_e     x2_e     x3_e      xi1
u1  -0.5388  -0.4173  -0.2481   0.5578
u2   -1.492   -1.388   -1.131   0.5869

d =
r1  y1
u1   0   0
u2   0   0

Input groups:
Name        Channels
Setpoint         1
Measurement       2

Output groups:
Name      Channels
Controls      1,2

Continuous-time model.```

## More About

expand all

### Tips

lqg can be used for both continuous- and discrete-time plants. In discrete-time, lqg uses x[n|n-1] as state estimate (see kalman for details).

To compute the LQG regulator, lqg uses the commands lqr and kalman. To compute the servo-controller, lqg uses the commands lqi and kalman.

When you want more flexibility for designing regulators you can use the lqr, kalman, and lqgreg commands. When you want more flexibility for designing servo controllers, you can use the lqi, kalman, and lqgtrack commands. For more information on using these commands and how to decide when to use them, see Linear-Quadratic-Gaussian (LQG) Design for Regulation and Linear-Quadratic-Gaussian (LQG) Design of Servo Controller with Integral Action.

## See Also

Was this topic helpful?