Lecture 4 · Digital Signal Processing · University of Klagenfurt, 2022
Lecture 4 of 6
From Digital Signal Processing at the University of Klagenfurt, first taught in 2020: this is the edition of summer 2022, so some of it may be a little dated. All lectures.
01
From now on, for convenience, T=1. The Z-transform X(z) of the discrete-time signal x(n) is
X(z)=\sum_{n=-\infty}^{+\infty}x(n)\,z^{-n},\qquad z\in\mathbb{C}
It comes with the idea of convergence: we ask for absolute convergence,
\sum_{n=-\infty}^{+\infty}\left|x(n)\,z^{-n}\right|<\infty
and the set of z where it holds is the region of convergence (ROC).
X(z)=\mathcal{Z}[x]=\sum_nx(n)\,z^{-n}. On the unit circle it is the DTFT: X\left(e^{j2\pi f}\right)=\mathcal{F}[x(n)].
| linearity | \mathcal{Z}[\alpha_1x_1(n)+\alpha_2x_2(n)]=\alpha_1X_1(z)+\alpha_2X_2(z) |
| flipping | \mathcal{Z}[x(-n)]=X\left(\frac1z\right) |
| conjugation | \mathcal{Z}[x^*(n)]=X^*(z^*) |
| time shift | \mathcal{Z}[x(n-n_0)]=z^{-n_0}X(z) |
| scaling in z | \mathcal{Z}[a^nx(n)]=X\left(\frac za\right) |
| upsampling | \mathcal{Z}\left[x\left(\frac na\right)\right]=X(z^a), with zeros where \frac na is not an integer |
| derivative | \mathcal{Z}[n\,x(n)]=-z\,\dfrac{dX(z)}{dz} |
| convolution | \mathcal{Z}[x_1*x_2(n)]=X_1(z)\cdot X_2(z) |
Compute the Z-transform X(z) of the discrete-time signals
1. X(z)=z^{-n_0}, for all z\neq0 if n_0>0.
2. X(z)=a_0+a_1z^{-1}+\dots+a_Nz^{-N}=\sum_{n=0}^{N}a_nz^{-n}: a polynomial in z^{-1}, converging for z\neq0.
3. A geometric series in q=az^{-1}:
X(z)=\sum_{n=0}^{\infty}\left(az^{-1}\right)^n=\frac{1}{1-az^{-1}},\qquad |z|>|a|
4. With m=-n:
X(z)=-\sum_{m=1}^{\infty}\left(b^{-1}z\right)^m=1-\frac{1}{1-b^{-1}z}=\frac{1}{1-bz^{-1}},\qquad |z|<|b|
The same expression as item 3, with a different ROC: the formula alone does not say whether the signal is causal or anticausal.
5. H(z)=1+0.2z^{-1}, so Y(z)=\dfrac{1+0.2z^{-1}}{1-az^{-1}}=-\dfrac{0.2}{a}+\dfrac{1+\frac{0.2}{a}}{1-az^{-1}}, |z|>|a|, and for a\neq0
y(n)=-\frac{0.2}{a}\,\delta(n)+\left(1+\frac{0.2}{a}\right)a^n\,1_0(n)
Solve the four exercises.
a. \mathrm{rect}(2t) is 1 on \left[-\frac14,\frac14\right); the step keeps \left[0,\frac14\right): \ x(t)=\mathrm{rect}\left(\frac{t-1/8}{1/4}\right) and X(f)=\frac14\,\mathrm{sinc}\left(\frac f4\right)e^{-j\pi f/4}.
b. Only three samples are non-zero, x(\pm T)=\frac12 and x(0)=1:
X(f)=T\sum_kx(kT)\,e^{-j2\pi fkT}=\frac12\left[\frac12e^{j\pi f}+1+\frac12e^{-j\pi f}\right]=\frac12+\frac12\cos(\pi f)=\cos^2\left(\frac{\pi f}{2}\right)
real and non-negative, periodic with period \frac1T=2 Hz.
c. x(n)=\frac12\left[1+(-1)^n\right]: the DFT of the ones is N\delta(h), the one of (-1)^n is the exam exercise of lecture 3. So, for N even, X=\left[\frac N2,0,\dots,0,\frac N2,0,\dots,0\right] with the second line at h=\frac N2; for N odd, X(0)=\frac{N+1}{2} and X(h)=\frac12+\frac j2\tan\left(\frac{\pi h}{N}\right) otherwise.
d. Two geometric series, one per exponential of the cosine:
X(z)=\frac12\left(\frac{e^{j\varphi}}{1-e^{j2\pi f}z^{-1}}+\frac{e^{-j\varphi}}{1-e^{-j2\pi f}z^{-1}}\right)=\frac{\cos\varphi-\cos(2\pi f-\varphi)\,z^{-1}}{1-2\cos(2\pi f)\,z^{-1}+z^{-2}},\qquad|z|>1
with two poles on the unit circle, at e^{\pm j2\pi f}.
Exercise c: the DFT computed by fft against the formula, for any N.
No saved run survives. What to expect for N=200: two lines of height 100, at indices 1 and 101 (Matlab counts from 1), with the formula on top of them. For an odd N, a line of height \frac{N+1}{2} at index 1 and a curve that grows near h=\frac N2.
The script compares magnitudes only, not phases.
02
The Z-transform is convenient because a convolution in time becomes a multiplication of polynomials in z. A general discrete-time system
x(n) h(n) y(n)
has the input-output relation, with x(n) and y(n) causal,
y(n)=\underbrace{\sum_{k=1}^{N}a_k\,y(n-k)}_{\text{AR, autoregressive}}+\underbrace{\sum_{m=0}^{M}b_m\,x(n-m)}_{\text{MA, moving average}}
How can we identify the impulse response h(n)?
Find the impulse response h(n) of the systems below, with x and y causal and x(n)=[1,0,\dots,0]:
1. Feed the impulse: y=\left[1,\,-1,\,\frac14,\,0,\dots\right]. The response stops after three samples: a finite impulse response, h(n)=\delta(n)-\delta(n-1)+\frac14\delta(n-2), with b_0=1, b_1=-1, b_2=\frac14.
2. Feed the impulse: y=\left[1,\,1,\,\frac12,\,\frac14,\,\frac18,\dots\right]. The feedback keeps it going forever: an infinite impulse response. With the transfer function of the next slide,
H(z)=\frac{1+\frac12z^{-1}}{1-\frac12z^{-1}}=-1+\frac{2}{1-\frac12z^{-1}}\ \Longrightarrow\ h(n)=-\delta(n)+2\left(\frac12\right)^n1_0(n),\qquad|z|>\frac12
Take the Z-transform of the general input-output relation:
Y(z)=\sum_{k=1}^{N}a_k\,z^{-k}\,Y(z)+\sum_{m=0}^{M}b_m\,z^{-m}\,X(z)
therefore
Y(z)=X(z)\cdot\frac{\sum_{m=0}^{M}b_m\,z^{-m}}{1-\sum_{k=1}^{N}a_k\,z^{-k}}=X(z)\cdot\frac{B(z)}{A(z)}=X(z)\cdot H(z)
H(z) is the transfer function of the filter: the roots of B(z) are its zeros, the roots of A(z) its poles. For the IIR filter of Ex. 2:
A causal filter is stable when all its poles are inside the unit circle.
The frequency response of a filter is the transfer function on the unit circle:
\tilde H(f)=H\left(e^{j2\pi f}\right),\qquad |\tilde H(f)|=\left|\frac{B\left(e^{j2\pi f}\right)}{A\left(e^{j2\pi f}\right)}\right|
With B(z)=c\prod_m\left(1-z_mz^{-1}\right) and A(z)=\prod_k\left(1-p_kz^{-1}\right), and \left|e^{j2\pi f}\right|=1,
|\tilde H(f)|=|c|\,\frac{\prod_m\left|e^{j2\pi f}-z_m\right|}{\prod_k\left|e^{j2\pi f}-p_k\right|}
the product of the distances of the point e^{j2\pi f} from the zeros, over the product of its distances from the poles. Walk around the circle: near a zero the response dips, near a pole it peaks.
H(z)=\frac12+\frac12z^{-2}=\dfrac{z^2+1}{2z^2}: zeros at z=\pm j, a double pole at z=0. On the unit circle,
\tilde H(f)=\frac12+\frac12e^{-j4\pi f}=e^{-j2\pi f}\,\frac{e^{j2\pi f}+e^{-j2\pi f}}{2}=\cos(2\pi f)\,e^{-j2\pi f}
so |\tilde H(f)|=|\cos(2\pi f)|, and the phase is -2\pi f (a delay of one sample), with jumps of \pi at f=\frac14 and \frac34, where the cosine changes sign.
The input \cos\left(\frac{2\pi}{4}n\right) sits exactly at f=\frac14, on the zero z=j: for all n the output is 0. Started at n=0, x(n)=[1,0,-1,0,1,\dots], only a transient survives, y(n)=\frac12\delta(n). The filter is a notch: it removes the frequency \frac14.
H(z)=\frac{1+\frac12z^{-1}+\frac14z^{-2}}{1-2z^{-1}-\frac13z^{-2}}=-\frac34+\frac{\frac74-z^{-1}}{1-2z^{-1}-\frac13z^{-2}}=-\frac34+\frac{A}{1-p_1z^{-1}}+\frac{B}{1-p_2z^{-1}}
The poles solve 3z^2-6z-1=0: p_{1,2}=1\mp\frac{2}{\sqrt3}, with |p_1|\approx0.15 and |p_2|\approx2.15; the residues are
A=\frac{14-3\sqrt3}{16}\approx0.55,\qquad B=\frac{14+3\sqrt3}{16}\approx1.20\qquad(A+B=\tfrac74)
Each ROC gives a different h(n):
03
How do we build the system \ y(n)=\sum_{k=1}^{N}a_k\,y(n-k)+\sum_{m=0}^{M}b_m\,x(n-m)\ in hardware? With four blocks:
| block | input | output |
|---|---|---|
| sum | x(n), y(n) | x(n)+y(n) |
| product with a constant a | x(n) | a\cdot x(n) |
| delay z^{-1} | x(n) | x(n-1) |
| filter H(z) | x(n) | x*h(n) |
In the diagrams that follow, an arrow labelled with a coefficient is a product, a z^{-1} on an arrow is a delay, and arrows that meet are summed.
In the direct form I, the feedforward part (MA, B(z)) and the feedback part (AR, 1/A(z)) are separate blocks, in series.
It needs M+N delays.
Direct form II. Swap the two blocks: \frac{1}{A(z)} first, then B(z). Both now delay the same signal w(n), so the two delay chains merge into one.
Direct form II transposed. Reverse every arrow, and swap input and output: the transfer function does not change.
Both need only \max(M,N) delays.
The inverse problem: given a network, find its transfer function. Name the signal at the output of every sum, w_0(n),\dots,w_4(n), write one equation per node, and take the Z-transform. In the example of the lecture:
\begin{cases}w_0(n)=x_1(n)\\w_1(n)=x_1(n-1)+2w_4(n)\\w_2(n)=3w_4(n)\\w_3(n)=x_1(n)+2w_1(n)+w_2(n-1)\\w_4(n)=w_3(n-1)\end{cases}\ \xrightarrow{\ \mathcal{Z}\ }\ \begin{cases}W_0(z)=X_1(z)\\W_1(z)=z^{-1}X_1(z)+2W_4(z)\\W_2(z)=3W_4(z)\\W_3(z)=X_1(z)+2W_1(z)+z^{-1}W_2(z)\\W_4(z)=z^{-1}W_3(z)\end{cases}
In matrix form, with the output a combination of the nodes:
\begin{cases}\mathbf{W}=\mathbf{F}\mathbf{W}+\mathbf{A}X\\Y=\mathbf{B}\mathbf{W}\end{cases}\ \Longrightarrow\ \begin{cases}\mathbf{W}=(\mathbf{I}-\mathbf{F})^{-1}\mathbf{A}X\\Y=\mathbf{B}(\mathbf{I}-\mathbf{F})^{-1}\mathbf{A}X\end{cases}\ \Longrightarrow\ H(z)=\mathbf{B}(\mathbf{I}-\mathbf{F})^{-1}\mathbf{A}
a. h(n)=\frac18 for n=0,\dots,7, and 0 elsewhere. b. \tilde H(0)=\sum_mb_m=8\cdot\frac18=1.
c. A geometric series:
H(z)=\frac18\sum_{m=0}^{7}z^{-m}=\frac18\cdot\frac{1-z^{-8}}{1-z^{-1}}
The zeros are the 8th roots of unity, z_k=e^{j\frac{2\pi}{8}k}, except z=1, cancelled by the denominator: 7 zeros on the unit circle, and 7 poles at z=0.
d. |\tilde H(f)|=\dfrac18\left|\dfrac{\sin(8\pi f)}{\sin(\pi f)}\right|: 1 at f=0, zero at f=\frac k8. A low-pass filter, and not a sharp one.
H(z)=\dfrac{1}{1-\alpha^2z^{-2}}: poles at \pm\alpha, a double zero at z=0. a. Causal and stable if |\alpha|<1.
c. |\tilde H(f)|=\dfrac{1}{\sqrt{1+\alpha^4-2\alpha^2\cos(4\pi f)}}: from \frac{1}{1+\alpha^2} at f=\frac14,\frac34 to \frac{1}{1-\alpha^2} at f=0,\frac12. Flat for \alpha=0, peaks that grow without bound as |\alpha|\to1.
d. Partial fractions, H(z)=\frac{1/2}{1-\alpha z^{-1}}+\frac{1/2}{1+\alpha z^{-1}}, |z|>|\alpha|:
h(n)=\frac{\alpha^n+(-\alpha)^n}{2}\,1_0(n)=\begin{cases}\alpha^n&n\ge0\text{ even}\\0&\text{otherwise}\end{cases}
a. With \tau=NT a whole number of sampling periods, N=\tau F_s: \ y_s(n)=\alpha\,y_s(n-N)+x_s(n) and
H(z)=\frac{1}{1-\alpha z^{-N}}
b. z^N=\alpha: for 0<\alpha<1, N poles equally spaced on a circle of radius \alpha^{1/N}, z_i=\alpha^{1/N}e^{j\frac{2\pi}{N}i}, and N zeros at z=0.
c. |\tilde H(f)|=\dfrac{1}{\sqrt{1+\alpha^2-2\alpha\cos(2\pi fN)}}: a comb, with peaks \frac{1}{1-\alpha} at f=\frac kN and dips \frac{1}{1+\alpha} halfway between. The echo reinforces the frequencies whose period fits the delay. (Item d, a Matlab task, has no surviving solution.)
Write a Matlab function to filter a recorded voice. The voice, sampled at 8192 Hz, is distorted by a harmonic component at f_0=1 kHz. The function is
function y = Filter_Harmonic(x, Fs, f0, type)
where x is the distorted voice, Fs the sampling frequency, f0 the frequency of the disturbance, type either 'FIR' (finite impulse response) or 'IIR' (infinite impulse response), and y the filtered, clean voice.
For both the FIR and the IIR implementation:
What are the main differences between the two approaches?
f_0 = 1000;
T = 1/Fs;
% ...
harm = V_0*cos(2*pi*f_0*T.*k+phi); % V_0 = 0.2, phi = pi/15
y_d = y+harm;
% ...
b = [1 -2*cos(2*pi*f_0*T) 1];
a = [1 0 0];
zplane(b,a)
f = 0:T:1;
w = 2*pi*f;
figure
[H_FIR,~] = freqz(b,a,w);
plot(w,abs(H_FIR))
% ...
b = [1 -2*cos(2*pi*f_0*T) 1];
a = [1 -1.98*cos(2*pi*f_0*T) 0.99^2];
zplane(b,a)
% ...
error_FIR = norm(y_FIR-y);
error_IIR = norm(y_IIR-y);With \theta_0=2\pi\frac{f_0}{F_s}\approx0.767 rad, both filters put two zeros on the unit circle at e^{\pm j\theta_0}:
The code is mine; the comparison is added for the web version. No saved run survives: expect a smaller error for the IIR filter. The FIR gain is not normalised to 1 at DC, and the second zplane draws over the FIR magnitude.
letizia.tech · Digital Signal Processing · University of Klagenfurt