Sei sulla pagina 1di 4

2005 Spring

Middle East Technical University Electrical & Electronics Engineering Department

Plot the impulse response of the systems using stem(.) and subplot(.) command of Matlab on the same figure window.

(a) 1 Imaginary Part 0.5 0 -0.5 -1 -1

(b)

Imaginary Part

EE 430 Computer Assignment # 4


Given: May 13, 2005 Due: May 31, 2005 Time: 23:59

0.5

-0.5

-1

(Please read the notes at the end of the assignment for required file formats to use during preparation and submission)
Imaginary Part

-0.5 0 0.5 Real Part (c) 1 0.5 0 -0.5 -1 -1 4

-1

-0.5 0 0.5 Real Part (d)

Imaginary Part

0.5

In this computer assignment, you will deal with properties of minimum-phase systems (Q-1), magnitude and phase response compensation using minimum-phase and all-pass systems (Q-2) and basic properties of random signals (Q-3 and Q-4). 1. (25pts) In this question, you will observe some of the properties of the minimum-phase systems. Systems that you will deal with have been taken from Sec. 5.6 of your textbook. For detailed information about the properties of minimum-phase systems, you can consult Chapter 5 of your textbook. a. In this first part, you are required to generate impulse responses of 4 different systems whose pole-zero maps are given in the Figure 1. In Figure 1, zeros of the four systems are at 0 .9 e j 0 .6 , 0 .8 e j 0.8 and at their reciprocals. Note that, given the pole-zero maps of the systems, system transfer functions are given up to a constant multiplier. It is therefore assumed that the overall energy contained in the impulse responses of the four systems are unity. Therefore, after finding the impulse responses of the filters, you are required to normalize them to unit energy, i.e. the sum of square magnitude of the responses should be 1. Now, realizing that these 4 filters have finite impulse responses, generate 4 impulse response sequences h1[n], h2[n], h3[n] and h4[n] corresponding to the four systems described in the Figure 1. a, b, c, and d respectively. Hint: For this purpose, you can first generate the 4 element arrays which contain the 4 zeros of each corresponding system. Of course, the zeros are complex and therefore you have to use the variable i as a complex variable not an integer in Matlab. When not initialized as an integer, the variable name i is assigned to complex variable j that the electrical engineers frequently use. Making use of also the exp(.) function of Matlab, you can easily generate 4 element root (i.e zero) array. Then inputting these arrays into the poly(.) function of the Matlab, you can generate the coefficients of the impulse response. Note that this is not the only way. There may be many trivial methods to do the same job. Every possible method is acceptable as well as the analytical calculation. Dont forget to normalize your coefficients to unit energy. 1

-0.5

-1

-0.5 0 0.5 Real Part

-1

-0.5 0 0.5 Real Part

Figure 1. Four systems, all having the same frequency-response magnitude. Zeros are at all combinations of 0 .9 e j 0.6 and 0 .8 e j 0.8 and their reciprocals. All four poles of the systems are at the origin. The figure is the same as the Figure 5.30 in your textbook

b. Now, take the 200 point DFT of the impulse responses using zero padding. Observe the magnitude response of each system using now plot(.) and subplot(.) command on the same figure window. What do you observe in the magnitude characteristics? c.

Now, plot the corresponding phase responses of all 4 systems in the same graphic (on a single plot) on another figure using different colors. This can easily be accomplished using the options of the plot(.) command and the hold on command of Matlab.

Comment on the phase responses. Can you differentiate the minimum-phase system by just looking at their phases? Which one is the minimum-phase system? Explain briefly how you reached that result. Does this result agree with the pole-zero maps given in Figure 1.

d. Now, observe the group-delays of the systems using the grpdelay(.) function of Matlab. Plot the group delays of all 4 systems into the same graph as in part c using different colors. Comment about the group delays. What characteristic is satisfied by group delay of the minimum-phase system? At about which discrete frequencies is the group delay minimum? What about the magnitude attenuation at those values?

e. In this part of the question, you will observe the minimum energy delay property of the minimum-phase system. For this purpose, we define the partial energy of an impulse response h[n] as
PE h [n] = h[k]
k =0 n 2

