# Designing an LQG Regulator

As an example of LQG design, consider the following regulation problem.

Figure 1. Schematic of simple closed-loop regulator system.

The goal is to regulate the plant, the simple buck converter we have been using, around zero. The input disturbance `d` is low frequency with a given power spectral density PSD.

There is some measurement noise `n`, with noise intensity given by `E(n2)=0.01`.

Use the cost function

`J(u) = \int_0^\infty (10 y^2 + u^2) dt`

to specify the tradeoff between regulation performance and cost of control. The following equations represent our open-loop state-space model:

    	dx/dt = Fo x + Go u + Go d   (state equations)
    	 y    = Ho x + n             ( measurements)

where

    	Fo = [  9.42e-001  1.90e-001
    	       -1.90e-001  9.50e-001 ];
    	Go = [  4.31e-001
    	        3.03e+000 ];
    	Ho = [  1.00e+000  0.00e+000 ];
    	Ko = [  0.00e+000 ];
    	Ts = 10e-6;

The following commands design the optimal LQG regulator `F(s)` for this problem:

    	sys = ss(Fo,Go,Ho,Ko,Ts) % State-space plant model

    	% Design LQ-optimal gain K
    	K = lqry(sys,10,1)       % u = -Kx minimizes J(u)
    	K =
    		1.1308    0.3317

    	% Separate control input u and disturbance input d
    	P = sys(:,[1 1]);        % input [u;d], output y

    	% Design Kalman state estimator Kest.
    	Kest = kalman(P,1,0.01)

    	a =                    x1_e         x2_e
    		 x1_e      -1.0789         0.19
    		 x2_e      -5.5806         0.95

    	b =                      u1           y1
    		 x1_e        0.431       2.0209
    		 x2_e         3.03       5.3906

    	c =                    x1_e         x2_e
    		 y1_e     0.037999            0
    		 x1_e     0.037999            0
    		 x2_e      -5.8668            1

    	d =                      u1           y1
    		 y1_e            0        0.962
    		 x1_e            0        0.962
    		 x2_e            0       5.8668

    	Sampling time: 1e-005
    	Discrete-time model.

With this information we can construct a Kalman filter and feedback matrix in LTSPICE as shown in Figure 2.

Figure 2. Schematic of simple closed-loop buck converter regulator system.

The results from this simple procedure, Fig. 3, are comparable to what we get with the non-automated procedure we showed before.

Figure 3. Results for closed-loop buck converter regulator system.

The slight overshoot is caused by the fact that we are now not exactly in the steady-state where we computed our system matrices `Fo`, `Go`, `Ho` and `Ko`. If necessary, the response can be tuned by tweaking the coefficients (10 and 1) of `J(u)`.

## Summary

With the Kalman State Observer we can predict the inductor current instead of measuring it. In effect we are exchanging computing power for ADC and signal-conditioning hardware.