0% found this document useful (0 votes)
51 views

SNS Lab14

This document provides instructions for Lab #14 which explores computing the z-transform and discrete-time convolution using MATLAB. It covers finding the z-transform and inverse z-transform of signals using the ztrans and iztrans commands. Other topics covered include partial fraction decomposition using residue, plotting pole-zero locations with zplane, computing the frequency response with freqz and fvtool, and performing discrete-time convolution using conv, filter, and impz. Examples are provided for each MATLAB command and comparisons are made between computing the impulse response and filtering with different inputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

SNS Lab14

This document provides instructions for Lab #14 which explores computing the z-transform and discrete-time convolution using MATLAB. It covers finding the z-transform and inverse z-transform of signals using the ztrans and iztrans commands. Other topics covered include partial fraction decomposition using residue, plotting pole-zero locations with zplane, computing the frequency response with freqz and fvtool, and performing discrete-time convolution using conv, filter, and impz. Examples are provided for each MATLAB command and comparisons are made between computing the impulse response and filtering with different inputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Signals and Systems

(EE-223)

LABORATORY MANUAL
Spring 2019

Dr. Shahzad Saleem


Engr. Fakhar Abbas

LAB # 14
COMPUTING Z-TRANSFORM AND DISCRETE-TIME CONVOLUTION
USING MATLAB

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES, ISLAMABAD

Prepared by: Engr. Fakhar Abbas Version: 1.00

Dr. Waqas Bin Abbas, Dr. Shahzad


Verified by: Saleem Updated: Spring 2020

1
Lab # 14: COMPUTING Z-TRANSFORM AND DISCRETE-TIME
CONVOLUTION USING MATLAB
Objective: In this lab, you will learn and explore:
 Finding z-transform and inverse z-transform
o ztrans and iztrans command
 Partial fraction decomposition of a discrete-time transfer function using residue command
 zplane command for pole zero plot
 Finding frequency response of a discrete-time system using freqz command
o fvtool (num,den) command
 Computing discrete-time convolution
o conv (), filter() and impz () commands

Tools Used: MATLAB 2018b

Description:

z-Transform

In mathematics and signal processing, the z-transform converts a discrete-time signal, which is
a sequence of real or complex samples, into a complex frequency-domain representation. It is defined
as follows:

Unilateral Z-Transform:

In cases where 𝑥[𝑛] is defined only for n greater than or equal to zero, the single-sided or unilateral z-
transform is defined as

z-Transform in MATLAB
ztrans:
ztrans(f,n,z) computes the Z transform of the expression 𝑓 = 𝑓(𝑛) with respect to the index 𝑛 at the
point 𝑧.
Examples:
Code:

syms n
f = sin(n)
ztrans(f)

ans = (z*sin(1))/(z^2 - 2*cos(1)*z + 1)

2
MATLAB Command:
iztrans:
iztrans(f,z,n) computes the inverse z-transform of the expression 𝐹 = 𝐹(𝑧) with respect to the
variable 𝑧 at the point 𝑛.
Example 1:
Code:

syms z
F = (z*sin(1))/(z^2 - 2*cos(1)*z + 1)
iztrans(F)

ans = sin(n)

residue command in MATLAB:


[r,p,k] = residue(b,a) finds the residues, poles, and direct term (k) of a partial fraction expansion of the
ratio of two polynomials (discrete-time transfer function), where the expansion is of the form

The inputs to residue are vectors of coefficients of the polynomials 𝑏 = [𝑏𝑚 . . . 𝑏1 𝑏0 ] and
𝑎 = [𝑎𝑛 . . . 𝑎1 𝑎0 ]. The outputs are the residues 𝑟 = [𝑟𝑛 . . . 𝑟2 𝑟1], the poles 𝑝 = [𝑝𝑛 . . . 𝑝2 𝑝1 ], and
the constant k. For most textbook problems, 𝑘 is 0 or a constant.

Example 2:
Find the partial fraction expansion of the following transfer function 𝐻(𝑧) using residue
𝐵(𝑧) −4𝑧 + 8
𝐻(𝑧) = = 2
𝐴(𝑧) 𝑧 + 6𝑧 + 8
b = [-4 8];
a = [1 6 8];
[r,p,k] = residue(b,a)

