Matlab examples

Inverse z-Transform
Partial Fraction expansion
Examples: Using partial fraction methods, find the inverse z-transform
u
An example for Simple Real Poles
6 − 9z
X (z ) =
X (z) =
1 − 2.5z
−1
−1
+z
6 − 9z
−1
−1
−1
A2 = (1 − 2z −1 ) X( z)
z
−1
=2
z −1 =0.5
A1
=
(1 − 0.5 z )(1 − 2z )
A1 = (1 − 0.5 z − 1) X (z)
X (z ) =
−2
−1
(1 − 0.5 z )
6 − 9z − 1
=
−1
(1 − 2z )
z
−1
=2
+
A2
−1
(1 − 2z )
=
6 − 9(2)
1 − 2(2)
6 − 9 z −1
=
−1
(1 − 0.5 z )
4
2
+
−1
(1 − 0.5z ) (1 − 2 z −1)
z − 1 =0.5
=
=
4,
6 − 9(0.5)
1 − 0.5(0.5)
=
2
ROC z > 2
x(n) =  4(0.5)n + 2(2)n  u(n )
v
An example for Multiple Real Poles
F (z ) =
F1 (z ) =
1
1 − 0.7z
−1
+ 0.16 z
d
dz
z −1 =
1− 0.6z −1
9
−1
(1 − 0.3 z )
=
−
A1
A2
A3 z− 1
+
+
(1− 0.3z −1) (1− 0.2z −1) (1− 0.2z −1)2
−1
(1 − 0.2z ) z =
−1 2
3
z
−3
1
=
1
z −1 = 5
(1 − 0.2z − 1)2 zF (z)
(1− 0.3z −1) 2 z −1 = 5
F (z ) =
=
(1 − 0.3 z −1 )(1 − 0.2z −1 )2
A3 = (1 − 0.2z − 1) zF(z )
A2 =
− 0.012 z
1
A1 = (1 − 0.3z −1)F( z)
A2 =
−2
=
−1
1− 0.6(5)
3
z
=
1
=
=
=
1
3
9
(1 − 0.2 ) 2
0.2
(1 − 0.3 z −1) z − 1 = 5 1 − 0.3(5)
=5
(1 − 0.3(5)) 2
1 =
=
−0.4 ,
z
(1 − 0.3z −1 ) − z(0.3) z −2
=
−
1
−
1
dz (1 − 0.3 z ) z = 5
z −1 = 5
(1− 0.3 z − 1) 2
d
−8
8
−1
(1 − 0.2z )
−
0.4z
−1
−1 2
(1 − 0.2 z )
f (n) = 9(0.3)n − 8(0.3)n + 2n (0.3)n  u(n )
Z-Transform with MatLab-1
w
An example for Multiple Real Poles F (z) =
p1 =
− b − b 2 − 4ac
2a
=
1 + 2z −1 + z −2
1 − z −1 + 0.3561z −2
o
− 1 − 12 − 4(0.3561)
= 0.5 + j 0.3257 = 0.5967e j 33.08
2
2
o
−b + b 2 − 4ac −1 + 1 − 4(0.3561)
=
= 0.5 − j 0.3257 = 0.5967e− j 33.08
2a
2
1 + 2z −1 + z −2
F (z ) =
(1 − p1z −1 )(1 − p2 z −1 )
p2 =
F (z ) = 2.8082 −
F1 (z ) =
A1 =
1.8082 − 4.8082z −1
(1 − p1z −1 )(1 − p2 z − 1)
1.8082 − 4.8082z −1
A1
A2
=
+
−1
−1
−1
(1 − p1z )(1 − p2 z ) (1 − p1z ) (1 − p2 z −1)
1.8082 − 4.8082z
(1 − (0.5 − j 0.3257) z−1)
1.8082 − 4.8082z −1
A2 =
(1 − (0.5 + j0.3257)z −1)
z − 1=
1
0.5 + j 0.3257
=
4.8082
o
0.5 − j 0.3257
= 0.904 − j5.993 = 6.06e − j 98.58
(0.5 + j 0.3257)
1−
(0.5 − j 0.3257)
1.8082 −
z−1=
1
0.5 − j 0.3257
o
F (z ) = 2.8082 +
4.8082
o
0.5 + j 0.3257
= + 0.904 + j 5.993 = 6.06e+ j 98.58
(0.5 − j 0.3257)
1−
(0.5 + j 0.3257)
1.8082 −
−1
6.06e − j 98.58
−
o
=
6.06e j 98.58
o
o
1 − 0.5967e j 33.08 z − 1 1 − 0.5967e − j33.08 z −1
o
o
f (n) = 2.8082δ (n ) +  6.06e − j 98.58 (0.5967)n e j 33.08n + 6.06e j 98.58 (0.5967)n e − j 33.08n  u(n )


