Chapter - 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

Chapter 3.

z-Transform and Digital Filters


3.1 z-Transform
X(s) = L{x(t)} =

x (t )e st dt .

where L{}denotes the Laplace transform operation

z FGH x(nT)(t nT)IJK e dt L{x (t)} = x (nT )F z (t nT )e dt I . H K


L{xs(t)} =
N 1 n=0 st
N 1 n=0

st

L{xs(t)} =

x(nT )e
n=0

N 1

sTn

z = e sT = e( + j)T = eT e jT = re j
N 1 n=0

X(z) =

x ( n) z

z-transform

X(z) =

n =

x ( n) z

z-transform of an infinitely long sequence

3-1

jIm{z}

j3/T j j/T j/T j j3/T 1 1 Re{z}

(a)

(b)

Fig. 3.1 Relationship between two transform domains: (a) s plane (b) z plane.

3-2

3.2 z-Transform Examples


Example 3.2.1 A continuous-time impulse response h(t) = e2tu(t) where u(t) is the unit step function. (a) Find the Laplace transform of h(t). (b) The signal h(t) is sampled at every 0.1[s] to generate h(n) = anu(n) where a = e.2. Find the z-transform of h(n).

Solution (a) H ( s) =

e 2 t e st dt =

1 . s+2

(b) H ( z ) = a n z n = az 1
n=0 n=0

c h

1 1 . = 1 2 (.1) 1 z 1 az 1 e

FG H

IJ K

The summation converges when |az1|< 1 which implies |z|>|a|. Thus, we say that the region of convergence (ROC) is that |z|>|a|. Note that the Laplace transform pole is at s = 2 and the z-transform pole is at z = e2T.

3-3

Example 3.2.2 Find the z-transform of x(n) = (nn0).

Solution X ( z) = z n0 . ROC: |z|> 0.

Example 3.2.3 Find the z-transform of x(n) = u(n) u(nN).

Solution X ( z) = z n =
n=0 N 1

1 z N 1 z 1

ROC: |z|> 0.

3-4

Example 3.2.4

Find the inverse z-transform of X ( z ) = Answer x(n) = anu(n).

1 with the ROC: |z|>|a|. 1 az 1

Example 3.2.5

Find the inverse z-transform of X ( z) =

1 . (1 az )(1 bz 1 )
1

Solution
A B + 1 1 az 1 bz 1 1 1 a = and B = where A = 1 1 bz z = a a b 1 az 1 1 b 1 a X ( z) = 1 a b 1 bz 1 a b 1 az b n a n a b u ( n) . Thus, x(n) = ab a b X ( z) =

=
z =b

b . ba

3-5

Example 3.2.6 Find the z-transform of the left-sided sequence, x(n) = anu(n1).
0 -0.5 -1 0 5 10 15 20 25

1 0

Solution
X ( z) =
n =

a n z n = ( a 1 z ) =
n n =1

a 1 z 1 = 1 1 a z 1 az 1

ROC: |z| < |a|.

Example 3.2.7 Find the z-transform of the double-sided sequence, x(n) = a|n|.
1 0.5 0

10

15 1 0 1 2

20

25

30

35

Solution x(n) = anu(n) + anu(n1). The z-transform of the first sequence is


1 with ROC of |a| < |z|. 1 az 1 1 The z-transform of the second term is with ROC of |z| < |1/a|. 1 1 z 1 a 1 1 X(z) = ROC: : |a| < |z| < |1/a|. 1 1 az 1 1 z 1 a

jIm{z}

1/a

Re{z}

Fig. 3.2 The region of convergence is specified by a ring.

3-6

3.3. Properties of the z-Transform


z 1. ax1 (n) + bx2 (n) aX 1 ( z ) + bX 2 ( z ) z 2. x(n n0 ) z n0 X ( z )

(Proof)

n =

x(n n ) z
0

m =

x ( m) z

( m + n0 )

= z n0

m =

x ( m) z

= z n0 X ( z) .

z 3. a n x(n) X (a 1 z ) .

(Proof)

n =

a x ( n) z
n

n =

x ( n) a

= X (a 1 z ) .

z 4. x(n) X ( z 1 )

(Proof)

n = ( N 1)

x( n) z n = x(m) z ( m) = x(m) z 1
m= 0 m= 0

N 1

N 1

= X(z1).

3-7

3.4 Discrete-Time System (Digital Filter)

input x(n)

impulse response h(n)

output y(n)

Fig. 3.3 Discrete-Time System (Digital Filter)

3.4.1 FIR filter (MA system; all-zero system)


b , 0 n M h( n) = n 0, otherwise

y (n) = h(n) * x(n) = h(m) x(n m) = bm x(n m) .


m=0 m=0

(difference equation) Y ( z ) = bm z m X ( z ) .
m=0 M

H ( z) =

Y ( z) X ( z)

Transfer Function

H ( z ) = bm z m .
m=0

3-8

3.4.2 IIR filter I (AR or all-pole system)

H ( z) =

1 . 1 a1 z 1

h(n) = a1nu (n) . (1 a1 z 1 )Y ( z ) = X ( z ) .