We get following outputs for r, p and k:


r = 2×1

-12
8

p = 2×1

-4
-2

k = []
𝑟
This represents the partial fraction expansion. We can write it in the form of (𝑧−𝑝) as follows:
−4𝑧 + 8 12 8
2
= − +
(𝑧 + 6𝑧 + 8) (𝑧 + 4) (𝑧 + 2)

3
zplane command in MATLAB:

zplane(z,p) plots the zeros specified in column vector z and the poles specified in column vector p in
the current figure window. The symbol 'o' represents a zero and the symbol 'x' represents a pole. The
plot includes the unit circle for reference. If z and p are matrices, then zplane plots the poles and zeros
in the columns of z and p in different colors. zplane(b,a), where b and a are row vectors, first
uses roots to find the zeros and poles of the transfer function represented by the numerator
coefficients b and the denominator coefficients a.

Example 3: Use zplane command to find the pole-zero plot in MATLAB:


1 − 0.75𝑧 −1
𝐻(𝑧) =
(1 + 0𝑧 −1 − 0.25𝑧 −2 )
zplane([1 0.75],[1 0 -0.25])
Following output is displayed by running this command:

Stability of system:
A discrete-time linear time-invariant (LTI) system is said to be stable if all poles lie inside the unit
circle.

freqz command in MATLAB:

freqz(b,a) returns the frequency response using transfer function coefficients b and a.

freqz([1 3/4],[1 0 -1/4])

fvtool Command:
fvtool is a graphical user interface (GUI) that allows you to analyze digital filters.
fvtool(B,A) launches the filter visualization tool and computes the magnitude response for the filter
defined by numerator and denominator coefficients in vectors B and A.
Note: -You can visualize all system plots like magnitude and phase responses, impulse and step
responses, group delay and phase delay plotd, pole zero plot etc.
fvtool([1 3/4],[1 0 -1/4])

Following output is displayed by running this command:

4
impz() Command:-
impz command computes impulse response of digital filter
[h,n] = impz(b,a) computes the impulse response of the filter, where a and b are coefficients of
difference equation, while h and n are outputs of impz(), where h contains the result of impulse
response and n contains the indices.
filter() Command:-
filter() command applies one-dimensional digital filter.
Y = filter(B,A,X) filters the data in vector X with the filter described by vectors A and B to create the
filtered data Y. The filter implements the input signal X using the standard difference equation:
𝑎1 𝑦[𝑛] = 𝑏1 𝑥[𝑛] + 𝑏2 𝑥[𝑛 − 1] + . . . + 𝑏𝑛𝑏+1 𝑥[𝑛 − 𝑛𝑏 ] − 𝑎2 𝑦[𝑛 − 1] − . . . − 𝑎𝑛𝑎+1 𝑦[𝑛 − 𝑛𝑎 ]
If 𝑎1 is not equal to 1, filter normalizes the filter coefficients by 𝑎1
conv() Command:-
conv() command computes the convolution and polynomial multiplication.
C = conv(A, B) convolves vectors A and B. The resulting vector is of length length(A)+length(B)-1. If A
and B are vectors of polynomial coefficients, convolving them is equivalent to multiplying the two
polynomials.
Note:- impz() , filter() and conv() results in the same output only if 𝑥[𝑛] is unit impulse sequence, but
if 𝑥[𝑛] is other than impulse sequence, then impz is used to find impulse response ℎ[𝑛] of the system
while filter(b,a,x) and conv(x,h) perform convolution and the same result. The only difference of
filter() and conv() command is that output of filter has the same number of samples as that of 𝑥[𝑛]
while in conv command output samples are equal to length(x)+length(h)-1.

5
Computing Impulse Response h[n] from a difference equation
Consider following difference equation
𝑦[𝑛] − 0.5 𝑦[𝑛 − 1] = 𝑥[𝑛]
Compute impulse response ℎ[𝑛] of this difference equation on paper and then verify it with following
code.

Your answer of ℎ[𝑛] = ________________________


