```python
import control
import sympy
import numpy as np
import matplotlib.pyplot as plt
sympy.init_printing()
plt.rcParams['figure.figsize']=(10, 5)
```

## Original System


```python
s = control.tf([1, 0], [0, 1])
```


```python
G = 1/((s+2)*s)
G
```




$$\frac{1}{s^2 + 2 s}$$




```python
control.rlocus(G, xlim=[-5, 0.1], ylim=[-5, 5]);
plt.title('uncompensated root locus')
sd = -2 + 2j

plt.plot(np.real(sd), np.imag(sd), 's')
plt.plot(np.real(sd), -np.imag(sd), 's')
```


```python
Gc = G/(1+G)
t, y = control.step_response(Gc/s, T=np.linspace(0, 20));
plt.plot(t, t)
plt.plot(t, y)
plt.title('uncompensated step response')

Kv = np.real((control.minreal(s*G).horner(0))[0, 0])
Kv

plt.figure()
t, y = control.step_response(Gc/s, T=np.linspace(0, 20));
plt.plot(t, t-y)
plt.hlines(1/Kv, 0, 20)
```

## Lead Compensator


```python
H_lead = 8*(s+2)/(s+4)
H_lead
```




$$\frac{8 s + 16}{s + 4}$$




```python
control.rlocus(G*H_lead, ylim=[-3, 3]);
plt.plot(-2, 2, 's')
plt.plot(-2, -2, 's')
plt.title('lead compensated root locus');
```


```python
Gc_lead = G*H_lead/(1+G*H_lead)
t = np.linspace(0, 10, 1000)
_, y = control.step_response(Gc_lead/s, T=t);
plt.plot(t, t)
plt.plot(t, y)
plt.title('lead compensated ramp response')

plt.figure()
_, y = control.step_response(Gc_lead/s, T=t);
plt.plot(t, t-y)
plt.hlines(0.5, 0, 20)
```

## Lead-Lag Compensator


```python
H_lag = (s+0.05)/(s+0.01)
H_lag
```




$$\frac{s + 0.05}{s + 0.01}$$




```python
H = H_lag*H_lead
```


```python
control.rlocus(G*H);
plt.plot(-2, 2, 's')
plt.plot(-2, -2, 's')
```


```python
control.minreal(G*H_lead*s).horner(0)
```

    2 states have been removed from the model





    array([[[2.+0.j]]])




```python
control.minreal(G*H*s).horner(0)
```

    2 states have been removed from the model





    array([[[10.+0.j]]])




```python
Gc_leadlag = G*H/(1+G*H)
t = np.linspace(0, 100, 1000)
_, y = control.step_response(Gc_leadlag/s, T=t);
plt.plot(t, t)
plt.plot(t, y)
plt.title('lead-lag compensated ramp response')

plt.figure()
plt.plot(t, t - y)
plt.hlines(0.1, t[0], t[-1])
plt.title('lead-lag compensated ramp response error')
```

91a2a06e994744bd16479ce34ff75f679e7e48f7
ipynb
Jupyter Notebook
08.Lag-Lead.ipynb
jgoppert/aae364_notebook
bc77866860e6bdb7d59467ce9817a604c7f26e20
BSD-3-Clause
2020-01-18T03:46:08.000Z
2020-01-18T03:46:08.000Z
08.Lag-Lead.ipynb
jgoppert/aae364_notebook
bc77866860e6bdb7d59467ce9817a604c7f26e20
BSD-3-Clause
08.Lag-Lead.ipynb
jgoppert/aae364_notebook
bc77866860e6bdb7d59467ce9817a604c7f26e20
BSD-3-Clause
2019-03-30T19:32:13.000Z
2020-07-09T07:18:17.000Z
Qwen/Qwen-72B
1. YES
2. YES