y (n) = a1 y (n 1) + x(n) .

Example 3.4.1 Find the impulse response of the system whose input, x(n), and output, y(n), are described by the following difference equation: y(n) = 0.8y(n1) + 2x(n).

Assume that h(n) = 0 for n < 0. Solution Method1: Because the impulse response is the response of the system to the unit impulse, input x(n) needs to be replaced by (n) and output y(n) needs to be replaced by h(n) such that the difference equation becomes h(n) = 0.8h(n1) + 2(n). Now h(n) = 0 when n < 0. h(0) = 0.8h(1) + 2(0) = (0.8)(0) + (2)(1) = 2 h(1) = 0.8h(0) + 2(1) = 2(0.8) h(2) = 0.8h(1) + 2(2) = 2(0.82), and so on. Note that (n) = 0 when n 0. Thus, h(n) = 2(0.8n)u(n). Method 2: The z-transform of the difference equation is Y(z) = 0.8z1Y(z) + 2X(z) or [1 0.8z1]Y(z) = 2X(z). Thus, the transfer function becomes 2 H(z) = . 1 0.8z 1 The inverse z-transform of the above gives h(n) = 2(0.8n)u(n).

3-9

AR or all-pole system

H ( z) =

b0 1 a1 z a2 z 2
1

aK z

b0 1 am z
m =1 K m

y (n) = b0 x(n) + am y (n m) .
m =1

In AR systems, the present output sample is determined by the present input sample, and the previous output samples.

3-10

3.4.3 IIR Filter II (ARMA or pole-zero system)

H ( z) =

b0 + b1 z + b2 z + 1 a1 z 1 a2 z 2

+ bM z = aK z K

1 am z m
m =1

m=0 K

z m .

y (n) = bm x(n m) + am y (n m) .
m=0 m =1

3.4.4 Causal or noncausal filter

If h(n) = 0 for n < 0, then the system is causal or realizable. A system whose impulse response is nonzero for n < 0 is called a noncausal or nonrealizable system.

3-11

3.5 Frequency Response of a Digital Filter


3.5.1 Analog Filter Frequency Response

+ x(t)

1 [] 1 [F]

+ y(t)

+ X(s)

1 1/s

+ Y(s)

(a)

(b)

Fig. 3.4 (a) LPF circuit (b) LPF in the Laplace transform domain.

1 Y ( s) = s X ( s) . 1 1+ s 1 Y ( s) 1 . = s = H (s) = X ( s) 1 + 1 s + 1 s 1 H () = H ( s ) s = j = . j + 1 1 H () = . 2 + 1 0 arg{H ()} = tan 1 tan 1 = tan 1 1 1

3-12

1 Magnitude

0.5

4 5 6 Frequency (rad/s)

10

0 Phase (degrees)

-50

-100

4 5 6 Frequency (rad/s)

10

(a)
0 Magnitude (dB) -10 -20 -30 -2 10 0 Phase (degrees)

10

-1

10 Frequency (rad/s)

10

-50

-100 -2 10

10

-1

10 Frequency (rad/s)

10

(b) Fig. 3.5 (a) Magnitude and Phase plots - linear scale (b) Bode plots

3-13

3.5.2 dB (decibel)

10 log10(Po/Pi) [dB]. 10 log10(Po/Pi) = 10 log102 = 3 [dB]. 10 log10(Po/Pi) = 10 log10(106) = 60 [dB]. 10 log10(Vo/Vi)2 = 20 log10(Vo/Vi) 10 log10(Io/Ii)2 = 20 log10(Io/Ii).
20 log10 H () .

3.5.3 Bode Plot

There are a number of ways to represent the frequency response graphically, but the method suggested by H. W. Bode in the 1930s is particularly useful. Bode's method consists of plotting two curves: the magnitude response in dB and phase in radians as functions of the log of frequency. Usually the magnitude response in dB and the phase are plotted linearly along the vertical axis on graph paper that has several cycles of a log scale on the horizontal axis. Each cycle represents a factor of ten in frequency. This special paper is known as semilog graph paper.

3-14

3.5.4 Cutoff Frequency

1 [rad/s] c c

Fig. 3.6 Magnitude response of an ideal lowpass filter

woofer

mid-range

tweeter [rad/s]

Fig. 3.7 Typical frequecy responses of three-way speaker system

1 and 2 are referred to as 3 dB cutoff frequencies.

3-15

3.5.5 Digital Filter Frequency Response

H () = H ( z ) z =e j =

1 am e jm
m =1

m =0 K

b e
m

j m

Example 3.5.1

Find the frequency response of a system whose transfer function is specified by H ( z ) = 0.25 + 0.5 z 1 + 0.25 z 2 . Plot the magnitude response and determine what kind of filter this is: lowpass or highpass? Solution The frequency response of the system is obtained by evaluating the transfer function on the unit circle ej: H () = 0.25 + 0.5e j + 0.25e j 2 = e j (0.25e j + 0.5 + 0.25e j 2 ) = e j (0.5 + 0.25e j + 0.25e j 2 ) = e j (0.5 + 0.5cos ) The magnitude response H () = 0.5(1 + cos ) . The phase response arg{H ()} = . The magnitude response plots in linear scale and in dB are shown below.

