This we will explore digital systems and learn more about the z-transfer function model.
The material in this presentation and notes is based on Chapter 9 (Starting at Section 9.7) of Steven T. Karris, Signals and Systems: with Matlab Computation and Simulink Modelling, 5th Edition. from the Required Reading List. I have skipped the section on digital state-space models.
In the lecture that introduced the z-transform we talked about the representation of a discrete-time (DT) system by the model shown below:
In this session, we want to explore the contents of the central block.
$$y_d[n] = h[n] * x_d[n]$$
$$Y_d(z) = H(z) X_d(z)$$
Let us assume that the sequence transformation is a difference equation of the form2:
$$\begin{array}{l} y[n] + {a_1}y[n - 1] + {a_2}y[n - 2] + \cdots + {a_k}y[n - k]\\ \quad = {b_0}x[n] + {b_1}u[n - 1] + {b_2}u[n - 2] + \cdots + {b_k}u[n - k] \end{array}$$
From the z-transform properties
$$f[n-m] \Leftrightarrow z^{-m}F(z)$$
so....
$$Y(z) + a_1z^{-1}Y(z) + a_2z^{-2}Y(z) + \cdots + a_kz^{-k}Y(z) = ...$$
$$b_0 U(z) + b_1z^{-1}U(z) + b_2z^{-2}U(z) + \cdots + b_kz^{-k}U(z)$$
$$\begin{array}{l} \left( {1 + {a_1}{z^{ - 1}} + {a_2}{z^{ - 2}} + \cdots {a_k}{z^{ - k}}} \right)Y(z) = \\ \quad \left( {{b_0} + {b_1}{z^{ - 1}} + {b_2}{z^{ - 2}} + \cdots {b_k}{z^{ - k}}} \right)U(z) \end{array}$$
from which ...
$$Y(z) = \left(\frac{b_0 + b_{1}z^{-1} + b_{2}z^{-2} + \cdots b_{k}z^{-k}}{1 + a_{1}z^{-1} + a_{2}z^{-2} + \cdots a_{k}z^{-k} }\right) U(z)$$
We define the discrete time transfer function $H(z) := Y(z)/U(z)$ so...
$$H(z) = \frac{Y(z)}{U(z)} = \frac{b_0 + b_{1}z^{-1} + b_{2}z^{-2} + \cdots b_{k}z^{-k}}{1 + a_{1}z^{-1} + a_{2}z^{-2} + \cdots a_{k}z^{-k} }$$
... or more conventionally3:
$$H(z) = \frac{b_0z^k + b_{1}z^{k-1} + b_{2}z^{k-2} + \cdots b_{k-1}z + b_{k}}{z^k + a_{1}z^{k-1} + a_{2}z^{k-2} + \cdots a_{k-1} z + a_{k}}$$
The discrete-time impulse reponse $h[n]$ is the response of the DT system to the input $x[n] = \delta[n]$
Last week we showed that $\mathcal{Z}\left\{\delta[n]\right\}$ was defined by the transform pair
$$\delta[n] \Leftrightarrow 1$$
so
$$h[n] = \mathcal{Z}^{-1}\left\{H(z).1\right\} = \mathcal{Z}^{-1}\left\{H(z)\right\}$$
Karris Example 9.10:
The difference equation describing the input-output relationship of a DT system with zero initial conditions, is:
$$y[n] - 0.5 y[n-1] + 0.125 y[n-2] = x[n] + x[n -1]$$
Compute:
$$H(z) = \frac{Y(z)}{U(z)} = ...?$$
See dtm_ex1_2.mlx. (Also available as dtm_ex1_2.m.)
The difference equation describing the input-output relationship of the DT system with zero initial conditions, is:
$$y[n] - 0.5 y[n-1] + 0.125 y[n-2] = x[n] + x[n -1]$$
Numerator $z + 1$
Nz = [0 1 1];
Denominator $z^2 - 0.5 z + 0.125$
Dz = [1 -0.5 0.125];
[r,p,k] = residue(Nz,Dz)
r = 0.5000 - 2.5000i 0.5000 + 2.5000i p = 0.2500 + 0.2500i 0.2500 - 0.2500i k = []
Hz = tf(Nz,Dz,1)
hn = impulse(Hz, 15);
Hz = z + 1 ------------------- z^2 - 0.5 z + 0.125 Sample time: 1 seconds Discrete-time transfer function.
stem([0:15], hn)
grid
title('Example 5 - Part 2')
xlabel('n')
ylabel('Impulse response h[n]')
impulse(Hz,15)
grid
title('Example 5 - Part 2 - As Analogue Signal')
xlabel('nTs [s]')
ylabel('Impulse response h(t)')
$$Y(z) = H(z)X(z)$$
$$u_0[n] \Leftrightarrow \frac{z}{z - 1}$$
$$\begin{array}{lcl} Y(z) = H(z){U_0}(z) &=& \frac{{{z^2} + z}}{{{z^2} + 0.5z + 0.125}}.\frac{z}{{z - 1}}\\ & = & \frac{{z({z^2} + z)}}{{({z^2} + 0.5z + 0.125)(z - 1)}} \end{array}$$
$$\frac{Y(z)}{z} = \frac{z^2 + z}{(z^2 + 0.5 z + 0.125)(z - 1)}$$
Solved by inverse Z-transform.
See dtm_ex1_3.mlx. (Also available as dtm_ex1_3.m.)
open dtm_ex1_3
Code extracted from dtm_ex1_3.m:
Ts = 1;
z = tf('z', Ts)
z = z Sample time: 1 seconds Discrete-time transfer function.
Hz = (z^2 + z)/(z^2 - 0.5 * z + 0.125)
Hz = z^2 + z ------------------- z^2 - 0.5 z + 0.125 Sample time: 1 seconds Discrete-time transfer function.
step(Hz)
grid
title('Example 1 - Part 3 - As Analogue Signal')
xlabel('nTs [s]')
ylabel('Step response y(t)')
axis([0,15,0,3.5])
dtm
c2d
Let's see what the help function says:
doc c2d
See digit_butter.m.
First determine the cut-off frequency $\omega_c$
$$\omega_c = 2\pi f_c = 2\times \pi \times 20\times 10^3\;\mathrm{rad/s}$$
wc = 2*pi*20e3
wc = 1.2566e+05
$$\omega_c = 125.66\times 10^3\;\mathrm{rad/s}$$
From the lecture on filters, we know the 2nd-order butterworth filter has transfer function:
$$H(s) = \frac{{Y(s)}}{{U(s)}} = {\rm{ }}\frac{{\omega _c^2}}{{{s^2} + {\omega _c}\sqrt 2 \,s + \omega _c^2}}$$
Substituting for $\omega_c = 125.6637\times 10^3 $ this is ...?
Hs = tf(wc^2,[1 wc*sqrt(2), wc^2])
Hs = 1.579e10 --------------------------- s^2 + 1.777e05 s + 1.579e10 Continuous-time transfer function.
$$H(s) = \frac{{15.79 \times {{10}^9}}}{{{s^2} + 177.7 \times {{10}^3}s + 15.79 \times {{10}^9}}}$$
Matlab:
bode(Hs,{1e4,1e8})
grid
From the bode diagram, the frequency at which $|H(j\omega)|$ is $-80$ dB is approx $12.6\times 10^6$ rad/s.
To avoid aliasing, we should choose a sampling frequency twice this = ?
$\omega_s = 2\times 12.6\times 10^6$ rad/s.
ws = 2* 12.6e6
ws = 25200000
So
$\omega_s = 25.2\times 10^6$ rad/s.
Sampling frequency ($f_s$) in Hz = ?
$$f_s = \omega_s/(2\pi)\;\mathrm{Mhz}$$
fs = ws/(2*pi)
fs = 4.0107e+06
$$f_s = 40.11\;\mathrm{Mhz}$$
Sampling time $T_s = ?$
$T_s = 1/fs\;\mathrm{s}$
Ts = 1/fs
Ts = 2.4933e-07
$$T_s = 1/f_s \approx 0.25\;\mu\mathrm{s}$$
zero-order-hold equivalent
Hz = c2d(Hs, Ts)
Hz = 0.0004836 z + 0.0004765 ----------------------- z^2 - 1.956 z + 0.9567 Sample time: 2.4933e-07 seconds Discrete-time transfer function.
step(Hz)
From previous result:
$$H(z) = \frac{Y(z)}{U(z)} = \frac{486.6\times 10^{-6}z + 476.5\times 10^{-6}}{z^2 - 1.956z + 0.9567}$$
Dividing top and bottom by $z^2$ ...
$$H(z) = \frac{Y(z)}{U(z)} = \frac{486.6\times 10^{-6}z^{-1} + 476.5\times 10^{-6}z^{-2}}{1 - 1.956z^{-1} + 0.9567z^{-2}}$$
expanding out ...
$$\begin{array}{l} Y(z) - 1.956{z^{ - 1}}Y(z) + 0.9567{z^{ - 2}}Y(z) = \\ \quad 486.6 \times {10^{ - 6}}{z^{ - 1}}U(z) + 476.5 \times {10^{ - 6}}{z^{ - 2}}U(z) \end{array}$$
Inverse z-transform gives ...
$$\begin{array}{l} y[n] - 1.956y[n - 1] + 0.9567y[n - 2] = \\ \quad 486.6 \times {10^{ - 6}}u[n - 1] + 476.5 \times {10^{ - 6}}u[n - 2] \end{array}$$
in algorithmic form (compute $y[n]$ from past values of $u$ and $y$) ...
$$\begin{array}{l} y[n] = 1.956y[n - 1] - 0.9567y[n - 2] + 486.6 \times {10^{ - 6}}u[n - 1] + ...\\ \quad 476.5 \times {10^{ - 6}}u[n - 2] \end{array}$$
To implement: $$y[n] = 1.956 y[n-1] - 0.9567 y[n - 2] + 486.6\times 10^{-6} u[n-1] + 476.5\times 10^{-6} u[n-2]$$
/* Initialize */
Ts = 2.4933e-07; /* more probably some fraction of clock speed */
ynm1 = 0; ynm2 = 0; unm1 = 0; unm2 = 0;
while (true) {
un = read_adc;
yn = 1.956*ynm1 - 0.9567*ynm2 + 486.6e-6*unm1 + 476.5e-6*unm2;
write_dac(yn);
/* store past values */
ynm2 = ynm1; ynm1 = yn;
unm2 = unm1; unm1 = un;
wait(Ts);
}