Then the minimum energy delay property of the minimum-phase systems can be specified as PE h min [n] PE h min [n] where hmin[n] is the impulse response of the minimum-phase system whose magnitude response is the same as that of h[n]. Now, generate the partial energy sequences of the 4 systems given in Figure 1. You can make use of the cumsum(.) function of Matlab for easy calculation. Plot all four partial energy functions in to the same graph using different colors as in part c. Now, what about the partial energy function of the minimum-phase system? 2. (35pts) This question is related with magnitude and phase response compensation using minimumphase and all-pass systems. In many signal processing contexts, a signal is distorted by an LTI system with undesirable frequency response. In such situations, it may be reasonable to process the distorted signal by a suitably designed system to recover the original signal as much as possible. This compensation structure is shown in the following figure.
Original Signal x[n]

A is the array containing the coefficients of the polynomial (in increasing powers of the complex variable z-1) in the denominator of the transfer function of the filter. Since Hd(z) is a FIR filter you can take it as 1. The command zplane(.) works similarly except that the arrays A and B must be row vectors. If they are given as column vectors, Matlab considers the elements of the arrays as the zero and pole locations, not coefficients of a polynomial.

c. Obtain the distorted signal xd[n] using the Matlab command filter(.). Observe the distorted and the original signals in time domain on the same figure window using the Matlab command subplot(.).

Hint: The filter(.) function takes three inputs (in default mode), namely, B, A and x. B is the array containing the coefficients of the polynomial (in increasing powers of the complex variable z-1) in the numerator of the transfer function of the filter. You are required to find this array for Hd(z). You can do it using the poly(.) function as it is done in Question-1. A is the array containing the coefficients of the polynomial (in increasing powers of the complex variable z-1) in the denominator of the transfer function of the filter. Since Hd(z) is a FIR filter you can take it as 1. x is the input array we would like to filter.
Phase

Distorting System Hd(z)


xd[n]

Distorted Signal

Magnitude Compensated Signal Compensating System xmc[n] Hmc(z)

Magnitude

Phase Compensated Signal Compensating System xpc[n] Hpc(z)

d. Observe the frequency response characteristics (i.e, magnitude and phase characteristics) of the distorted signal.

a. We choose the original signal as


x[n] = 1 sin ( 0.2n ) for n = 0,..., 200 1 + 2n

Plot and observe this signal. Also observe the magnitude and phase characteristics of the signal on another figure window using the Matlab command subplot(.).
b. Let the system function Hd(z) of the distorting system be given as
H d ( z ) = (1 0.9e j 0.4 z 1 )(1 0.9e j 0.4 z 1 )(1 2e j 0.25 z 1 )(1 2e j 0.25 z 1 ) Obtain the pole-zero map of the system using the Matlab function zplane(.). Also, observe the frequency response of the distorting system using the Matlab function freqz(.).

Hint: The freqz(.) function takes two inputs (in default mode), namely, B and A. B is the array containing the coefficients of the polynomial (in increasing powers of the complex variable z-1) in the numerator of the transfer function of the filter. You are required to find this array for Hd(z). You can do it using the poly(.) function as it is done in Question-1. 3

e. Note that since the distorting system represented by Hd(z) is not minimum-phase its inverse system is either non-causal or unstable. Therefore, as the magnitude compensated system, we cannot use its direct inverse. Instead, we are going to decompose Hd(z) as H d ( z ) = H d _ min ( z ) H d _ ap ( z ) where the minimum-phase transfer function Hd_min(z) contains the zeros of Hd(z) that lie inside the unit circle plus the zeros that are conjugate reciprocals of the zeros of Hd(z) that lie outside the unit circle. The all-pass transfer function Hd_ap(z) is comprised of all the zeros of Hd(z) that lie the outside of the unit circle together with poles to cancel the reflected conjugate reciprocal zeros in Hd_min(z). After this decomposition, we are going to choose the magnitude compensating filter as 1 H mc ( z ) = H d _ min ( z ) This selection of the compensating filter compensates only for the magnitude distortion caused by the distorting system. Make this decomposition analytically and obtain the system function Hmc(z). Obtain the pole zero plot of the compensating system Hmc(z) using the Matlab command zplane(.). Also, observe the frequency response characteristics of the system using the freqz(.) command of Matlab.

Hint: Note that, while using the freqz(.) and zplane(.) functions, you must take B=1 and A as the denominator polynomial of Hmc(z). This is due to the fact that our filter Hmc(z) is an allpole filter unlike the case in part-c where our filter was an all-zero (i.e, FIR) filter.

