## Solutions to auto-diagnostic test 3
Exercises By L.C. Félix-Herrán, Tec.

## 1)
Zero-order-hold sampling with sampling period $h=0.1$ and process model 
$$ G(s) = \frac{s(s+0.3}{(s-0.2)(s+0.7)}. $$
### Solution
#### Step-response of the system
$$ Y(s) = \frac{G(s)}{s} = \frac{(s+0.3}{(s-0.2)(s+0.7)} = \frac{0.556}{s-0.2} + \frac{0.444}{s+0.7} $$
$$ y(t) = \mathcal{L}^{-1} \{ Y(s) \} = 0.556\mathrm{e}^{0.2t} + 0.444 \mathrm{e}^{-0.7t}.$$
#### Sample and apply z-transform
$$ Y(z) = 0.556 \mathcal{Z}\{(\mathrm{e}^{0.2h})^k\} + 0.444 \mathcal{Z}\{(\mathrm{e}^{-0.7h})^k\} = \frac{0.556 z}{z - \mathrm{e}^{0.2h}} + \frac{0.444z}{z - \mathrm{e}^{-0.7h}}. $$
#### Divide by z-transform of step input
\begin{align}
H(z) &= \frac{Y(z)}{U(z)} = \frac{z-1}{z} \left(\frac{0.556 z}{z - \mathrm{e}^{0.2h}} + \frac{0.444z}{z - \mathrm{e}^{-0.7h}} \right)\\
&= (z-1) \frac{ 0.556(z - \mathrm{e}^{-0.7h}) + 0.444(z - \mathrm{e}^{0.2h})}{(z - \mathrm{e}^{0.2h})(z - \mathrm{e}^{-0.7h})}\\
&= \frac{\big(z-1\big)\big( z - \big(0.556 \mathrm{e}^{-0.7h} - 0.444 \mathrm{e}^{0.2h}\big)\big)}{(z - \mathrm{e}^{0.2h})(z - \mathrm{e}^{-0.7h})}\\
\end{align}

## 2)
Closed-loop system with plant model $$G(s) = \frac{27}{s(s+27)}. $$
### a) Do ZOH-sampling
#### Step-response of the  system
$$Y(z) = \frac{G(s)}{s} = \frac{27}{s^2(s+27)} = -\frac{1/27}{s} + \frac{1}{s^2} + \frac{1/27}{s+27}. $$
$$ y(t) = \mathcal{L}^{-1} \{ Y(s) \} = t - \frac{1}{27} + \frac{1}{27} \mathrm{e}^{-27t}.$$
#### Sample and apply z-transform
$$ Y(z) = \frac{zh}{(z-1)^2} - \frac{1/27 z}{z-1} + \frac{1/27 z}{ z - \mathrm{e}^{-27h}}. $$
#### Divide by z-transform of step input
\begin{align}
H(z) &= \frac{Y(z)}{U(z)} = \frac{z-1}{z} \left(\frac{zh}{(z-1)^2} - \frac{1/27 z}{z-1} + \frac{1/27 z}{ z - \mathrm{e}^{-27h}} \right)\\
&= \frac{h}{z-1} - \frac{1}{27} + \frac{ 1/27(z-1)}{ z - \mathrm{e}^{-27h}}\\
&= \frac{h(z - \mathrm{e}^{-27h}) - \frac{1}{27}(z-1)(z - \mathrm{e}^{-27h}) + \frac{1}{27}(z-1)^2}{(z-1)(z - \mathrm{e}^{-27h})}\\
&= \frac{h (z - \mathrm{e}^{-27h}) - \frac{1}{27}(z^2 - (1+\mathrm{e}^{-27h})z + \mathrm{e}^{-27h}) + \frac{1}{27}(z^2 - 2z +1)}{(z-1)(z - \mathrm{e}^{-27h})}\\
&= \frac{\big(h - \frac{1}{27}(1-\mathrm{e}^{-27h})\big) z  - \big(h\mathrm{e}^{-27h} + \frac{1}{27}\mathrm{e}^{-27h} - \frac{1}{27}\big)}{(z-1)(z - \mathrm{e}^{-27h})}
\end{align}



```python
import numpy as np
h = 0.1
e27h = np.exp(-27*h)
b0 = h - 1.0/27*(1 - e27h)
b1 = -(h*e27h + 1.0/27*(e27h - 1))
print("exp(-27h) = %f, b0=%f, b1=%f" %(e27h, b0, b1))
```

    exp(-27h) = 0.067206, b0=0.065452, b1=0.027827


Pulse-transfer function for the process:
$$ H(z) = \frac{0.0065 z + 0.028}{(z-1)(z-0.067)}. $$

### b) Find difference equation corresponding to plant model
Using the shift operator $\text{q}$ we have
$$ c(k) = H(\text{q}) u(k) = \frac{0.0065\text{q} + 0.028}{(\text{q}-1)(\text{q} - 0.067)}u(k) $$
$$ (\text{q}-1)(\text{q} - 0.067) c(k) = (\frac{0.0065\text{q} + 0.028})u(k)$$
$$ (\text{q}^2 - 1.067\text{q} + 0.067) c(k) = (\frac{0.0065\text{q} + 0.028})u(k) $$
$$ c(k+2) - 1.067 c(k+1) + 0.067 c(k) = 0.0065 u(k+1) + 0.028 u(k) $$

## 3) 
Given $$ G(s) = \frac{3s\mathrm{e}^{-2s}}{s+1}, $$
Determine the discretization of the system assuming that it is preceeded by a hold and proceeded by an ideal sampler for the following cases

- **a)** ZOH and sampling period $h=0.5$
- **b)** ZOH and sampling period $h=0.3$
- **c)** FOH and sampling  period $h=0.5$