3-16

1 Magnitude
Magnitude

0.5

0 0 Magnitude (dB)
Magnitude (dB)

0.1

0.2

0.3

0.4

0.5

0.6 0.7 Angle (rad)

0.8

0.9

1 (x )

-50

-100

0.1

0.2

0.3

0.4

0.5

0.6 0.7 Angle (rad)

0.8

0.9

1 (x )

3-17

Example 3.5.3

Find the frequency response of a system whose transfer function is specified by 1 H ( z) = . 1 az 1 Solution H () = 1 1 = j 1 ae 1 a cos + ja sin 1 H () = (1 a cos ) 2 + (a sin ) 2 = 1

1 2a cos + a 2 a sin arg{H ()} = tan 1 . 1 a cos

3-18

MATLAB Example 3.5.1

Find the frequency response of a system whose transfer function is specified by 1 H ( z) = . 1 0.85z 1 (Suggestion) Use MATLAB command freqz. Type help freqz for usage of the command. Type the following commands.
b=1; % Numerator polynomial coefficients a=[1 -0.85]; % Denominator polynomial coefficients [H,w]=freqz(b,a,100); subplot(121), plot(w,20*log10(abs(H))) % Magnitude in dB plot ylabel('Magnitude (dB)') xlabel('Angle (rad)') subplot(122), plot(w,angle(H)) % Phase in radian plot ylabel('Phase (rad)') xlabel('Angle (rad)')
20 15
Magnitude (dB)

0 -0.2
Phase

Magnitude (dB)

10 5 0 -5 -10

-0.4 -0.6 -0.8 -1 -1.2 -1.4

(rad)

2 Angle (rad)

Phase (rad)

2 Angle (rad)

3-19

3.6. Computation of Frequency Response

H (k ) = H ()

2 = k N

1 am e
m =1

m =0 K

bme

2 km N 2 km N

for k = 0, 1, 2,

, N1.

H (k ) =

1 am e
m =1

m=0 K

b e
m

2 km N

m = M +1 2 N 1 j km N

N 1

0e

2 km N 2 km N

m = K +1

0e

for k = 0, 1, 2,

, N1.

The numerator is the DFT of the N-point sequence

{b0 , b1 , b2 ,

, bM , 0,

, 0}

The denominator is the DFT of the N-point sequence

{1, a1 , a2 ,
H (k ) = B(k ) A(k )

, aK , 0,

, 0} .

for k = 0, 1, 2,

, N1.

Alternative way but not recommended (because of truncation) H(k) =

h( n) e
n=0

N 1

2 nk N

3-20

3.7 Linear Phase and FIR systems


3.7.1 Linear Phase Case

H() = |H()|ej () = . x(n) = A e j0n . y ( n) =

k =

h(k ) Ae

k =

j 0 ( n k )

= Ae j0 n = Ae
j 0 n

h ( k )e

jk 0

H ( 0 )

y(n) = A|H(0 )| e j0 n e j0 = A H (0 ) e j ( 0 n 0 ) = A H (0 ) e j0 ( n ) . x(n) = Acos(0n), y(n) = A|H(0 )|cos(0n 0) = A|H(0 )|cos0(n ).

3-21

3.7.2 Nonlinear Phase Case

H() = |H()| e j . Note that the phase (2) is nonlinear. y(n) = A|H(0 )| e j0 n e j0 = A H (0 ) e j ( 0 n 0 )
2

= A H (0 ) e j0 ( n 0 ) .

3-22

Example 3.7.1

The impulse response of an FIR filter is 5-point long and is symmetric (or even symmetric) about the midpoint, i.e., h(0) = h(4), h(1) = h(3). Find an expression of the frequency response. Solution The frequency response of the filter is H() = h(0) + h(1)e j + h(2)e j 2 + h(3)e j 3 + h(4)e j 4

= e j 2 [ 2h(0) cos 2 + 2h(1) cos + h(2) ] = |H()| e j ( ) where |H()| = 2 h(2 n) cos(n) + h(2)
n =1 2

= e j 2 h(0) {e j 2 + e j 2 } + h(1) {e j + e j } + h(2)

= e j 2 {h(0)e j 2 + h(4)e j 2 } + {h(1)e j + h(3)e j } + h(2)

and () = 2. This frequency response has a linear phase that will give a constant delay of 2.

3-23

Example 3.7.2

The impulse response of an FIR filter is 6-point long and anti-symmetric (or odd symmetric), i.e. h(0) = h(5), h(1) = h(4), and h(2) = h(3). Find an expression of the frequency response.

Solution The frequency response of the filter is H() = h(0) + h(1)e j + h(2)e j 2 + h(3)e j 3 + h(4)e j 4 + h(5)e j 5 = e j 2.5 h(0) ( e j 2.5 e j 2.5 ) + h(1) ( e j1.5 e j1.5 ) + h(2) ( e j 0.5 e j 0.5 ) = e j 2.5 [ j 2h(0) sin 2.5 + j 2h(1) sin1.5 + j 2h(2) sin 0.5] = e 2 e j 2.5 [ 2h(0) sin 2.5 + 2h(1) sin1.5 + 2h(2) sin 0.5]
j

