4.2.4. Difference Equations in the Z-domain

4.2.4.1. From Difference Equation to Transfer Function

A LTI system is completely characterized by its impulse response \(h[n]\) or equivalently the Z-transform of the impulse response \(H(z)\) which is called the transfer function. Remember:

\[y[n] = x[n]\ast h[n] \ZTright Y(z) = X(z)H(z).\]

Note that we thus have:

\[H(z) = \frac{Y(z)}{X(z)}\]

In case the impulse response is given to define the LTI system we can simply calculate the Z-transform to obtain \(H(z)\) often called the transfer function of the system.

In case the system is defined with a difference equation we could first calculate the impulse response and then calculate the Z-transform (we have done so in this section. But it is far easier to calculate the Z-transform of both sides of the difference equation.

As a first example we consider the difference equation

\[y[n] = x[n] + \alpha y[n-1]\]

for which we shown that the impulse response function \(h\) is given by:

\[h[n] = \alpha^n u[n]\]

From our table of Z-transform pairs we read:

\[a^n u[n] \ZTright \frac{1}{1 - az^{-1}}\]

so

\[H(z) = \frac{1}{1-\alpha z^{-1}}\]

Instead of first finding the impulse response function of a system we could start with the difference equation and apply the Z-transform to both sides of the equation:

\[\begin{split}\ZT\{ y[n] \} &= \ZT\{ x[n] + \alpha y[n-1] \}\\ Y(z) &= \ZT\{ x[n] \} + \alpha \ZT\{ y[n-1] \}\\ Y(z) &= X(z) + \alpha z^{-1} Y(z)\end{split}\]

Rearranging terms leads to

\[(1-\alpha z^{-1}) Y(z) = X(z)\]

and thus

\[H(z) = \frac{Y(z)}{X(z)} = \frac{1}{1-\alpha z^{-1}}\]

showing that \(H(z)\) can be directly calculated from the difference equation without explicit constrution of the (infinite length) impulse response function.

As another example consider the following difference equation:

\[y[n] = 1.5y [n - 1] - 0.5y [n - 2] + 0.5x[n].\]

Remember that

\[x[n-n_0]\ZTright z^{-n_0}X(z)\]

and knowing that the Z-transform is a linear transform we can apply the Z-transform to both sides of the above equation and obtain:

\[Y(z) = 1.5 z^{-1} Y(z) - 0.5 z^{-2} Y(z) + 0.5 X(z)\]

This can be rewritten as:

\[H(z) = \frac{Y(z)}{X(z)} = \frac{0.5}{1-1.5z^{-1}+0.5z^{-2}} = \frac{z^2}{2z^2 - 3z + 1}\]

The generic form of a difference equation is

\[\]

4.2.4.2. Poles and Zeros

The generic difference equation for an LTI system is:

\[a_0 y[n] + a_1 y[n-1] + \cdots a_N y[n-N] = b_0 x[n] + b_1 x[n-1] + \cdots b_N x[n-N]\]

We have taken the number of terms (called taps in DSP lingo) both equal to \(N\). In practice some of the \(a_i\) and \(b_j\) can be zero.

Taking the Z-transform on both sides of the equation and rearranging terms leads to the transfer function \(H(z)\):

\[H(z) = \frac{Y(z)}{X(z)} = \frac{b_0 + b_1 z^{-1} + \cdots + b_N z^{-N}}{ a_0 + a_1 z^{-1} + \cdots + a_N z^{-N}}\]

Multiplying by \(z^N/z^N\) results in

\[H(z) = \frac{Y(z)}{X(z)} = \frac{b_0 z^{N} + b_1 z^{N-1} + \cdots + b_N}{ a_0 z^{N} + a_1 z^{N-1} + \cdots + a_N }\]

The fundamental theorem of algebra states that every \(N\)-th order complex polynomial has exactly \(N\) roots. The roots of the nominator are called the zeros of the transfer function and indinated with \(q_i\) and the roots of the denominator are called the poles of \(H\) and indinated as \(p_i\). With these zeros and poles we can rewrite the transfer function as:

\[H(z) = \frac{Y(z)}{X(z)} = K \frac{(z-q_1)(z-q_2)\cdots(z-q_N)}{(z-p_1)(z-p_2)\cdots(z-p_N)}\]

The factor \(K\) expresses the fact that \(b_0\) and \(a_0\) need not be equal to one.

The zeros and poles of such a rational function in \(z\) for a system with real valued coefficients come in conjugate pairs. That is, if \(p\) is a pole then \(p^*\) is a pole as well. Also when \(z\) is a zero of \(H(z)\) then \(z^*\) is a zero as well.

A simple proof for this is as follows: Write \(H(z) = \frac{p(z)}{q(z)}\), with \(p\) and \(q\) polynomials. Then \(p\) and \(q\) must have real coefficients to get a real-valued IR filter. Write \(p(z) = a_n z^n + a_{n-1} z^{n-1} + \cdots + a_1 z + a_0\) with \(a_i \in \setR\) and let \(z_0\) be a zero of \(p\). Then \(0 = 0^* = p(z_0)^* = a_n^* (z_0^n)^* + \cdots + a_1^* z_0^* + a_0^* = a_n (z_0^*)^n + \cdots + a_1 z_0^* + a_0 = p(z_0^*)\), so \(z_0^*\) is a zero of \(p\) as well. The same holds for \(q\).

Without proof we further state the following. For a system characterized with a difference equation with real coefficients

  • the poles should be inside the unit circle for the system to be stable,

  • Any such system (arbitrary \(N\)) can be build as the cascade (sequence) of second order systems (each with \(N=2\)) and possibly a first order system \(N=1\) (in scipy.signal such a system build from at most order 2 systems is called a SOS system (Secord Order Sequence)). Note that a second order system with real coefficients has a conjugate pair of zeros and a conjugate pair of poles.

Because a LTI system is completely characterized by its transfer function \(H(z)\), the system is also completely characterized by its set of zeros and poles (together with the gain factor \(K\)). Plotting the zeros and poles in the complex plane characterizes the LTI system.

As an example consider the LTI system with transfer function \(H(z)\):

\[\begin{split}H(z) &= \frac{z^2 - 1.9 z + 1}{z^2 - 1.8 z + 0.9} \\ &= \frac{(z - 0.95 - 0.31j)(z - 0.95 + 0.31j)}{ (z - 0.9 - 0.3j)(z - 0.9 + 0.3 j)}\end{split}\]

The poles and zeros are plotted in the complex plane, poles are indicated with a small cross \(\times\) and zeros are indicated with a small circle \(\circ\). In the complex plane the unit circle is also shown.

In the figure on the right the frequency response

\[H(\W) = H(z)\Bigr|_{z=e^{j\W}}\]

is also shown.

Show code for figures
1import numpy as np
2import matplotlib.pyplot as plt
3from audiolazy import z
4
5H = (z**2-1.9*z+1)/(z**2-1.8*z+0.9)
6H.zplot().savefig('source/figures/hzplot.png')
7H.plot().savefig('source/figures/hfplot.png')
../../_images/hzplot.png ../../_images/hfplot.png

The placements of the poles and zeros determine the system (with a possible gain factor \(K\)) and thus determines the frequency response. Consider only the magnitude \(H(\W)\):

\[\begin{split}|H(\W)| = \left| H(z)\Bigr|_{z=e^{j\W}} \right| &= \left| k \frac{(e^{j\W}-q_1)(e^{j\W}-q_2)\cdots(e^{j\W}-q_N)}{ (e^{j\W}-p_1)(e^{j\W}-p_2)\cdots(e^{j\W}-p_N)} \right| \\ &= K \frac{|e^{j\W}-q_1| |e^{j\W}-q_2| \cdots |e^{j\W}-q_N|}{ |e^{j\W}-p_1| |e^{j\W}-p_2| \cdots |e^{j\W}-p_N|}\end{split}\]

From this equation we see that if \(e^{j\W}\) is close to a zero the magnitude of the frequency response tends to be small, but if it is close to a pole its response tends to be large. In the example given zeros are exactly on the unit circle and thus the response magnitude in decibels is \(-\infty\). If \(e^{j\W}\) is further away from a zero pole pair (wich are really close to eachother) the distance to the pole and the distance to the zero are about equal and thus the influences of both cancel out (leadning to a response of 1).