Dsp Using Matlab® - 5

26
Lecture 5: Z-Transform Mr. Iskandar Yahya Prof. Dr. Salina A. Samad

Transcript of Dsp Using Matlab® - 5

Page 1: Dsp Using Matlab® - 5

Lecture 5: Z-Transform

Mr. Iskandar Yahya

Prof. Dr. Salina A. Samad

Page 2: Dsp Using Matlab® - 5

Properties of z-TransformThe important properties of the z-transform:

1. Linearity

2. Sample shifting

3. Frequency shifting

4. Folding

5. Complex conjugation

6. Differentiation in the z-domain

212121 xx ROCROC:ROC)z(X)z(X)]n(x)n(x[z

xn ROC:ROC)z(Xz)]nn(x[z 0

0

abyscaledROC:ROC)a

z(X)]n(xa[z x

n

xROCinverted:ROC)z

(X)]n(x[z1

x*** ROC:ROC)z(X)]n(x[z

xROC:ROCdz

)z(dXz)]n(nx[z

Page 3: Dsp Using Matlab® - 5

Properties of z-TransformThe important properties of the z-transform:

7. Multiplication

8. Convolution

211

2121 2

1xx

c

ROCinvertedROC:ROCdvv)v/z(X)v(Xj

)]n(x)n(x[z

212121 xx ROCROC:ROC)z(X)z(X)]n(x*)n(x[z

Page 4: Dsp Using Matlab® - 5

Properties of z-TransformThe important properties of the z-transform:

7. Multiplication

8. Convolution

The time domain convolution transforms into a multiplication of two functions. We can use “conv” to implement the product of X1(z) and X2(z).

211

2121 2

1xx

c

ROCinvertedROC:ROCdvv)v/z(X)v(Xj

)]n(x)n(x[z

212121 xx ROCROC:ROC)z(X)z(X)]n(x*)n(x[z

Page 5: Dsp Using Matlab® - 5

Properties of z-TransformExample 1:

Let

Find

From definition of the z-transforms,

Hence

?)()()(

6543)(,432)(

213

3212

211

zXzXzX

zzzzXzzzX

}6,5,4,3{)(}4,3,2{)( 21 nxnx

x1 = [2,3,4]; x2 = [3,4,5,6];

x3 = conv(x1,x2)

x3 =

6 17 34 43 38 24

543213 24384334176 zzzzz)z(X

Page 6: Dsp Using Matlab® - 5

Properties of z-TransformExample 2:

We can use the “conv_m” function in to multiply two z-domain polynomials corresponding to noncausal sequences:

We have

Therefore X3(z) = 2z3 + 8z2 + 17z + 23 + 19z-1 + 15z-2

?)()()(

5342)(,32)(

213

122

11

zXzXzX

Find

zzzzXzzzX

}5,3,4,2{)(}3,2,1{)( 21 nxnx

x1 = [1,2,3]; n1 = [-1:1];

x2 = [2,4,3,5]; n2 = [-2:1];

[x3,n3] = conv_m(x1,n1,x2,n2)

x3 =

2 8 17 23 19 15

n3 =

-3 -2 -1 0 1 2

Page 7: Dsp Using Matlab® - 5

Properties of z-TransformTo divide one polynomial by another, we need an inverse

operation called deconvolution.In Matlab we use “deconv”, i.e. [p,r] = deconv(b,a) where we are

dividing “b” by “a” in a polynomial part “p” and a remainder “r”.Example,

We divide polynomial X3(z) in previous example by X1(z):

x3 = [6,17,34,43,38,24]; x1 = [2,3,4];

[x2, r] = deconv(x3,x1)

x2 =

3 4 5 6

r =

0 0 0 0 0 0

Page 8: Dsp Using Matlab® - 5

z-Transform Pairs

Page 9: Dsp Using Matlab® - 5

z-Transform PairsLet’s look at one example:

Determine the z-transform of )2()]2(3

cos[)5.0)(2()( )2( nunnnx n

5.0;0625.025.075.01

0625.05.025.0

0625.025.075.01

0625.05.025.0)

25.05.01

25.01()(

5.0;25.05.01

25.01

25.0)3cos5.0(21

)3cos5.0(1)](]

3cos[)5.0[(

1.4

;])](]