= |H()| e j ( ) where |H()| = 2 h(2 n) sin ( (n + .5) )


n=0 2

and () = /2 2.5. This frequency response has a linear phase and it will give a constant delay of 2.5.

NOTE

N-point symmetric filter will have the following frequency response when N is even.
N N 1 2 1 j 2 n=0

H() = 2e

h 2 1 n cos ( (n + .5) ) .

Note that the frequency response is zero at = . This cannot be a highpass or bandstop filter.

3-24

3.8 FIR Lowpass Filter Design Using Windows


1, c c H a () = elsewhere 0,
1 [rad/s] c c

Fig. 3.8 Ideal lowpass filter frequency response

ha(t) =

1 c jt 1 1 j t j t c e d = 2 jt e c e c = c 2
ha(t)

sin c t . c t

Fig. 3.9 Impulse Response of the ideal lowpass filter

Sampling interval T = 1[s] so that the cutfoff frequency in digital filter c = cT = c. First, ha(t) can be sampled every second at t = 0, 1, 2, . Second, ha(t) can be sampled every second at t = 0.5, 1.5, 2.5, .

3-25

Example 3.8.1 Design a 7-point FIR lowpass filter with the cutoff frequency c of 0.2.

Solution

ha(t) = 0.2

2 b g sin.0.tt from Eq. (3.28). 02

Now ha(t) is sampled at t = 0, 1, 2, 3 so that ha(3) = 0.1009, ha(2) = 0.1514, ha(1) = 0.1871, ha(0) = 0.2000, ha(1) = 0.1871, ha(2) = 0.1514, ha(3) = 0.1009. To make a causal digital filter, ha(n) should be shifted by 3. Finally, a lowpass filter should have unit gain at = 0, i.e., H(0) =
3
a

h( n) e
n=0

j ( 0) n

h(n) = 1.
n=0

Because

n =3

h (n) = 1.0787, the final digital filter is obtained by shifting ha(n) by 3 to the right

and by dividing each coefficient by 1.0787. h(0) = 0.0935, h(1) = 0.1403, h(2) = 0.1734, h(3) = 0.1854, h(4) = 0.1734, h(5) = 0.1403, h(6) = 0.0935.
20 log10 H () [dB].
h(n) 0.2 0 dB H()

main lobe side lobes

-20 dB

0.1

-40 dB

-60 dB

-80 dB

0.5

1 [ rad]

(a) Impulse response

(b) Magnitude response

Fig. 3.10 The impulse response and the magnitude response of the LPF designed using a rectangular window.

3-26

Windows

Rectangular (or boxcar) window 1, 0 n N 1 wR(n) = elsewhere. 0, A window is used to truncate a long sequence (often, a infinitely long sequence) to make a finite-length sequence. 1) Obtain the expression of ha(t) for the desired normalized frequency c (= c). 2) Sample ha(t) at every second at t = 0, 1, 2, for the filter with odd number of coefficients or at t = 0.5, 1.5, 2.5, for the filter with even number of coefficients. 3) Sampled version of ha(t) is shifted by (N1)/2 to the right.. 4) Each of the resulting filter coefficients is multiplied by the corresponding window coefficient. 5) Filter coefficients are normalized so that H () =0 = 1.

3-27

Triangular (Bartlett) window (for odd N): N 1 2n 0n N 1 , 2 N 1 2n , < n N 1 WT(n) = 2 N 1 2 0, otherwise Hamming window: 0.54 0.46cos[2 n /( N 1)], 0 n N 1 wH(n) = 0, otherwise

Blackman window: 0.42 0.5 cos[2n /( N 1)] + 0.08 cos[4n /( N 1)], 0 n N 1 wB(n) = 0, otherwise

Note that the actual length of the Bartlett and the Blackman windows is N2 as the first and the last window points are zero.

0.5

0.5

0.5

0 N1

0 N1

N1

(a) Triangular window

(b) Hamming window

(c) Blackman window

Fig. 3.11 Three different types of windows

3-28

Example 3.8.2 Design a 7-point FIR lowpass filter with the cutoff frequency c of 0.2 using the triangular window.

Solution We can use the same coefficients obtained in Example 3.8.1. Let us shift the sequence by 3. ha(0) = 0.1009, ha(1) = 0.1514, ha(2) = 0.1871, ha(3) = 0.2000, ha(4) = 0.1871, ha(5) = 0.1514, ha(6) = 0.1009. Each filter coefficient must be multiplied by each of the triangular window coefficients. The triangular window coefficients are given as follows. (N = 9 is used but the first and the last window points are neglected as they are 0.) wT(1) = 0.5, wT(2) = 0.75, wT(3) = 1.0, wT(0) = 0.25, wT(4) = 0.75, wT(5) = 0.5, wT(6) = 0.25. Now intermediate filter coefficients are obtained by multiplying corresponding window coefficients. hi(0) = ha(0) wT(0) = 0.1009 0.25 = 0.0252 hi(1) = ha(1) wT(1) = 0.1514 0.5 = 0.0757 hi(2) = ha(2) wT(2) = 0.1871 0.75 = 0.1403 hi(3) = ha(3) wT(3) = 0.2000 1.0 = 0.2000 hi(4) = 0.1403, hi(5) = 0.0757, hi(6) = 0.0252. A lowpass filter should satisfy the condition: H(0) =
6