Example 4 : Computing and Plotting Impulse Response h[n] using Matlab:-
clc;clear all;close all
% Let Difference Equation is y[n]-0.5y[n-1]=x[n]
a = [1 -0.5];% co-efficients of y[n]or Denominator Coefficients
b = [1];% co-efficients of x[n] or Numerator Coefficients
impz(b,a);% Computing and Plotting Impulse Response using
coefficients of Difference Equation
xlabel('n (samples)','fontweight','bold')
ylabel('Amplitude','fontweight','bold')
title('Impulse Response h[n]','fontweight','bold')
grid

Example 5 :Computing and Plotting System Response y[n] using Matlab:-

% Computing System Response/Convolution y[n] in Time Domain


clc;clear all;close all
% Let Difference Equation is y[n]-0.5y[n-1]=x[n]
a = [1 -0.5];% co-efficients of y[n]
b = 1;% co-efficients of x[n]
x = [1 0 1 0 1];% Defining input sequence x[n]

6
h=impz(b,a);% Computing Impulse Response using Num and Den
coefficients
y_filter = filter(b,a,x)%
Computing System Response y[n]
using Filter command
y_conv = conv(x,h);% Computing
System Response y[n] using
conv command
n=0:length(x)-1;
subplot(211)
stem(n,y_filter,'filled');
title('System Response using
filter')
grid

xlabel('n','fontweight','bold')
ylabel('y[n]','fontweight','bold')
subplot(212)
stem(n,y_conv(1:length(x)),'filled')
title('System Response using conv')
xlabel('n','fontweight','bold')
ylabel('y[n]','fontweight','bold')
grid

Example 6 :Comparing Impulse Response 𝒉[𝒏] and System Response 𝒚[𝒏] when input
is impulse sequence 𝜹[𝒏] using Matlab:-
% Comparing Impulse Response h[n] and System Response/Convolution
y[n] in Time Domain
% When input signal is Impulse
clc;clear all;close all
% Let Difference Equation is y[n]-0.5y[n-1]=x[n]
a = [1 -0.5];% co-efficients of y[n]
b = [1];% co-efficients of x[n]
[h,n]=impz(b,a);% Computing Impulse Response using Num and Den
coefficients
x = [1 zeros(1,13)];% Defining x[n] as Impulse sequence
y_filter = filter(b,a,x);% Computing System Response y[n] using
Filter command
y_conv = conv(h,x);% Computing System Response y[n] using conv
command

7
subplot(311)
impz(b,a);% Computing and Plotting Impulse Response using
coefficients of Difference Equation
title('Impulse Response using filter');xlabel('n
(samples)','fontweight','bold');ylabel('Amplitude','fontweight','b
old')
title('Impulse Response h[n]','fontweight','bold');xlim([0
length(x)-1]);grid;subplot(312)
stem(n,y_filter,'filled');title('System Response y[n] using
filter');grid
xlabel('n','fontweight','bold')
ylabel('y[n]','fontweight','bold')
xlim([0 length(x)-1]);subplot(313)
stem(n,y_conv(1:length(x)),'filled')
title('System Response y[n] using conv')
xlabel('n','fontweight','bold')
ylabel('y[n]','fontweight','bold')
xlim([1 length(x)]-1)
grid

Convolution of Discrete Time Signal using Graphical Method:


𝑥[𝑛] ∗ ℎ[𝑛] = ∑ 𝑥[𝑘]ℎ[𝑛 − 𝑘]


𝑘=−∞
Convolution involves the sum of a product of two signals: 𝑥[𝑘]ℎ[𝑛 – 𝑘]. At each output index 𝑛, the
product changes.
1- Write both as functions of 𝑘: 𝑥[𝑘] and ℎ[𝑘].
2- Flip ℎ[𝑘] to get ℎ[−𝑘] (This is called “folding”).
3- For each output index 𝑛 value of interest, shift by 𝑘 to get ℎ[𝑛 − 𝑘].
4- Form product 𝑥[𝑘]ℎ[𝑛 – 𝑘] and sum its elements to get the number 𝑦[𝑛].
5- Repeat step 3 and 4 for each 𝑛.

8
Example 7: Convolution:
𝑦[𝑛] = 𝑥[𝑘]ℎ[𝑛 – 𝑘]

Appendix:
Z Transform table:

9
10
11
12

You might also like