o
o
f (n) = 2.8082δ (n ) + (6.06)(0.5967)n e j 33.08n− 98.58 + 6.06(0.5967)n e − j (33.08n−98.58 )  u (n )


f (n) = 2.8082δ (n ) + 12.12(0.5967)n cos(33.08 n − 98.58o ) u (n)
Z-Transform with MatLab-2
Z-Transform in Matlab
Z-transform is defined as
∞
X ( z ) = ∑ x( n) z − n
n =0
or
X ( z ) = Z [ x( n) ]
The inverse z-transform is denoted by
x(n ) = Z − 1 [ X (z )]
MatLab Symbolic Toolbox gives the z-transform of a function
Example:
1
u (n )
4n
x (n ) =
X ( z) =
2z
2z −1
>> syms z n
>> ztrans(1/4^n)
>> syms z n
>> iztrans(2*z/(2*z-1))
ans =
ans =
4*z/(4*z-1)
(1/2)^n
Example:
X (z ) =
6 − 9z
1 − 2.5z
−1
−1
+z
−2
>> syms z n
>> iztrans((6-9*z^-1)/(1-2.5*z^-1+z^-2))
>> syms z n
>> ztrans (2*2^n+4*(1/2)^n)
ns =
ans =
2*2^n+4*(1/2)^n
z/(1/2*z-1)+8*z/(2*z-1)
Z-Transform with MatLab-3
Power series expansion with the MatLab
The deconv function is used to perform the long division required in power series method.
For given z-transform X(z)
X (z ) =
b0 + b1z
a +az
0
−1
+ ... + b z
−n
+ ... + a z
−m
n
−1
m
1
The matLab command is
>>[q,r]=deconv(b,a)
Example:
1 + 2z
X (z ) =
1− z
−1
−1
+z
−2
+ 0.3561z
−2
>> b=[1 2 1];
>> a=[1 –1 0.356];
>> n=5;
>> b=[b zeros(1,n-1)];
>> [x,r]=deconv(b,a);
>> disp(x)
1.0000 3.000 3.6439 2.5756
1.2780
Partial fraction expansion with MatLab
The residuez function is used to find the partial fraction coefficients and poles of the z-transform
For given z-transform X(z)
X (z ) =
b0 + b1z
a +az
0
X (z ) =
1
r0
1− p1z − 1
−1
+ ... + b z
−n
+ ... + a z
−m
n
−1
m
+ ... +
rn
1− pn z −1
+k +k z
1
−1
2
+ ... + k
z
− ( m − n)
m − n− 1
The matLab command is
>> [r,p,k]=residues(b,a)
Example:
X (z ) =
1 + 2z
1− z
−1
−1
+z
−2
+ 0.3561z
−2
>> [r,p,k]=residuez([1,2,1],[1, -1,0.3561])
r=
-0.9041 - 5.9928i
-0.9041 + 5.9928i
p=
-0.5000 – 0.3257i
-0.5000 + 0.3257i
k=2.8082
Z-Transform with MatLab-4
Pole-zero Diagram
zplane command compute and display of the pole-zero diagram of z-function
The command is
>> zplane(b,a)
To display the pole value, use root(a) command. To display the zero value root(b)
Example:
X (z ) =
1 − 1.6180 z
1 − 1.5161z
−1
−1
+z
−2
+ 0.878 z
−2
>> b=[1 –1.6180 1];
>> a=[1 –1.5161 0.878];
>> roots(a)
ans =
0.7581 + 0.5508i
0.7581 - 0.5508i
>> roots (b)
ans =
0.8090 + 0.5878i
0.8090 - 0.5878i
>> zplane(b,a)
Z-Transform with MatLab-5
Frequency Response estimation
The freqz function computes and display the frequency response of given z-transform of the
function.
The command is
>> freqz(b, a, npt, Fs)
where Fs is the sampling frequency, npt is the number of frequency points between 0 and Fs/2.
Example:
X (z ) =
1 − 1.6180 z
1 − 1.5161z
−1
−1
+z
−2
+ 0.878 z
−2
>> b=[1 –1.6180 1];
>> a=[1 –1.5161 0.878];
>>freqz(b,a)
Z-Transform with MatLab-6