Вы находитесь на странице: 1из 11

EE113: Digital Signal Processing Prepared by Prof.

Mihaela van der Schaar, Martin Andersen, and Hyunggon Park

Spring 2008 Project Solution

Project Problems
Problem 1. Voiced and Unvoiced Speech Answer the questions in the Exercise section of Voiced and Unvoiced Speech.

Problem 2. Time and Frequency Representations Answer the questions in the Exercise section of Time and Frequency Representations.

Problem 3. Sampling and Aliasing Answer the questions in the Exercise section of Sampling and Aliasing.

Problem 4. Signal Quantization and Compression Answer the questions in the Exercise section of Signal Quantization and Compression.

Problem 5. Touch Tone Telephone Answer the questions in the Exercise section of Touch Tone Telephone. Note that these questions require you to use MATLAB.

Problem 6. IIR and FIR Filters Answer the questions in the Exercise section of IIR and FIR Filters.

(Problem 7 on next page.) 1

Problem 7. System Analysis using Matlab The system H is given by a cascade of two causal systems H1 and H2 . H1 H2

Each of the systems H1 and H2 is described by a second order dierence equation, i.e., H1 is described by a01 y(n) + a11 y(n 1) + a21 y(n 2) = b01 x(n) + b11 x(n 1) + b21 x(n 2) and H2 is described by a02 y(n) + a12 y(n 1) + a22 y(n 2) = b02 x(n) + b12 x(n 1) + b22 x(n 2). The coecients are: H1 1.000000 0.795431 0.636625 0.315014 0.148538 0.315014 H2 1.000000 0.237906 0.100460 0.481253 0.544432 0.481253

a01 = a11 = a21 = b01 = b11 = b21 =

a02 = a12 = a22 = b02 = b12 = b22 =

1. Use the z-transform to nd the transfer functions H1 (z), H2 (z), and H(z). Solution: H1 (z) = b01 + b11 z 1 + b21 z 2 , a01 + a11 z 1 + a21 z 2 H2 (z) = b02 + b12 z 1 + b22 z 2 , a02 + a12 z 1 + a22 z 2 H(z) = H1 (z)H2 (z).

2. For each of the three transfer functions, use Matlab to nd and plot the zeros and the poles. Which of the systems are stable? Hint: you may use the zplane function. Solution: MATLAB code: a1 b1 a2 b2 = = = = [1.000000 [0.315014 [1.000000 [0.481253 -0.795431 -0.148538 -0.237906 0.544432 0.636625]; 0.315014]; 0.100460]; 0.481253];

figure(1) zplane(b1,a1) figure(2) zplane(b2,a2) figure(3) zplane(conv(b1,b2),conv(a1,a2)) 2

1 Imaginary Part Imaginary Part -1

-1 0 Real Part
(a) H1 (z)

-1 1 -1 0 Real Part
(b) H2 (z)

1 Imaginary Part

-1 -1 0 Real Part
(c) H(z)

Figure 1: Pole/zero plots (problem 7.2). Fig. 1 shows that all three systems are stable (all poles are inside the unit circle). 3. Use Matlab to compute and plot the magnitude response |H(ej )| (in dB) and the phase response H(ej ). Is the system lowpass, highpass, bandpass, or bandstop? Hint: you may use the functions freqz and angle. Solution: MATLAB code: [H1,w1] = freqz(b1,a1); [H2,w2] = freqz(b2,a2); [H,w] = freqz(conv(b1,b2),conv(a1,a2)); figure(4) subplot(2,1,1) plot(w1/pi,20*log10(abs(H1))); grid on; subplot(2,1,2) plot(w1/pi,angle(H1)); grid on figure(5) subplot(2,1,1) plot(w2/pi,20*log10(abs(H2))); grid on; subplot(2,1,2) plot(w2/pi,angle(H2)); grid on figure(6) subplot(2,1,1) 3

plot(w/pi,20*log10(abs(H))); grid on; subplot(2,1,2) plot(w/pi,angle(H));grid on