h( n) e j ( 0 ) n =
n=0

h(n) = 1.
n=0

Because 0.6824.

h (n) = 0.6824, the final digital filter is obtained by dividing hi(n) by


n=0 i

h(0) = 0.0369, h(1) = 0.1109, h(2) = 0.2056, h(3) = 0.2931, h(4) = 0.2056, h(5) = 0.1109, h(6) = 0.0369.

3-29

Exercise 3.8.2 Design a 7-point FIR lowpass filter with the cutoff frequency of 0.2 using the Hamming window.

Answer h(n) = {0.0135, 0.0785, 0.2409, 0.3344, 0.2409, 0.0785, 0.0135}

H()
Rectangular 0 dB Triangular Hamming -20 dB

-40 dB

-60 dB

-80 dB 0 0.2 0.4 0.6 0.8 1 [ rad]

Fig. 3.12 Magnitude response of LPF designed using different windows

3-30

0 dB

Rectangular Hamming Blackman

-40 dB

-80 dB

-120 dB

[rad]

Fig. 3.13 Lowpass filter magnitude response (20-point long filters)

3-31

3.9 FIR Highpass Filter Design


1, c c Hl() = otherwise 0
sin ct hl(t) = c c t

Hh() = 1 Hl()
1 [rad/s] c c

Fig 3.14 Ideal highpass filter frequency response

sin ct . hh(t) = (t) c c t

3-32

Example 3.9.1 Design a 7-point FIR highpass filter with the cutoff frequency of 0.2 using the Hamming window.

Solution Using Eq. (3.33), hh(t) sampled at t = 0, 1, 2, 3 are hh(3) = 0.1009, hh(2) = 0.1514, hh(1) = 0.1871, hh(0) = 1 0.2 = 0.8000, hh(1) = 0.1871, hh(2) = 0.1514, hh(3) = 0.1009. Each filter coefficient must be multiplied by the corresponding window coefficient. The Hamming window coefficients are given as follows. wH(1) = 0.31, wH(2) = 0.77, wH(3) = 1.0, wH(0) = 0.08, wH(5) = 0.31, wT(6) = 0.08. wH(4) = 0.77, Now intermediate filter coefficients are obtained by multiplying window coefficients. hi(0) = ha(0) wH(0) = 0.1009 0.08 = 0.0081 hi(1) = ha(1) wT(1) = 0.1514 0.31 = 0.0469 hi(2) = ha(2) wT(2) = 0.1871 0.77 = 0.1441 hi(3) = ha(3) wT(3) = 0.8000 1.0 = 0.8000 hi(4) = 0.1441, hi(5) = 0.0469, hi(6) = 0.0081. A highpass filter should satisfy H() =

h( n) e j ( ) n =
n=0

h(n)( 1)
n=0

= 1. Because

h (n)(1)
n =0 i

= 1.0106, the final digital filter is obtained by dividing hi(n) by

1.0106. h(0) = 0.0080, h(1) = 0.0464, h(2) = 0.1426, h(3) = 0.7917, h(4) = 0.1426, h(5) = 0.0464, h(6) = 0.1426.

3-33

3.10 Half-band LPF and HPF


H0() H1()

/2

Fig. 3.15 Half-band LPF and HPF frequency response

H1() = H0(). H0() =


N 1 n =0

h0 (n)e j () n = h0 (n)e jn e jn ,
n =0 n =0

N 1

N 1

H1() =

h ( n)e
1

j n

h1(n) = h0(n)ejn = (1)n h0(n).

3-34

Example 3.10.1

Design an 8-point FIR highpass filter with the cutoff frequency c = /2. Solution From Exercise 3.8.1 which is an 8-point half-band lowpass filter, one can simply change the sign of odd indexed coefficients to obtain a highpass filter. h(0) = 0.0721 h(1) = 0.1010 h(4) = 0.5048 h(5) = 0.1683 h(2) = 0.1683 h(3) = 0.5048 h(6) = 0.1010 h(7) = 0.0721

Note that the highpass filter we designed here is anti-symmetric.

3-35

MATLAB Examples

1. Design a 7-point FIR filter with the cutoff frequency of 0.2 using the rectangular window (the rectangular window is called the boxcar window in MATLAB).
h = fir1(6,0.2,boxcar(7)) h = 0.0935 0.1403 0.1734 0.1854 0.1734 0.1403 0.0935

2. Plot the frequency response of the filter above.


freqz(h,1)
0 M agnitude Res pons e (dB ) -20 -40 -60 -80 -100 0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