### Solutions
#### b)
The delay $\tau$ in the process is 2, so we have $$ \tau = 6h + mh$$ with $h=0.3$ and $ m = 2/3$. Let $y_0(t)$ be the step-response of the system without the delay, and $y_1(t)$ be the step-response of the system for a delay of $6h$. We get
\begin{align}
y_0(t) &= \mathcal{L}^{-1} \{ \frac{3s}{s+1} \cdot \frac{1}{s} \} = 3\mathrm{e}^{-t}u_H(t)\\
y_1(t) &= y_0(t-6h)\\
y(t) &= y_1(t-mh) = y_0(t-6h-mh)
\end{align}
Applying the z-transform to the sampled signal $y_1(kh)$ gives
$$ Y_1(z) = z^{-6} Y_0(z) = z^{-6} \frac{3z}{z-\mathrm{e}^{-h}}. $$
In order to obtain the z-transform of the actual step-response $y(t)$ we need to use the modified z-transform (See the textbook Fernández y Ramírez, ch 4.6).
\begin{align}
 Y(z, m) &= \sum_{k=0}^\infty y_1(kh+mh)z^{-k} = \sum_{k=0}^\infty 3\mathrm{e}^{-kh-mh}z^{-k}\\
 &= \mathrm{e}^{-mh} \sum_{k=0}^\infty 3\mathrm{e}^{-kh}z^{-k} = \mathrm{e}^{-mh} Y_1(z)\\
 &= \mathrm{e}^{-mh} \frac{3}{z^5(z-\mathrm{e}^{-h})}
 \end{align}


```python

```


```python
import numpy as np
h = 0.3
m = 2.0/3.0
emh = np.exp(-m*h)
eh = np.exp(-h)
print('e^{-mh}=%s' %(emh))
print('e^{-h}=%s' %(eh))
3*emh
np.exp(-0.33*0.3)
```

    e^{-mh}=0.8187307530779818
    e^{-h}=0.7408182206817179





    0.9057427080235485



With numerical values
$$ Y(z,m=2/3) = 0.82 \frac{3}{z^5(z-0.74)}$$
All that is left is to divide by the z-transform of the step signal
\begin{align}
H(z) &= \frac{Y(z)}{U(z)} = \frac{z-1}{z}\frac{3\cdot 0.82}{z^5(z-0.74)}\\
&= \frac{2.46(z-1)}{z^6(z-0.74)}
\end{align}


```python
0.44444444 + 0.555555555555
```




    0.9999999955550001




```python

```

f97f9b0412da3e2a89b697bcd4620078c7699b77
ipynb
Jupyter Notebook
discrete-time-systems/notebooks/Auto-diagnostic-3.ipynb
kjartan-at-tec/mr2007-computerized-control
16e35f5007f53870eaf344eea1165507505ab4aa
MIT
2020-11-07T05:20:37.000Z
2020-12-22T09:46:13.000Z
discrete-time-systems/notebooks/Auto-diagnostic-3.ipynb
kjartan-at-tec/mr2007-computerized-control
16e35f5007f53870eaf344eea1165507505ab4aa
MIT
2020-06-12T20:44:41.000Z
2020-06-12T20:49:00.000Z
discrete-time-systems/notebooks/Auto-diagnostic-3.ipynb
kjartan-at-tec/mr2007-computerized-control
16e35f5007f53870eaf344eea1165507505ab4aa
MIT
2021-03-14T03:55:27.000Z
2021-03-14T03:55:27.000Z
Qwen/Qwen-72B
1. YES
2. YES