Lead and lag compensators are used quite extensively in control. A lead compensator can increase the stability or speed of response of a system; a lag compensator can reduce (but not eliminate) the steady state error. Depending on the effect desired, one or more lead and lag compensators may be used in various combinations.

Lead, lag, and lead/lag compensators are usually designed for a system in transfer function form. The conversions page explains how to convert a state-space model into transfer function form.

A first-order lead compensator can be designed using the root locus. A lead compensator in root locus form is given by

where the magnitude of zo is less than the magnitude of po. A phase-lead compensator tends to shift the root locus toward the left half plane. This results in an improvement in the system's stability and an increase in the response speed.

How is this accomplished? If you recall finding the asymptotes of the root locus that lead to the zeros at infinity, the equation to determine the intersection of the asymptotes along the real axis is:

When a lead compensator is added to a system, the value of this intersection will be a larger negative number than it was before. The net number of zeros and poles will be the same (one zero and one pole are added), but the added pole is a larger negative number than the added zero. Thus, the result of a lead compensator is that the asymptotes' intersection is moved further into the left half plane, and the entire root locus will be shifted to the left. This can increase the region of stability as well as the response speed.

In MATLAB a phase lead compensator in root locus form is implemented by using the transfer function in the form

```numlead = kc*[1 z];
```
and we can interconnect it with a plant as follows:
```sys = lead*plant;
```

A first-order phase-lead compensator can be designed using the frequency response. A lead compensator in frequency response form is given by

Note that this is equivalent to the root locus form

with p = 1/T, z = 1/aT, and Kc = a. In frequency response design, the phase-lead compensator adds positive phase to the system over the frequency range 1/aT to 1/T. A bode plot of a phase-lead compensator looks like the following

The two corner frequencies are at 1/aT and 1/T; note the positive phase that is added to the system between these two frequencies. Depending on the value of a, the maximum added phase can be up to 90 degrees; if you need more than 90 degrees of phase, two lead compensators can be used. The maximum amount of phase is added at the center frequency, which is located at

The equation which determines the maximum phase is

Additional positive phase increases the phase margin and thus increases the stability of the system. This type of compensator is designed by determining a from the amount of phase needed to satisfy the phase margin requirements, and determining T to place the added phase at the new gain-crossover frequency.

Another effect of the lead compensator can be seen in the magnitude plot. The lead compensator increases the gain of the system at high frequencies (the amount of this gain is equal to a). This can increase the crossover frequency, which will help to decrease the rise time and settling time of the system.

In MATLAB, a phase lead compensator in frequency response form is implemented by using the transfer function in the form

```numlead = kc*[1 z];
```
and we can interconnect it with a plant as follows:
```sys = lead*plant;
```

## Lag or Phase-Lag Compensator using Root Locus

A first-order lag compensator can be designed using the root locus. A lag compensator in root locus form is given by

where the magnitude of zo is greater than the magnitude of po. A phase-lag compensator tends to shift the root locus to the right, which is undesirable. For this reason, the pole and zero of a lag compensator must be placed close together (usually near the origin) so they do not appreciably change the transient response or stability characteristics of the system.

How does the lag controller shift the root locus to the right? If you recall finding the asymptotes of the root locus that lead to the zeros at infinity, the equation to determine the intersection of the asymptotes along the real axis is:

When a lag compensator is added to a system, the value of this intersection will be a smaller negative number than it was before. The net number of zeros and poles will be the same (one zero and one pole are added), but the added pole is a smaller negative number than the added zero. Thus, the result of a lag compensator is that the asymptotes' intersection is moved closer to the right half plane, and the entire root locus will be shifted to the right.

It was previously stated that that lag controller should only minimally change the transient response because of its negative effect. If the phase-lag compensator is not supposed to change the transient response noticeably, what is it good for? The answer is that a phase-lag compensator can improve the system's steady-state response. It works in the following manner. At high frequencies, the lag controller will have unity gain. At low frequencies, the gain will be z0/p0 which is greater than 1. This factor z0/p0 will multiply the position, velocity, or acceleration constant (Kp, Kv, or Ka), and the steady-state error will thus decrease by the factor z0/p0.

In MATLAB, a phase lead compensator in root locus form is implemented by using the transfer function in the form

```numlag = [1 z];
denlag = [1 p];
lag = tf(numlag,denlag);
```
and we can interconnect it with a plant as follows:
```sys = lag*plant;
```

## Lag or Phase-Lag Compensator using Frequency Response

A first-order phase-lag compensator can be designed using the frequency response. A lag compensator in frequency response form is given by

The phase-lag compensator looks similar to a phase-lead compensator, except that a is now less than 1. The main difference is that the lag compensator adds negative phase to the system over the specified frequency range, while a lead compensator adds positive phase over the specified frequency. A bode plot of a phase-lag compensator looks like the following

The two corner frequencies are at 1/T and 1/aT. The main effect of the lag compensator is shown in the magnitude plot. The lag compensator adds gain at low frequencies; the magnitude of this gain is equal to a. The effect of this gain is to cause the steady-state error of the closed-loop system to be decreased by a factor of a. Because the gain of the lag compensator is unity at middle and high frequencies, the transient response and stability are not impacted too much.

The side effect of the lag compensator is the negative phase that is added to the system between the two corner frequencies. Depending on the value a, up to -90 degrees of phase can be added. Care must be taken that the phase margin of the system with lag compensation is still satisfactory.

In MATLAB, a phase-lag compensator in frequency response form is implemented by using the transfer function in the form

```numlag = [a*T 1];
denlag = a*[T 1];
lag = tf(numlag,denlag);
```
and we can interconnect it with a plant as follows:
```sys = lag*plant;
```
Lead-lag Compensator using either Root Locus or Frequency Response

A lead-lag compensator combines the effects of a lead compensator with those of a lag compensator. The result is a system with improved transient response, stability and steady-state error. To implement a lead-lag compensator, first design the lead compensator to achieve the desired transient response and stability, and then add on a lag compensator to improve the steady-state response.