Normalized frequency (Nyquist == 1)

100 50 P has e (degrees ) 0 -50 -100 -150 -200 0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

Normalized frequency (Nyquist == 1)

3. Design a 15-point highpass filter with the cutoff frequency of 0.6 using the Hamming window.
h = fir1(14,0.6,'high',hamming(15)); freqz(h,1)

4. The lowpass IIR filter h(n) = 0.9nu(n) = {1, 0.9, 0.81,


j

}has discrete-time

Fourier transform H() = 1/(10.9e ). Normalize all plots so that the gain at dc is 1, i.e. H(0) = 1. (a) Plot |H()|.
H = 1 ./(1 - 0.9*exp(-j*2*pi*.01*(0:99))); % Evaluation of H() at % 100 points between 0 and 2 H = abs(H); % Magnitude of H H = H/H(1); % For normalization

(b) Truncate h(n) to length 10 to obtain h10(n). Compute and plot |H10()|. Observe and explain the phenomenon resulting from the discontinuity of the rectangular window.
h10 = 0.9 .^(0:9); H10 = abs( fft(h10, 100) ); H10 = H10/H10(1); % % % % Select first ten samples of h(n) Pad 90 zeros to h10 to make 100-point DFT that will make a plot smoother Normalization

3-36

(c) Use a rectangular window of length 20. Compute and plot |H20()| on the same graph. Compare the ripples in |H10()| and |H20()|.
h20 = 0.9 .^(0:19); H20 = abs( fft(h20, 100) ); H20 = H20/H20(1); % Select first twenty samples of h(n)

(d) To reduce the ripple, repeat using the Hamming window. Compare the ripples to those in (b) and (c).
w10 = hamming(10); % Get 10-point hamming window coefficients for n=1:10, hh10(n) = h10(n)*w10(n); % Loop to get a windowed sequence end HH10 = abs( fft(hh10, 100) ); HH10 = HH10/HH10(1);

3-37

3.11 Implementation of FIR filters

buffer:

x(n)

x(n1)

x(n2)

x(nM+1)

x(nM)

filter coefficients: h(0)

h(1)

h(2)

h(M1)

h(M)

y(n)

Fig. 3.16 Implementation of a digital FIR filter.

#include <stdio.h> #define N 16 void main() { int n; double buf[N], h[N], output; FILE *in, *out; in = fopen("signal.dat", "r"); out = fopen("out.dat", "w"); h[0] =-0.0024; h[1] =-0.0042; // LPF coefficients h[2] = 0.0095; h[3] = 0.0200; h[4] =-0.0380; h[5] =-0.0696; h[6] = 0.1374; h[7] = 0.4472; for (n=0; n<=7; n++) h[N-1-n] = h[n]; // Copy h[8] - h[15] for (n=0; n<N; n++) buf[n] = 0.; // Initialize buffer with zeros while ( !feof(in) ) // As long as there is data in the file, { // the filtering process is continued. fscanf (in, "%lf\n", &buf[0]); // Get sample and put it in buffer output = 0.; // Initialize output for (n=0; n<N; n++) output = output + h[n]*buf[n]; // Current output fprintf (out, "%f\n", output); // Print output for (n=N-1; n>0; n--) buf[n] = buf[n-1]; // Update buffer } fclose(in); fclose(out); }

3-38

C Program Example 3.1

The following C program is to compute coefficients of the16-point FIR lowpass filter (with c = 0.5) using three different windows. The magnitude response of each filter is computed.
/******************************************** * Lowpass Fiter Design Using Windows * ********************************************/ #include <stdio.h> #include <math.h> #define PI 3.1415926536 #define N 100 void magdft(double x[], double mag[]); void main() { int n; double hrec[16], hham[16], hbla[16], x[N], mag[N], arg; double norm1, norm2, norm3; FILE *filter, *out1, *out2, *out3; filter = fopen("filter.dat", "w"); out1 = fopen("rect.dat", "w"); out2 = fopen("hamm.dat", "w"); out3 = fopen("blac.dat", "w"); for (n=0; n<=7; n++) /* LPF design with rectangular window */ { arg = (.5 + n) * 0.5 * PI; /* argument for sinc function */ hrec[8+n] = .5 * sin(arg)/arg; /* 0.5*sinc(arg) */ hrec[7-n] = hrec[8+n]; /* Use even symmetric property */ } for (n=0; n<=15; n++) /* Compute LPF coefficients */ { hham[n] = hrec[n]*(0.54 - 0.46*cos(2*PI*n/15) ); /* Hamming */ hbla[n] = hrec[n]*(.42 - .5*cos(2*PI*n/15) + .08*cos(4*PI*n/15) ); /* Blackman */ } norm1 = norm2 = norm3 = 0.; for (n=0; n<=15; n++) /* Find the frequency response at dc */ { norm1 = norm1 + hrec[n]; norm2 = norm2 + hham[n]; norm3 = norm3 + hbla[n]; } for (n=0; n<=15; n++) /* Normalize filter coefficients */ { hrec[n] = hrec[n]/norm1; hham[n] = hham[n]/norm2; hbla[n] = hbla[n]/norm3; } fprintf (filter, "\tRectangular\tHamming\t\tBlackman\n"); for (n=0; n<=15; n++) fprintf(filter, "%d\t%f\t%f \t%f\n",n,hrec[n],hham[n],hbla[n]); for (n=16; n<N; n++) x[n] = 0.0; /* Pad extra zeros out */ for (n=0; n<=15; n++) x[n] = hrec[n]; /* Copy rectangular filter coefficients */ magdft (x, mag); /* Magnitude response of LPF rectangular window */ for (n=0; n<N; n++) fprintf (out1, "%f\n", mag[n]); for (n=0; n<=15; n++) x[n] = hham[n]; /* Copy Hamming filter coefficients */ magdft (x, mag); /* Magnitude response of LPF using Hamming */ for (n=0; n<N; n++) fprintf (out2, "%f\n", mag[n]); for (n=0; n<=15; n++) x[n] = hbla[n]; /* Copy Blackman filter coefficients */ magdft (x, mag); /* Magnitude response of LPF using Blackman */ for (n=0; n<N; n++) fprintf (out3, "%f\n", mag[n]); fclose(filter); fclose(out1); fclose(out2); fclose(out3); }