f. Obtain the magnitude compensated signal xmc[n] from the distorted signal xd[n] using the Matlab command filter(.).Observe the magnitude compensated and the original signals in time domain on the same figure window using the Matlab command subplot(.). Hint: Note that, while using the filter(.) function, you must take B=1 and A as the denominator polynomial of Hmc(z). g. Superimpose the magnitude and phase characteristics of the original and the magnitude compensated signals on top of each other using the Matlab commands hold on and hold off. What are differences in magnitude and phase characteristics if any? h. In the previous parts of the question, we have compensated the magnitude distortion caused by the distorting system. In this part, we are going to compensate for the phase distortion caused by the distorting system. For this purpose, we are going to use the transfer function Hd_ap(z) found in part-e. you are required in this part to find the transfer function Hpc(z) of an all-pass filter whose zeros and poles are obtained from the zeros and the poles of the Hd_ap(z) as follows = r0 e j ( +0 ) Let z0 = r0e j0 be a zero of Hd_ap(z), then Hpc(z) has a zero at z0
= r0e j ( +0 ) Let p0 = r0e j0 be a pole of Hd_ap(z), then Hpc(z) has a pole at p0 This procedure is illustrated in the following figure.
Imaginary Axis

and the original signals in time domain on the same figure window using the Matlab command subplot(.).

j. Superimpose the magnitude and phase characteristics of the original and the phase compensated signals on top of each other as done in part-g. What are differences in magnitude and phase characteristics if any?

3. (15pts) In this question, you will observe some basic properties of the random signals. a.

Generate a random sequence x[n] of length 10000 using the randn(.) function of Matlab. Note that this function generates zero mean Gaussian random vectors with unity variance. Observe this signal in time domain using the stem function.

b. Now, try to see a rough estimate of shape of the probability density function of this sequence. For this purpose, generate a histogram for your sequence. Your histogram should have an horizontal axis range of [-4 , 4] with bins of length 0.1. Plot the histogram and comment on the resulting waveform.

Note: You can quantize your sequence values into nearest bin values by just multiplying your sequence by 10, rounding the resulting sequence to the nearest integer, and then dividing the rounded sequence by 10. You can use the hist() function of Matlab only for checking your work.

z0

p0 + 0
0

Real Axis

p0

c. Now, check the stationarity of your signal. For this purpose, you will observe the change of mean and variance characteristics of your signal with respect to time. Assuming that you have partitioned your signal into 20 frames of length 500, place the mean and variance information for these frames into two arrays. (Of course, you will not actually partition your signal, you should handle this in a for loop by selecting the initial and final sample values for the corresponding frames at each iteration). Now, plot these mean and variance characteristics and comment on the stationarity of your signal. Is it stationary, nearly stationary, or nonstationary? Note: You can make use of mean(.) and var(.) functions of Matlab in order to find the mean and variance of the frames. 4.

z0

(25pts) In this question, you will practice finding the autocorrelation functions of random signal and learn about the effects of linear systems on the autocorrelation functions and power spectral densities of random signals.
a.

Find the coefficients of the numerator and denominator polynomials of all-pass phasecompensating filter Hpc(z). Obtain the pole-zero plot of the phase compensating system Hpc(z) using the Matlab command zplane(.). Also, observe the frequency response characteristics of the system using the freqz(.) command of Matlab.
i. Obtain the phase compensated signal xpc[n] from the magnitude compensated signal xmc[n] using the Matlab command filter(.).Observe the phase compensated, magnitude compensated

Now, write a Matlab function named autocorr(x, S) which finds the autocorrelation function Rx[s] of a discrete-time signal x[n] for -SsS. Note that since we dont have an ensemble (a set of different realizations of the random process) for the signal, you have to use time averages to calculate the autocorrelation values. In other words, to find Rx[s], you will calculate the time average,
Rx [ s ] =

1 Ls x[i + s ]x[i ] for -SsS L s i =1

where L is the length of the sequence x[n].

b. Generate a zero-mean Gaussian random sequence of length 1000 as you did in Question-3. Assuming that your signal is Wide-Sense Stationary find its autocorrelation function Rx[s] for 10s10 using the function you have written in part-a. Observe the autocorrelation function and comment on it. Which samples of your sequence seem to be correlated (Those who could not implement part-a can use the built in function xcorr(.) of Matlab after examining its help). c.
Remembering the relation of power spectral density (PSD) of a signal to the autocorrelation function of it, find the PSD of your sequence using the autocorrelation sequence you generated in part-b. Observe and comment on it. Can you say that your sequence is white, why?