|H1 (ej )| [dB] 0 |H2 (ej )| [dB] 20 0 -20 -40 5 0 -5 0 0.5 Normalized frequency (b) H2 (z) 1 0 0.5 1

-50 5 0 -5 0 0.5 Normalized frequency (a) H1 (z) |H(ej )| [dB] 0 1 0 0.5 1

H1 (ej )

-50 5 0 -5 0 0.5 Normalized frequency (c) H(z) 1 0 0.5 1

Figure 2: Magnitude and phase response (problem 7.3). The magnitude and phase plots are shown in Fig. 2. The system H(z) is lowpass. 4. Compute and plot the rst 30 values of the impulse response h(n). Hint: apply h(n) to the sequence x(n) = (n). You may use the filter function. Solution: MATLAB code: x = zeros(30,1); x(1) = 1; h = filter(conv(b1,b2),conv(a1,a2),x); figure(7) stem(0:29,h) The impulse response is shown in Fig. 3. 5. Let H3 be a system with the transfer function H3 (z) = H(z). (a) Plot the poles and zeros of H3 (z). Is H3 stable? Can it be causal? Solution: H3 (z) = H1 (z)H2 (z) = b01 b11 z 1 + b21 z 2 b02 b12 z 1 + b22 z 2 . a01 a11 z 1 + a21 z 2 a02 a12 z 1 + a22 z 2

H(ej )

H2 (ej )

0.6

0.4 h(n)

0.2

-0.2

10 n

20

30

Figure 3: Impulse response h(n) (problem 7.4). MATLAB code: b3 = b1; b3(2) = -b3(2); b4 = b2; b4(2) = -b4(2); a3 = a1; a3(2) = -a3(2); a4 = a2; a4(2) = -a4(2); [H3,w3] = freqz(conv(b3,b4),conv(a3,a4)); figure(8) zplane(conv(b3,b4),conv(a3,a4)) The pole/zero plot is shown in Fig. 4. H3 (z) is clearly stable and can be causal.
|H3 (ej )| [dB]

1 Imaginary Part

-50 5 0 -5 0.5 1 Normalized frequency (b) Magnitude/phase response. 0 0 0.5 1

-1 -1 0 Real Part 1

(a) Poles/zeros of H3 (z).

Figure 4: H3 (z) (problem 7.5). (b) Plot magnitude response |H3 (ej )| (in dB) and the phase response H3 (ej ). Solution: MATLAB code: figure(9) subplot(2,1,1) plot(w3/pi,20*log10(abs(H3))); grid on subplot(2,1,2) plot(w3/pi,angle(H3)); grid on The magnitude/phase response is shown in Fig. 4. 5

H3 (ej )

(c) Describe how H3 (ej ) is related to H(ej )? Justify why this is the case. Solution: The function H(z) is the mirror image of H(z), i.e., a reection against the imaginary axis. The frequency response H3 (ej ) can be written as H(z)|z=ej = H(ej ) = H(ej() ) which can be thought of as a frequency shift. Since the frequency response is periodic with period 2, the shift eectively reverts the frequency axis such that H3 (ej ) is highpass. 6. Compute and plot the rst 30 values of the impulse response h3 (n). Describe how h3 (n) is related to h(n), and justify your answer. Solution: MATLAB code: h3 = filter(conv(b3,b4),conv(a3,a4),x); figure(10) stem(0:29,h3) The impulse response h3 (n) is shown in Fig. 5.
0.4

0.2 h3 (n)

-0.2

-0.4

10 n

20

30

Figure 5: Impulse reponse h3 (n) (problem 7.6). Using the z-transform pair X as
z a

an x(n) we see that the impulse response h3 (n) is related to h(n) h3 (n) = (1)n h(n)

i.e., the odd samples of h(n) are multiplied by 1, and the even samples are the same. Hint: recall that you can compute the product of two polynomials by convolution (the function conv).

Problem 8. Enhancing an image with the Laplacian lter 1. Read the image named moon.tif and store it in a variable with a name of f in MATLAB. Plot the image in MATLAB. Hint: you may use the imread to read the image le and the imshow to plot the image. Solution: MATLAB Code: >> f = imread(moon.tif); >> figure >> imshow(f); Plot of image:

Figure 6: Plot of moon.tif. 2. What is the size of this image? Solution: 540 466. MATLAB Code: >> size(f) 3. What are the smallest and largest values of f?

Solution: smallest value = 0, largest value = 254. MATLAB Code: >> largest = max(max(f)) >> smallest = min(min(f)) 4. Show the values included in f(x,y): (a) For x = 1 : 10 and y = 1 : 10. Solution: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

MATLAB Code: >> f(1:10, 1:10) (b) For x = 265 : 274 and y = 228 : 237. Solution: 110 109 117 111 121 113 119 115 119 117 119 118 115 114 115 112 114 113 115 112

111 111 112 115 117 116 115 116 119 117

110 111 114 119 123 122 117 114 122 122

114 114 118 120 121 124 123 118 124 124

114 114 118 120 121 124 123 118 124 124

116 116 122 123 118 114 115 117 120 119

121 120 126 128 121 113 111 111 110 110

123 122 125 128 124 117 113 111 110 112

124 124 125 127 125 118 112 113 115 118

MATLAB Code: >> f(265:274, 228:237) (c) Discuss why the values in the above two matrices are dierent considering the image. Solution: The locations of part (a) correspond to the most left and upper part of the image, which is black. Hence, the values in part (a) represent the pixel values that correspond to black. Note that pixel value of 0 in gray scale image represents the black.

The locations of part (b) correspond to the middle of the image, which has dierent levels of gray scales and are not black. Hence, the pixel values in part (b) are dierent from those of part (a). 5. Consider spatial mask w4. Apply spatial mask w4 to image f2, and store the output in a variable with a name of g4. (a) Plot g4 using imshow (g4, [ ]). Solution:

Figure 7: Plot of moon.tif. MATLAB Code: >> f2 = im2double(f); >> w4 = [ 0 1 0 ; 1 -4 1; 0 1 0]; >> g4 = imfilter(f2,w4); >> figure >> imshow(g4, [ ]) (b) What can you observe in the ltered image g4? Solution: The edges of the image are emphasized. (c) What is the impact of the ltering with w4 on the image? Solution: This is a high-pass ltered image.

(d) Explain the ltering eect based on the form of w4 matrix. Solution: As discussed in problem statement, w4 represents 2 f (x, y) = [f (x + 1, y) + f (x 1, y) + f (x, y + 1) + f (x, y 1)] 4f (x, y), which implements a derivative operator. Hence, it sharpens the image but drives constant areas to zero. 6. Substract the ltered image g4 from the original image f2, and store the output in a variable with a name of g. (a) Plot original image f2 and image g. Solution:

image f2

image g

Figure 8: Plot of image f2 and image g. MATLAB Code: >> >> >> >> g = f2 - g4; figure subplot(1, 2, 1); imshow(f2); title(image f2); subplot(1, 2, 2); imshow(g); title(image g);

(b) What can you observe in the two images f2 and g? Discuss the dierence between them. Solution: Image g is a sharpened version of image f2. 7. Consider spatial mask w8. Apply spatial mask w8 to image f2, and store the output in a variable with a name of g8. Substract the ltered image g8 from the original image f2, and store the output in a variable with a name of h. 10

(a) Plot original image f2, image g, and image h.

image f2

image g

image h

(a) image f2

(b) image g

(c) image h

MATLAB Code: >> >> >> >> >> >> >> >> >> >> >> >> w8 = [ 1 1 1 ; 1 -8 1; 1 1 1]; g8 = imfilter(f2,w8) h = f2 - g8; figure imshow(f2); title(image f2); figure imshow(g); title(image g); figure imshow(h); title(image h);

(b) What can you observe in images f2, g, and h? Compare the dierence among them. Solution: Image g is a sharpened version of image f2, and image h is sharper than image g. (c) Explain the dierent ltering eects considering the form of w4 and w8 matrices. Solution: Like w4, spatial mask w8 also implements a derivative operator. However, w8 takes into account diagonal elements, which gives more sharpened image than w4.

11

Вам также может понравиться