3-39

void magdft(double x[], double mag[]) { int n, k; double XR[N], XI[N]; for (k=0; k<N; k++) { XR[k]=0; XI[k]=0.; for (n=0; n<N; n++) { XR[k] = XR[k] + x[n]*cos(2.*PI*k*n/N); XI[k] = XI[k] - x[n]*sin(2.*PI*k*n/N); } mag[k] = XR[k]*XR[k] + XI[k]*XI[k]; mag[k] = 10.*log10(mag[k]); } } Filter coefficients (filter.dat) are given below. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Rectangular -0.031779 -0.036668 0.043335 0.052965 -0.068098 -0.095337 0.158896 0.476687 0.476687 0.158896 -0.095337 -0.068098 0.052965 0.043335 -0.036668 -0.031779 Hamming -0.002409 -0.004162 0.009536 0.019971 -0.037954 -0.069573 0.137361 0.447230 0.447230 0.137361 -0.069573 -0.037954 0.019971 0.009536 -0.004162 -0.002409 Blackman 0.000000 -0.000580 0.003153 0.010040 -0.025333 -0.056707 0.127400 0.442026 0.442026 0.127400 -0.056707 -0.025333 0.010040 0.003153 -0.000580 0.000000

20 0 -20 -40 -60 -80 0

20 0 -20 -40 -60 -80 0


(b) Hamming

20 0 -20 -40 -60 -80 0


(c) Blackman

(a) Rectangular

Fig. P.3.1 Various FIR lowpass filters.

3-40

C Program Example 3.2

The following C program computes the outputs of both the lowpass and highpass filters at the same time. The half-band lowpass filter (Hamming window) was obtained from the previous example. Because the lowpass and the highpass filters share the same filter coefficients and only the odd-indexed coefficients have different signs, the number of multiplications can be reduced. In this program, we decompose the convolution into two summations: one for the even indices and the other for the odd indices. Lowpass out for each n = =

m =0

h( m) x ( n m)
h( m) x ( n m) +
m odd

m even

h ( m) x ( n m)

= even(n) + odd(n) Now the highpass filter output becomes Highpass out for each n = even(n) odd(n).
#include #define #define <stdio.h> 16 15

N N1

void main() { int n; double buf[N], h[N], even, odd, low, high; FILE *in, *out1, *out2; in = fopen("signal.dat", "r"); out1 = fopen("lpf.dat", "w"); out2 = fopen("hpf.dat", "w"); h[0] =-0.0024; h[1] =-0.0042; /* LPF coefficients */ h[2] = 0.0095; h[3] = 0.0200; h[4] =-0.0380; h[5] =-0.0696; h[6] = 0.1374; h[7] = 0.4472; for (n=0; n<=7; n++) h[N1-n] = h[n]; /* Copy h[8] - h[15] */ for (n=0; n<=N1; n++) buf[n] = 0.; /* Initialize buffer with zero */ while ( !feof(in) ) /* As long as there is data in the file, */ { /* the filtering process is continued. */ fscanf (in, "%lf\n", &buf[0]); even = odd = 0.; for (n=0; n<N; n=n+2) even = even + h[n]*buf[n]; /* Even indexed coefficients*/ for (n=1; n<N; n=n+2) odd = odd + h[n]*buf[n]; /* Odd indexed coefficients */ low = even + odd; /* LPF output */ high = even - odd; /* HPF output */ fprintf (out1, "%f\n", low); fprintf (out2, "%f\n", high); for (n=N1; n>0; n--) buf[n] = buf[n-1]; /* Update buffer */ } fclose(in); fclose(out1); fclose(out2); }

3-41

Computer Assignment 3.1

