Lab 3: Difference Equations, Z-Transform, Pole-Zero Diagrams, BIBO Stability and Quantization Effects
Lab 3: Difference Equations, Z-Transform, Pole-Zero Diagrams, BIBO Stability and Quantization Effects
0.1 Overview
In this laboratory we solve difference-equations, analyze the stability of LSI systems in terms of the
pole-zero location of their transfer function, and study the effects of quantization on different filter
structures.
0.2 Z transform
X(z) is a generalization of the discrete-time Fourier transform that is useful for studying discrete-time
signals and systems. Note that if z = ejω , the z-transform reduces to the discrete-time Fourier transform.
However, the bilateral z-transform exists for a broader class of signals than the discrete-time Fourier
transform does, and is useful for understanding the behavior of both stable and unstable systems. For a
large class of signals, the z-transform can be represented as a ratio of polynomials in z, i.e.,
N (z)
X(z) =
D(z)
These transforms are called rational transforms and arise as the system functions of LTI systems which
satisfy linear constant-coefficient difference equations. The locations of the roots N (z) and D(z), known
as the zeros and poles of the system, respectively, determine to within a constant multiplicative factor
the behavior of LTI systems with rational transforms. Therefore, plots of the pole and zero locations can
be used to analyze system properties.
The poles and zeros of rational system function can be computed using the function roots. The
function roots requires the coefficient vector to be in descending order of the independent variable. For
example, consider the LTI system with system function,
z2 − z
H(z) =
z 2 + 3z + 2
The poles and zeros can be computed by executing
>> b = [1 -1 0]
>> a = [1 3 2]
>> zs = roots(b)
>> zs =
0
1
>> ps = roots(a)
ps =
-2
-1
It is often desirable to write discrete-time system functions in terms of increasing order of z −1 . The coef-
ficients of these polynomials are easily obtained from the linear constant coefficient difference equation
and are also in the form that filter requires. However, if the numerator and denominator do not have
same order, some poles or zeros at z = 0 may be overlooked.
The previous example can be rewritten as :
1 − z −1
H(z) =
1 + 3z −1 + 2z −2
Now, if we use the roots command we will get :
>> b = [1 -1]
>> a = [1 3 2]
>> zs = roots(b)
>> zs =
1
>> ps = roots(a)
ps =
-2
-1
Note that z = 0 does not appear here. In order to find the complete set of poles and zeros when working
with a system function in terms of z −1 , you must append zeros to the coefficient vector for the lower
order polynomial such that the coefficient vectors are the same length.
The function dpzplot(a,b) plots the poles and zeros of discrete-time systems.
function dpzplot(b,a)
%dpzplot(b,a)
%plots the pole-zero diagram for the discrete-time system function
%H(z)=b(z)/a(z) defined by numerator and denominator polynomials b and a.
la = length(a);
lb = length(b);
if(la>lb)
b = [b zeros(1,la-lb)];
elseif (lb > la)
a = [a zeros(1,lb-la)];
end
ps = roots(a);
zs = roots(b);
mx = max(abs([ps’ zs’ 0.95])) + 0.5;
clf
axis([-mx mx -mx mx]);
axis(’equal’);
hold on
w = [0 : 0.01:2*pi];
plot(cos(w),sin(w),’.’);
plot([-mx mx],[0 0 ]);
plot([0 0], [-mx mx]);
text(0.1,1.1,’Im’,’sc’);
text(1.1,0.1,’Re’,’sc’);
plot(real(ps),imag(ps),’x’);
plot(real(zs),imag(zs),’o’);
numz=sum(abs(zs)==0);
nump=sum(abs(ps)==0);
if numz > 1
text(-0.1,-0.1,num2str(numz));
elseif nump>1
text(-0.1,-0.1,num2str(nump));
end
holdoff
A causal LTI system is one whose unit impluse response h[n] satisfies the condition :
h[n] = 0, n < 0.
Also, we know that the ROC of the z-transform of a causal sequence is the exterior of a circle. Conse-
quently, an LTI system is causal if and only if the ROC of the system function is the exterior of a circle or
radius r < ∞ including the point z = ∞. The stability of an LTI system can also be expressed in terms
of the characteristics of the system function. The necessary and sufficient condition for a LTI system to
be BIBO stable is :
+∞
X
|h[n]| < ∞.
n=−∞
This condition implies that H(z) must contain the unit circle. Hence if the system is BIBO stable, the unit
circle is contained in the ROC of H(z). The converse is also true. Therefore, an LTI system is BIBO stable
if and only if the ROC of the system function includes the unit circle. Note that ROC cannot contain any
poles of H(z) and if we also consider the ROC of a causal system then it follows that a causal LTI system
is BIBO stable if and only if all the poles are inside the unit circle.
0.4 Quantization
We have assumed so far that we are dealing with discrete-time systems characterized by linear diffe-
rence equations with constant coefficients where both the coefficients and signal variables have infinite
precision. However, if we consider the implementation (computer or special purpose hardware), the
system parameters along with the signal variables (to be stored) can only take discrete values within
specified range since the registers (of processors in question) present a finite length.
The function ellip can be used to design a discrete-time elliptic filter. Elliptic frequency selective filters
have a frequency response magnitude which is equiripple in the pass-band, i.e., the frequency response
magnitude oscillates between 1 ± δ1 in the pass-band and between δ2 in the stop band. Consider an 8-th
order elliptic filter returned by the call of the following function :
>>[b,a] = ellip(4,0.2,40,[0.41 0.47]);
This filter has 0.2 dB ripple in pass-band, 0.41π ≤ |ω| ≤ 0.47π and has 40 dB attenuation in the stopband.
When discrete-time filters are implemented with quantized coefficients the resulting systems are called
digital filters. Digital filters are generally implemented using fixed-point arithmetic on integer digital
signal processing (DSP) chips. The coefficients of digital filter must be quantized to the number of bits
available on the DSP chip. The function quant below will quantize the coefficients in the vector x to N
bits, where M is the maximum possible amplitude of each element.
function qc = quant(x,N,M)
% QUANT Q = QUANT(x,N,M) quantizes the values of x(n) into
% 2^N values. The argument M is the value of the
% maximum amplitude of x[n]
[mm, nn] = size(x);
qc = zeros(mm,nn);
levels = 2^(N-1);
maxlevel = 2^(N)-1;
for k=1:mm
tmp = fix((x(k,:)+M)./(M/levels));
q = zeros(1,nn);
q(tmp <= maxlevel) = tmp(tmp <= maxlevel);
q(tmp > maxlevel) = maxlevel * ones(1,length(tmp(tmp>maxlevel)));
q(tmp < 0) = zeros(size(tmp(tmp < 0)));
q = (q- levels)*M/levels;
qc(k,:)=q;
end
Coefficient quantization can have an impact on the frequency response magnitude of the elliptic filter.
In problems 4 and 5 we will look at two different implementations (Direct Form II and Cascade form)
of filters and study the effects of quantization on these implementations. Note : the function filter in
MATLAB uses direct form structure.
where x[n] is the system input and y[n] is the system output. The vectors a and b contain the
coefficients ak such thatand bm such that :
K
X M
X
a[k + 1]y[n − k] = b[m + 1]x[n − m],
k=0 m=0
(a) Define coefficient vectors a and b to describe the causal LTI system described by :
y[n] = 0.5x[n] + x[n − 1] + 2x[n − 2]
(b) Define coefficient vectors a and b to describe the causal LTI system described by :
y[n] = 0.8y[n − 1] + 2x[n]
(c) Define coefficient vectors a and b to describe the causal LTI system described by :
y[n] − 0.8y[n − 1] = 2x[n − 1]
For each of these systems use the filter command to compute the response y[n] for the input
signal x[n] = u[n], 0 ≤ n ≤ 3. Also, plot the response for each of the above cases.
2. Consider the following difference equation :
y[n] = ay[n − 1] + x[n]
(a) Write a function y=diffeqn(a,x,yn1) which computes the output y[n] of the causal system
determined by the given equation. The input vector x contains x[n] for 0 ≤ n ≤ N − 1 and yn1
supplies the values of y[−1]. The output vector y contains y[n] for 0 ≤ n ≤ N − 1. The first line
of your M-file should read,
function y = diffeqn(a,x,yn1)
(b) Assume a = 1, y[−1] = 0, and that we are only interested in the output over the interval
0 ≤ n ≤ 30. Use your function to compute the response due to x1 [n] = u[n] and x2 [n] = u[n],
the unit impulse and unit step, respectively. Plot each response using stem.
(c) Assume again that a = 1, but that y[−1] = −1. Use your function to compute y[n] over 0 ≤
n ≤ 30 when the inputs are x1 [n] = u[n] and x2 [n] = 2u[n]. Define the outputs produced by the
two signals to be y1 [n] and y2 [n], respectively. Use stem to plot (2y1 [n] − y2 [n]). Given that the
equation is a linear difference equation, why isn’t this difference identically zero ?
(d) When is the causal system described by the given difference equation BIBO stable ? Assume
a = 1/2 and that x contains x[n] = u[n] for 0 ≤ n ≤ 30. Assuming both y[−1] = 0 and
y[−1] = 1/2, compute the two output signals y[n] for 0 ≤ n ≤ 30. Use stem to display both
responses. How do they differ ?
3. In this problem we will use dpzplot function to plot the poles and zeros of some rational functions.
(a) Use dpzplot to plot the poles and zeros for,
z2 − z
H(z) =
z 2 + 3z + 2
(b) Use dpzplot to plot the poles and zeros which satisfy the following difference equation
(c) Use dpzplot to plot the poles and zeros which satisfy the following difference equation
y[n] − 1.25y[n − 1] + 0.75y[n − 2] − 0.125y[n − 3] = x[n] + 0.5x[n − 1]
4. In this problem we will examine the effect of coefficient quantization on different filter structures.
Consider the 8-th order elliptic filter. Store in the vectors a and b the coefficients for this bandpass
filter. Use [H,w] = freqz(b,a,4096) to compute 4096 samples of the frequency response of the
filter for 0 ≤ ω ≤ π. Plot the log magnitude in decibels (dB) of H versus w/pi by executing :
>> plot(w/pi,20*log10(abs(H)));
>> axis([0 1 -80 10]);
Use axis to zoom in on the passband.
(a) Use filter to compute 4096 samples of the impulse response of the filter and store the result in
the vector h. Plot the first 200 samples of the impulse response.
(b) Set M=max(abs([b a])) and use quant to quantize the coefficients in b and a to 16 bits and
store the results in a16 and b16. What is the maximum amount any of the coefficients is chan-
ged by quantization ? Use freqz to plot the frequency response magnitude of the quantized
filter. Do you see any difference ?
(c) Use the function dpzlot to generate a pole-zero plot for the filter described by the coefficients
a16 and b16.
(d) Repeat parts (a) and (b) quantizing a and b to 12 bits and store the results in a12 and b12.
Based on the pole-zero plots is the frequency response you have plotted both causal and stable ?
Explain the reason.
(e) Use filter to compute 4096 samples of the impulse response of the filter described by a12 and
b12. Is the filter impulse response you have plotted stable ? Explain the reason.