Note that the filter designed with fir2(.) function is a FIR filter. And therefore it has no poles other than at the origin (i.e, the denominator of the transfer function of our filter is a constant if the transfer function is written in terms of the complex variable z-1). Therefore, you can take A=1 and B as the output array supplied by the fir2(.) function.
e.

Repeat part-d with the filter pass-band being [0.38, 0.4]. What are the differences from partd?
Notes Related with the Homework:

d. Now, design a FIR filter of order 200 of band-pass characteristics with the pass-band [0.2, 0.4] using the Matlab function fir2(.). Then, filter your random signal with this filter using the Matlab function filter(.). Observe the filtered random signal. Do you see a change in the characteristics? Now, using the steady-state part of the filtered signal (i.e. after the first 200 samples) repeat part-b and part-c. Is the PSD different from the previous case? Hints: fir2(.) gets (in default mode) three input elements as N,F and M. N is the filter order which determines the number of samples in your FIR filter. You may assume a fixed filter order of N=100. F and M are two arrays which characterize the frequency response of the desired filter such that when you use the plot command as plot(F,M), the desired frequency response is plotted. The elements of the array F corresponds to normalized frequencies (between 0 and 1 corresponding to 0 and ) and specify the frequency breakpoints of the filter. The elements of the array M corresponds to the desired magnitude values of the filter at the frequency breakpoints specified in array F. note that the number of the elements in arrays F and M must be equal and elements in F must be non-decreasing. Also F must always contain the normalized frequency values 0 and 1.

1. Late submissions will not be accepted without the consent of the instructor.

2. This homework will be evaluated by Asst. Ycel ZBEK.

3. Prepare a single m-file for each question (not each part) and for required functions; (Your m-files will be named as ca#q#.m according to the assignment and the question number). For example, for this homework, you are required to prepare 4 main m-files named as {ca4q1, ca4q2, ca4q3, ca4q4} and the required function files. In these files, first use the command echo on for your comments and commands to be shown on the command window during execution. Note that before for loops, you have to close echo and after the loop you have to open it again to avoid unnecessary loop echoing during execution. Also, put after each plot and comment a pause command to make the execution slow enough to make evaluation easier. Assignments can be submitted only via m-files; thus, you have to write all your observations and comments into these files. 4.

corner frequency c = . Then the Matlab commands for doing this using fir2(.) 2 function is as follows, >>N=100; >>F=[0 1]; >>M=[0 0 1 1]; >>B= fir2(N,F,M)

Example: Suppose that you want to design a high-pass FIR filter of order N=100, with a

The method of submission is to send it via e-mail as an attachment file to the e-mail address umut@metu.edu.tr . Note that while submitting the homework, you must compress the homework files (using Winzip or compatible) into one file named as id_noCA4.zip . For example, if your id number is 102351-4, you will send only one compressed file named 102351CA4.zip with your email.
5.

Before submitting your homework, please execute them in a clear workspace (with only the needed variables for the programs. You can use clear command for obtaining this) and check if they are creating every variable required. Moreover, look at them as if you are the one who grades (surely, you will not like waiting for an array of length 1000 passing through the screen just because of a missing semi-colon). Comments should not be underestimated because they are the things that differentiate your homework from the one just composed of Matlab commands. Also, they will form a considerable percent of the grades.
6.

You may use the filter(.) function to perform the desired filtering. The filter(.) function takes three inputs (in default mode), namely, B, A and x. B is the array containing the coefficients of the polynomial (in increasing powers of the complex variable z-1) in the numerator of the transfer function of the filter. A is the array containing the coefficients of the polynomial (in increasing powers of the complex variable z-1) in the denominator of the transfer function of the filter. x is the input array we would like to filter.
7

Never hesitate to contact the assistants any time you want about homework. Also, e-mail communication is possible and surely encouraged with the address that is specified for submission. Any announcements related with the homework will be on the web page www.eee.metu.edu.tr/~umut

Good Luck Ycel ZBEK - Umut ORGUNER C-206 Tel: 4419 - C-211 Tel: 2374

Potrebbero piacerti anche