1. Write a C program to generate a signal and store it in signal.dat: s(n) = 2cos[2(.05)n] + sin[2(.2)n] for n = 0, 1, , 255. 2. Find the discrete Fourier transform S(k) using a C program with your own function void dft() whose input is s(n) and output are the real and imaginary parts of S (k ) = s (n)e j 2 nk / N
n =0 N 1

for k = 0, 1, , 255 and plot the magnitude and phase spectra. Choose N to be 256. 3. Write a C program to design 16-point FIR lowpass filters with the cutoff frequency of 0.2 using the rectangular, Hamming, and Blackman windows. Compute and plot the magnitude and the phase response of each filter. Try N = 1000. 4. Write a C program to implement the FIR lowpass filter. Use s(n) of part 1 as the input and find the output of the filter. Plot the input and the output.

3-42

PROBLEMS
1. Find the z-transform of the following and sketch the pole-zero plot. (a) x(n) = 0.8nu(n) (b) x(n) = [0.5n + (0.4)n]u(n) (c) x(n) = 0.5nu(n2) + (0.4)nu(n) (d) x(n) = 0.8n [u(n) u(n10)] 1 2 0.1z 1 1 0.5 z 1 0.25 z 2 0.1z 3 (c) (b) (1 0.5 z 1 )(1 + 0.4 z 1 ) (1 0.5 z 1 )(1 + 0.4 z 1 ) 1 0.8z 1

Ans.

(a)

1 0.810 z 10 (d) 1 0.8 z 1 2. Find the inverse z-transform of the following. (a) X(z) = 1 , ROC: |z| > 0.8 z 0.8 1 0.5z 1 , ROC |z| > 0.5 1 + 0.75z 1 + 0125z 2 . 1 0.5z 1 , ROC: |z| > 0.25 1 0.25z 1

(b) X(z) =

(c) X(z) =

Ans. (a) 0.8n1u(n1) (b) [4(0.5)n 3(0.25)n]u(n) (c) 0.25nu(n) 0.25nu(n1)

3.

Find the inverse z-transform of H(z) =

4 . 1.75z +.125z 2
1

4.

Find the z-transform of a double-sided sequence p(n) = e0.1|n| and the region of convergence.

3-43

Ans.

1 1 e
0.1 1

1 , ROC: e 0.1 < z < e0.1 0.1 1 1 e z

5.

A continuous-time signal x(t) = 5e0.4tu(t) where u(t) is the unit step function. (a) Find the Laplace transform of x(t). Find the pole. (b) The signal x(t) is sampled at every 0.2[s]. Find the z-transform of the discrete-time signal. Find the pole. Consider an LTI discrete-time system whose input-output relationship is described by the following difference equation. y(n) = 0.8y(n1) + 3x(n). (a) Find the transfer function of the system. (b) Find the impulse response of the system.

6.

7.

An LTI systems input-output relation is described by y(n) = 0.8y(n1) + 2x(n1). (a) Find the impulse response of the system for n = 1, 2, 3, 4, 5 by inputting a unit impulse input. (b) Find the transfer function H(z) of the system. (c) Find the expression of the impulse response h(n). The LTI discrete-time systems input-output relation is given by y(n) = 1.25y(n1) .375y(n2) + x(n). (a) Find the impulse response of the system for n = 0, 1, 2, 3 by inputting a unit impulse. (b) Find the impulse response by taking the inverse z-transform of the transfer function.
Ans.

8.

(a) h(0) = 1, h(1) = 1.25, h(2) = 1.1875, h(3) = 1.0156 (b) 3(.75)n 2(.5)nu(n)

9.

A causal LTI system has the frequency response: H() = 10 . 1 + j 0.1

Sketch the Bode plot.

3-44

10.

Find and sketch the frequency response of H(z) = 1 z1. What kind of filter is this? Find and sketch the frequency response of H(z) = (1 z1)/(1 .25z1). What kind of filter is this?
Ans.

11.

|H(0)| = 0, |H(/4)| = 0.909, |H(/2)| = 1.372, |H()| = 1.6

12.

Find and sketch the magnitude and phase responses of a system whose transfer function is specified by (a) H(z) = 1 + z1 (b) H(z) = 1 2z1 + z2. Find and sketch the magnitude response for the 3-point moving average filter with h(0) = 0.5, h(1) = h(1) = 0.25. Does it have zero phase, constant phase, or linear phase? Does this filter cause any delay? Is this filter causal? Sketch the magnitude response of H(z) = 1 + 2z1 + z2. What kind of filter is this? The impulse response of a filter is given by h(n) = 0.25(n) + 0.5(n1) 0.25(n2). (a) Carefully sketch the magnitude response. (b) Carefully sketch the phase response. (c) Find the 3-dB cutoff frequency. (d) What kind of filter is it? (e) Find the delay of the filter. Design a 4-point FIR lowpass filter with the cutoff frequency of 0.3 using a Hamming window.
Ans.

13.

14.

15.

16.

{0.0350, 0.4650, 0.4650, 0.0350}

17.

Design a 5-point FIR highpass filter with the cutoff frequency of 0.7 using a Blackman window.
Ans.

{0.0000, 0.1843, 0.6314, 0.1843, 0.0000}

3-45

You might also like