3cos[)5.0[(

[

)](]3

cos[)5.0([)(

)

4321

543

4321

4321

21

11

21

1

21

1

2

2

zzzzz

zzz

zzzz

zzzz

zz

z

dz

dzzXhence

zzz

z

zz

znunZ

tablefrom

ROCtheinchangenodz

nundZzz

propertyplaneztheinationdifferentitheapplying

nunnZzzX

propertyshiftsampletheapplyingsol

n

n

n

Page 10: Dsp Using Matlab® - 5

z-Transform PairsIn this example, we can see that the transform is of the form X(z) =

B(z)/A(z).We can use the coefficients of B(z) and A(z) as the “b” and “a” in the

“filter” routine and excite this routine with an impulse sequence, δ(n), where Z[δ(n)] = 1. The output of “filter” will be x(n).

This is a numerical approach of computing the inverse z-transform.We can compare this output with the given x(n) to verify our z-transform

X(z) is indeed the transform of x(n).

Page 11: Dsp Using Matlab® - 5

z-Transform PairsThe Matlab inplementation:

b= [0,0,0,0.25,-0.5,0.0625]; a = [1,-1,0.75,-0.25,0.0625];

[delta,n] = impseq(0,0,10)

delta =

1 0 0 0 0 0 0 0

n =

0 1 2 3 4 5 6 7

x = filter(b,a,delta) % check sequence

x =

Columns 1 through 7

0 0 0 0.2500 -0.2500 -0.3750 -0.1250

Column 8

0.0781

x = [(n-2).*(1/2).^(n-2).*cos(pi*(n-2)/3)].*stepseq(2,0,7) %original sequence

x =

Columns 1 through 7

0 0 0 0.2500 -0.2500 -0.3750 -0.1250

Column 8

0.0781

Page 12: Dsp Using Matlab® - 5

z-Transform InversionA Matlab function “residuez” is available to compute

the residue part and the direct (or polynomial) terms of a rational function in z-1.

Let

Therefore we can find the Residues (R), Poles (p) and Direct terms (C) of X(z).

NM

k

kk

N

k k

k

xxNN

MM

zCzp

R

RzR;za....za

zb....zbb)z(X

011

11

110

1

1

[R, p, C] = residuez(b,a)

Page 13: Dsp Using Matlab® - 5

z-Transform InversionLet’s look at an example:Consider the rational function:

First rearrange X(z) so that it is a fucntion in ascending powers of z-1:

Use matlab:

143)(

2

zz

zzX

21

1

22

2

143)143()(

zz

z

zzz

zzzX

b = [0,1]; a = [3,-4,1];

[R,p,C] = residuez(b,a)

R =

0.5000

-0.5000

p =

1.0000

0.3333

C =

[]

Page 14: Dsp Using Matlab® - 5

z-Transform InversionWe obtain:

To convert back to the rational function form:

So that we get:

11

311

21

12

1

zz)z(X

[b,a] = residuez(R,p,C)

b =

0.0000

0.3333

a =

1.0000

-1.3333

0.3333

21

1

31

341

31

zz

z)z(X

Page 15: Dsp Using Matlab® - 5

z-Transform InversionAnother example, compute the inverse z-

transform:90

901901

1121

.z,)z.()z.(

)z(X

b = 1; a = poly([0.9,0.9,-0.9])

a =

1.0000 -0.9000 -0.8100 0.7290

[R,p,c] = residuez(b,a)

R =

0.2500 + 0.0000i

0.5000 - 0.0000i

0.2500

p =

0.9000 + 0.0000i

0.9000 - 0.0000i

-0.9000

c = []

Page 16: Dsp Using Matlab® - 5

z-Transform InversionUsing table 4.1:

Matlab verification:

)n(u).(.)n(u).)(n(.

.)n(u).(.)n(x nnn 902501901

90

5090250 1

[delta,n] = impseq(0,-1,7);

x = filter(b,a,delta) % check sequence

x =

Columns 1 through 7

0 1.0000 0.9000 1.6200 1.4580 1.9683

1.7715

Columns 8 through 9

2.1258 1.9132

x = (0.25)*(0.9).^n.*stepseq(0,-1,7) + (0.5)*(n+1).*(0.9).^n.*stepseq(-1,-1,7) + (0.25)*(-0.9).^n.*stepseq(0,-1,7) % answer sequence

x =

Columns 1 through 7

0 1.0000 0.9000 1.6200 1.4580 1.9683

1.7715

Columns 8 through 9

2.1258 1.9132

Page 17: Dsp Using Matlab® - 5

z-Transform InversionAnother Example. Determine the inverse z-

transform of

so that the resulting sequence is causal and contains no complex numbers.We will have to find the poles of X(z) in the polar

form to determine the ROC of the causal sequence.

21

1

6402801

2401

z.z.

z.)z(X

b = [1,0.4*sqrt(2)]; a=[1,-0.8*sqrt(2),0.64];

[R,p,C] = residuez(b,a)

R = 0.5000 - 1.0000i

0.5000 + 1.0000i

p = 0.5657 + 0.5657i

0.5657 - 0.5657i

C = []

Mp=abs(p) % pole magnitudes

Ap=angle(p)/pi % pole angles in pi units

Mp = 0.8000 0.8000

Ap = -0.2500 0.2500

Page 18: Dsp Using Matlab® - 5

z-Transform Inversion

From the Matlab calculation, we have:

And from table 4.1 we have:

sequencesidedrighttodue.z

,ze.

j.

ze.

j.)z(X

jj

80

801

50

801

50

1414

)n(u)]nsin()n[cos(.

)n(u)]ee(j)ee(.[.

)n(ue.)j.()n(ue.)j.()n(x

n

njnjnjnjn

njnnjn

42480

5080

80508050

4444

44

Page 19: Dsp Using Matlab® - 5

z-Transform InversionMatlab Verification:

[delta,n] = impseq(0,0,6);

x = filter(b,a,delta) % check sequence

x =

1.0000 1.6971 1.2800 0.3620 -0.4096 -0.6951 -0.5243

x = ((0.8).^n).*(cos(pi*n/4)+2*sin(pi*n/4)) % answer sequence

x =

1.0000 1.6971 1.2800 0.3620 -0.4096 -0.6951 -0.5243

Page 20: Dsp Using Matlab® - 5

Systems in The z-DomainTo determine zeros and poles of a rational H(z), we can use

“roots” for both the numerator and denominator. (“poly” is the inverse of “root”)

We can plot these roots in a pole-zero plot using “zplane(b,a)”. This will plot poles and zeros given the numerator row/coloumn vector “b” and the denominator row/coloumn vector “a”. (H(z) = B(z)/A(z))

We can calculate the magnitude and the phase responses of our system using “freqz”:

[H,w] = freqz(b,a,N) – Returns the N-point frequency vector “w” and the N-point complex frequencey response vector “H”.

Page 21: Dsp Using Matlab® - 5

Systems in The z-DomainSecond form:

[H,w] = freqz(b,a,N,’whole’) – uses N points around the whole unit circle for computation.

Another form:H = freqz(b,a,w) – it returns the frequency response at frequencies designated in vector “w”, normally between 0 and π.

Example:Given a causal system

y(n) = 0.9y(n-1) + x(n)a.Find H(z) and sketch its pole-zero plotb.Plot |H(ejw)| and <H(ejw).c. Determine the impulse response h(n)

Page 22: Dsp Using Matlab® - 5

Systems in The z-DomainSolution using Matlab:

a. use “zplane” function -

We specified b=[1,0] instead of b=1 because the “zplane” function assumes that scalars are zeros and poles.

>> b = [1,0]; a = [1,-0.9];>> zplane(b,a);>>title(‘Pole-Zero Plot’)

-1 -0.5 0 0.5 1

-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Real Part

Imag

inar

y P

art

Pole-Zero Plot

0 0.9

Page 23: Dsp Using Matlab® - 5

Systems in The z-DomainB. To plot the magnitude and phase response, we

use “freqz” function:>> [H,w] = freqz(b,a,100);>> magH = abs(H); phaH = angle(H);>> >> subplot(2,1,1); plot(w/pi,magH); grid>> xlabel('frequency in pi units'); ylabel('Magnitude');>> title('Magnitude Response')>> subplot(2,1,2); plot(w/pi,phaH/pi); grid>> xlabel('Frequency in pi units'); ylabel('Phase in pi units');>> title('Phase Response')

Page 24: Dsp Using Matlab® - 5

Systems in The z-DomainB. The plots:

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

2

4

6

8

10

12

frequency in pi units

Ma

gn

itud

e

Magnitude Response

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-0.4

-0.3

-0.2

-0.1

0

Frequency in pi units

Ph

ase

in p

i un

its

Phase Response

Page 25: Dsp Using Matlab® - 5

Systems in The z-DomainB. Points to note:

We see the plots, the points computed is between 0<w<0.99π

Short at w = π.To overcome this, use the second form of “freqz”:

>> [H,w] = freqz(b,a,200,’whole’);>> magH = abs(H(1:101)); phaH = angle(H(1:101));

Now the 101st element of the array H will correspond to w = π.

Similar result can be obtained using the third form: >> w = [0:1:100]*pi/100;

>> H = freqz(b,a,w);>> magH = abs(H); phaH = angle(H);

Try this

Page 26: Dsp Using Matlab® - 5

Systems in The z-DomainB. Points to note:

Also, note that in the plots we divided the “w” and “phaH” arrays by π so that the plot axes are in the units of π and easier to read

This is always a recommended practice!

END!!!!