The Z Transform, The DTFT, and Digital Filters: Signals and Systems Laboratory 9
The Z Transform, The DTFT, and Digital Filters: Signals and Systems Laboratory 9
The Z transform pairs that one encounters when solving difference equations involve discrete-time signals, which are
geometric (or exponential) in the time domain and rational in the frequency domain. MATLAB provides tools for
dealing with this class of signals. Our goals in this lab are to
ii. experiment with the properties of the Z transform and the Discrete Time Fourier Transform
iii. develop some familiarity with filters, including the classical Butterworth and Chebychev lowpass and
bandpass filters, all-pass filters, and comb filters.
The Z transform provides a frequency domain version of a discrete-time signal. Discrete time signals are sequences,
and the Z transform is defined by
∞
(1) h[k ] Z transform
← → H ( z) = ∑ h[k ]z
k = −∞
−k
.
Z 1
(2) h[k ] = a k u[k ] ←→ H ( z) =
1 − az −1
where u[k] is the unit step function. The time domain sequence h[k] and the frequency function H(z) are alternate ways
of describing the same signal. In the time domain, h[k] is exponential. In the frequency domain, is rational or, by
definition, the ratio of two polynomials. For discrete-time applications, we will use the representation
B( z )
(3) H ( z ) = zυ ,
A( z )
where B ( z ) = b[0] + b[1]z −1 + K + b[m]z − m , A( z ) = 1 + a[1]z −1 + a[2]z −2 + K + a[n]z − n , and υ is an integer. This
numbering of the coefficients is not standard for MATLAB, if we are talking about polynomials, but it is consistent
with the way the row vectors a and b are used in the filter function. The indices will be off by one, of course. The
representation is unique if we demand that the end coefficients b[0], b[m], and a[n] are not zero.
The poles of H(z) are the roots of the denominator polynomial A(z). At a pole, H(z) becomes infinite. The zeros of H(z)
are the roots of the numerator polynomial B(z). At a zero, H(z) is zero. A pole-zero plot of H(z) simply places the poles
(using the symbol ‘x’) and the zeros (using the symbol ‘o’) on the complex plane. For stability, it is necessary that the
poles of H(z) be inside the unit disk, or in other words have absolute value less than one. The complex frequency
jθ
response is computed by evaluating H(z) on the unit circle z = e , 0 ≤ θ < 2π .
This class of signals is most appropriate for discrete time linear filters. All filters which can be updated with a finite
number of multiplications and additions per output sample will be in this class. In other words, these are the only
filters that can be realized by DSP processors. The choice of the letter ‘h’ for the above signal is commonly used for
filters. In the time domain, h[k] is the unit pulse response sequence of the filter. In the frequency domain, H(z) is the
jθ jθ
transfer function of the filter. If we set z = e , then we get the complex frequency response function H (e ) . In fact,
jθ
with z = e , the Z transform becomes the DTFT, or Discrete Time Fourier Transform:
Page 1 of 9
∞
(4) h[k ] DTFT
← → H ( e jθ ) = ∑ h[k ]e
−∞
− jkθ
.
π
dθ
∫π H (e
jθ
(5) h[k ] = ) e jkθ .
2π
−
But there are conditions. The example in equation (2) will be consistent with equation (5) if and only if | a| < 1. Just as
there was in the Laplace Transform, there will be a Region of Convergence, or ROC, and the choice of inversion must
be consistent with the ROC. There are two important cases:
Region of Convergence
Application Condition on h
Causal sequences h[k ] = 0, for k < 0 z > max of the set of pole radii
Anti-Causal sequences h[k ] = 0, for k < 0 z < min of the set of pole radii
∞
∑ h[k ]
2
Finite Energy sequences <∞ 1− ε < z < 1+ ε
−∞
The first case is the one to respect when you are solving initial value problems, or difference equations for causal
systems, like sampled data control systems and real-time digital filters. The second case is used when designing
matched filters H(−z) or factoring spectral polynomials as S(z) = H(z)H(−z). The third case is the one to use when the
application need not be causal, but must involve a bounded sequence. Such problems are common in communication
systems. This is the case that one must assume when the discrete time Fourier transform is computed. In the causal
case, poles outside the unit circle, i.e. with absolute values greater than one, mean that the system is unstable. In this
case the sequence h[k] will be unbounded, and the response to a unit pulse will explode. In the finite energy case, poles
outside the unit circle mean only that the inverse transform h[k] will not be causal, but it will be bounded. There will
be no difference between these two cases if all the poles of H(z) are inside the unit circle. Then h[k] will be both
bounded and causal.
Laplace transforms use the s-plane, and frequency response is computed on the imaginary axis s = jω . The
jθ
Z transform uses the z-plane, and the frequency response is computed on the unit circle z = e . How do these
differences come about? The Laplace transform is appropriate for continuous-time systems, while the Z transform is
appropriate for discrete-time systems. In control system applications, discrete time systems are called sampled-data
systems. In signal processing applications, they are called digital filters or digital signal processors. Suppose that we
start with continuous time signals, and sample them to get discrete time signals. Let the sampling frequency be f s ,
and the sampling period be t s = 1 / f s = 2π / ω s . Consider a signal x(t ) with Laplace transform
∫ x(t )e
− st
(6) X ( s) = dt ,
−∞
and let y[k ] = x(kt s ) be the discrete time signal obtained by sampling x(t ) . The Z Transform of the sequence of
samples is
Page 2 of 9
∞
(7) Y ( z) = ∑ y[k ]z
k = −∞
−k
.
(8) z = e sts .
This relation maps the s plane into the z plane. It is important to understand this mapping if we want to think about
using digital signal processing to approximate continuous time signal processing. The following table summarizes the
key observations.
∞ ∞ ∞
(9) t s Y (e sts ) = t s ∑
k = −∞
y[k ]z − k = ∑
k = −∞
x(kt s )e − skts t s ≈ ∫ x(t )e
− st
dt = X ( s ) .
−∞
Therefore the Z transform of y[k] can approximate the Laplace Transform of x(t), and the DTFT of y[k] can
approximate the Fourier Transform of x(t), as in the following table:
st
provided z = e s ,
Laplace Transform / Z Transform X (s) ≈ t sY ( z )
and imag( s ) < ω s / 2
provided θ = ω t s = 2πω / ω s
Fourier Transform / DTFT jθ
X ( jω ) ≈ t s Y (e ) and ω < ω s / 2 , or θ < π
jθ
The approximation has its limits, because going around the unit circle is a periodic motion. The DTFT Y (e ) is 2π
periodic in θ = ω t s = 2πω / ω s and the approximation to X ( jω ) is therefore periodic with period ω s . Because of
symmetry about zero, this means that the approximation is good only to the half sampling frequency ω s / 2 . In digital
signal processing, bandwidth is limited. For greater bandwidth, one must sample faster. One should always be aware
of this. It is one of the two fundamental limitations, the other being finite word length effects.
jθ
There is a precise formula which relates Y (e ) and X ( jω ) , when y[k ] = x(kt s ) , as opposed to the approximation
that we have already mentioned. Whenever one samples in the time domain, then there will be aliasing in the
frequency domain. The formula is this:
Page 3 of 9
∞
1
(10) y[k ] = x (kt s ) DTFT
← → Y ( e jω t s ) =
ts ∑ X ( j(ω − nω )) .
n = −∞
s
When X ( jω ) is bandlimited to ω < ω s / 2 , the formula X ( jω ) = t s ⋅ Y (e jω ⋅ts ) will hold exactly for ω < ω s / 2 .
(This is the sampling theorem. We will study this in more depth in the next lab.)
Using the ‘help’ command, investigate the MATLAB standard functions: ‘residue’, ‘conv’, ‘filter’, ‘impz’, ‘freqz’,
and ‘invztrans’. Then look at the homebrew functions ‘plotZTP.m’, ‘z_rev.m’, and ‘z_mult.m’ located on the web
page under ‘Functions for Lab 9’. The MATLAB tool ‘freqz’ is very handy, but we will use ‘plotZTP.m’ to gain the
same information, and more! (NB: The ‘plotZTP.m’ requires two other homebrew functions, ‘gpfx.m’, ‘pzd.m’)
If B(z) has degree equal to that of A(z), and if A(z) does not have repeated roots, then the Z transform pair for
H(z)=B(z)/A(z) is
n n
γ [m]
n
γ [ m]
(11) ∑
h[k ] = b[0]δ [k ] + γ [m]α [m] k −1 u[k − 1] ←→
m=1
Z
H ( z ) = b[0] +
m =1
∑
z − α [ m]
= b[0] + z −1 ∑
m =1 1 − α [ m] z
−1 .
The right hand side of the above is a partial fraction expansion, of H (z ) . Under the conditions specified, the
parameters b[0], γ [1], γ [2]..., γ [m],α [1], α [2],...,α [m] can be computed using the MATLAB tool ‘residue’. For
example
From this you can write down the partial fraction expansion for H(z). Do It.
Page 4 of 9
Simulating Digital Filters
The function ‘conv’ does sequence convolution. The MATLAB function ‘filter’ will approximate the convolution
action of the discrete-time filter H(z). The input parameters are the row vectors ‘b’ and ‘a’ which parameterize H(z),
and the long row vector x which represents the input. The output is a row vector ‘y’ whose size is the same as that of
‘x’. Suppose that h[k] is causal, and has a Z transform H(z) given by equation (3), with υ equal to zero. Suppose that
the input sequence x[k] is also causal. Then the output sequence y[k] will also be causal and will satisfy the difference
equation
n m n m
(12) a ∗ y = b ∗ x , or ∑
i =0
a[i]y[k − i ] = ∑ b[i]x[k − i] , or y[k ] = −∑ a[i] y[k − i] + ∑ b[i]x[k − i]
i =0 i =1 i =0
The solution to this difference equation is the convolution of the input sequence and the pulse response sequence:
k n m
(13) y = h ∗ x , or y[k ] = ∑ h[i]x[k − i] , where ∑ a[i]h[k − i] = ∑ b[i]δ [k − i]
i =0 i =0 i =0
The MATLAB function ‘filter’ follows equation (12), while the MATLAB function ‘conv’ follows equation (13).
There is a difference in the tails however. The length of the sequence filter(b,a,x) will be the same as the sequence ‘x’.
The length of the sequence conv(h,x) will be the sum of the lengths of ‘h’ and ‘x’ minus one. Try this:
The two graphs should agree for k=1 to 51, but the lower one will have more values. These extra values will not be
correct, however, because the pulse response is good only out to k=50.
The following function will make a plot with four parts, a pole-zero diagram, a graph of h[k] from -tmax to tmax, and
jθ
graphs of the magnitude and phase of the complex frequency response function H (e ) . It uses the representation of
equation (5), and will assume that the sequence h[k] is bounded. It will therefore plot non-causal sequences when
necessary. An example of the output is given in Figure One for the third order Butterworth digital filter constructed
previously. The frequency response plots use a normalized frequency, so that the maximum of 1 corresponds to the
half sampling frequency f s / 2 , or θ = π . Notice that the time domain signal is plotted using the MATLAB function
‘stem’ to emphasize its discrete nature. The command used is »plotZTP(b,a,0,30). Type
»help plotZTP
plotZTP(b,a,nu,tmax)
Display Z transform pairs: plot
(1) pole zero diagram,
(2) frequency response
(3) pulse response on [-tmax,tmax]
h(k) <--> H(z)=(z^nu)*B(z)/A(z),
B(z)=b0+b1*z^(-1)+...+bm*z^(-m), etc.
b=[b0,b1,...,bm],a=[1,a1,a2,...,an]
b0,bm,an should all be nonzero
This function requires two other
homebrew functions, 'gpfx.m' and 'pzd.m'
Page 5 of 9
This is what you see:
0.8
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1
0.5
-0.5
-1
0 0.2 0.4 0.6 0.8 1 7
The following table contains Z transform properties that can be exploited with profit.
∞
convolution-multiplication y[k ] = ∑ h[i]x[k − i]
i = −∞
Y ( z) = H ( z) X ( z)
x[k ], if k is even 1
decimation by two y[k ] = Y ( z) = [X ( z ) + X ( − z )]
0, if k is odd 2
Page 6 of 9
Assignment:
For this assignment, you will need the following homebrew functions: ‘plotZTP.m’, ‘gpfx.m’, ‘pzd.m’,
‘zmodu.m’, ‘zmult.m’, and ‘z_rev.m’. These are located on the web page under ‘Functions for Lab 9’. The rest
of the functions will either be built-in MATLAB functions, or functions that you create.
1. Multiplication-Convolution
Construct two Z transform parameterizations, corresponding to Butterworth lowpass and bandpass filters as
follows:
»[bh,ah]=butter(4,.6);
»[bx,ax]=butter(4,.4,’high’);
Examine each of these signals using ‘plotZTP.m’ and print the results. (Use zero for the ‘nu’ parameter.) Then
construct pulse response sequences for each and the convolution of the two and display them as follows:
»x=filter(bx,ax,[1,zeros(1,20)]);
»h=filter(bh,ah,[1,zeros(1,20)]);
»figure(1),subplot(3,1,1),stem(x)
»subplot(3,1,2),stem(h)
»y=conv(h,x);
»subplot(3,1,3),stem(y)
Now, using the tool for multiplying Z transforms, construct the Z transform representation of y via
»[by,ay,ny]=z_mult(bx,ax,0,bh,ah,0);
»figure(2),plotZTP(by,ay,ny,40)
The time domain panel should be the same as the previous graph of y.
2. Time Shifts
Produce two plots using »plotZTP(bh,ah,nu,30) with the shift parameter ‘nu’ equal to 5 and then −5 .
Comment on the resulting graphs. Are there changes in the magnitude plot? The phase plot? The time plot?
Explain any changes.
3. Modulation
»hb=ones(1,20);ha=1;figure(1),plotZTP(hb,ha,0,20)
»[gb,ga,gn]=z_modu(hb,ha,0,.2);figure(2),plotZTP(gb,ga,gn,20)
Page 7 of 9
Assignment:
4. Time reversal
−1 −1
Construct H (z ) and make plots of H (z ) , H ( z ) and H ( z ) ⋅ H ( z ) , as follows:
»hb=ones(1,10);ha=[1,zeros(1,9),0.5];figure(1),plotZTP(hb,ha,0,50)
»[hb1,ha1,hn1]=z_rev(hb,ha,0);
»figure(2),plotZTP(hb1,ha1,hn1,50)
»[hha,hhb,hhn]=z_mult(hb,ha,0,hb1,ha1,hn1);
»figure(3),plotZTP(hha,hhb,hhn,50)
−1
Compare all plots for H ( z ) with those of H (z ) , Explain the differences. Then comment on all four parts
−1
of the plots for H ( z ) ⋅ H ( z ) , relating them to the same graphs for H (z ) . Why does the phase trivialize?
−1
Note that the magnitude of H ( z ) ⋅ H ( z ) is the square of the magnitude of H (z ) .
5. Decimation by Two
Study the code for the tools ‘z_rev.m’ and ‘z_modu.m’. Then write a tool to do decimation and produce
1
G ( z ) = [H ( z ) + H (− z )] from H (z ) . Your specifications should read
2
% [gb,ga,gn]=z_down(hb,ha,hn)
% G(z)=.5*[H(z)+H(-z)]
(The job can be done with five lines, having one statement per line.) Test your tool as follows:
»[gb,ga,gn]=z_down(hb,ha,0);figure(2),plotZTP(gb,ga,gn,40)
The sequence g[k] should agree with the sequence h[k] for even indices, but be zero for odd indices. The
poles of G(z) should consist of the poles of H(z), and the negatives of the poles of H(z). But don’t expect the
zeros to behave the same way. Provide printouts of the plot of G(z) and the code for ‘z_down.m’.
(Note: if you use H(z) from part (4), there will be some pole-zero cancellation.)
There are ways of choosing the poles and zeros of a filter H(z) so that it acts as a lowpass or bandpass filter.
A few classical filter designs are used extensively, including Butterworth and Chebychev filters. Butterworth
was an English electrical engineer and Pafnuti L. Tchebycheff (1821-1894) was a professor of Mathematics
at the University of Petrograd. Use the MATLAB ‘help’ command to investigate the functions ‘butter’,
‘cheby1’, and ‘cheby2’. Then do several repetitions of the commands
»n=3;beta=.5;[b,a]=butter(n,beta);plotZTP(b,a,0,30)
except vary the filter order ‘n’ and normalized cutoff frequency ‘beta’ ( β = 2 f c / f s ). Then experimentally
determine an approximate formula for
Page 8 of 9
Assignment:
7. All-pass filters
Let A( z ) = 1 + a[1]z −1 + a[2]z −2 + K + a[n]z − n be any polynomial whose roots are all inside the unit circle.
Let B ( z ) = z − n A( z −1 ) = a[n] + a[n − 1]z −1 + a[n − 2]z −2 + K + z − n . The coefficients of B(z ) are the same as
those of A(z ) , except in the reverse order. Now let H ( z ) = B ( z ) / A( z ) . This filter will be an all-pass filter.
Do this and print the resulting graphs:
»[b,a]=butter(5,.2);b=flipud(a’)’;plotZTP(b,a,0,40)
All-pass filters have nontrivial phase but trivial magnitude. Although it might seem that they are not
particularly useful, they have a great many uses. For example, all Butterworth filters can be expressed as one
half the sum of two all-pass filters.
8. Comb filters
Let A( z ) = 1 + a[n]z − n be a polynomial whose interior coefficients are all zero. The filter H ( z ) = b[0] / A( z )
will have special properties. Do this:
»a=[1 0 0 0 0 0 0 0 0 0 .7];
»plotZTP(a,1,0,100)
»plotZTP(1,a,0,100)
You will see why one of these filters is called a notch filter and the other a comb filter when you see the
magnitude plots. Print the resulting graphs. Show mathematically why the following are true:
1/ n
i. The roots of A(z ) will be equally spaced around a circle of radius a[n] .
ii. The pulse response sequence h[k] will be zero unless k is a multiple of n.
jθ
iii. The magnitude H (e ) is a periodic function in θ, with period 2π / n .
9. We have seen in Lab 4 in EE311 that MATLAB treats the vector a = [a[1] + a[2] + K a[n + 1]] as code for the
polynomial A( s ) = a[1]s n + a[2]s n−1 + K + a[n + 1] . But in digital filtering we want this to code
A( z ) = a[1] + a[2]z −1 + K a[n + 1]z − n . Why does this make no difference when computing poles and zeros,
complex frequency responses, and so on?
Page 9 of 9