$25
Program Assignment
1. Let π₯[π] = β[π] = (0.9)ππ’[π] and π¦[π] = π₯[π] ∗ β[π]
(a) Determine π¦[π] analytically and plot the first 99 non-zero samples using the stem function.
(b) Take first 50 samples of π₯[π] and β[π]. Compute and plot π¦[π] using the conv function.
(c) Using the filter function, determine and plot the first 99 samples of π¦[π].
(d) Which of the outputs in (b) and (c) come close to that in (a)? Explain.
2. The sum π΄π₯ β ∑π π₯[π] can be thought of as a measure of the “area” under a sequence x[n].
(a) Starting with the convolution sum (2.36), show that π΄π¦ = π΄π₯π΄β (derive in the live script).
(b) Given the sequences x=sin(2*pi*0.01*(0:100)) + 0.05*randn(1,101); h=ones(1,5);
compute y[n] = h[n] ∗ x[n], check whether π΄π¦ = π΄π₯π΄β, and use the subplot function plot x[n] and y[n] on the same graph.
(c) Normalize h[n] so that π΄β = 1 and repeat part (b).
(d) If π΄β = 1, then π΄π¦ = π΄π₯. Use this result to explain the difference between the plots obtained in parts (b) and (c).
3. The response of a LTI system to the input π₯[π] = π’[π] is π¦ .
(a) Find the impulse response β[π] of the system, and check the results using the function filter.
(b) Plot the pole-zero pattern using the function zplane(b, a).
(c) Compute and plot the impulse response using the functions filter and stem. Compare with the plot obtained using the function impz.
(d) Use the function residuez and the z-transform pairs in Table 3.1 to find an analytical expression for the impulse response h[n].
4. Find the impulse response of the system (3.97) for the case of real and equal poles and use the result to determine how the location of the poles affects (a) the stability of the system, and (b) the shape of the impulse response. (Hint: Use MATLAB to replicate Figure 3.10 for a double pole, find C and discuss stability of the three cases |π1| < πΆ, |π1| = πΆ, |π1| πΆ)
5. Consider the following LCCDE:
π¦[π] = 2πππ (π0)π¦[π − 1] − π¦[π − 2],
with no input but with initial conditions π¦[−1] = 0 and π¦[−2] = −π΄π ππ(π0).
(a) Show that the solution of the above LCCDE is given by the sequence
π¦[π] = π΄ ⋅ π ππ[(π + 1)π0] ⋅ π’[π].
This system is known as a digital oscillator (derive in the live script).
(b) For π΄ = 2 and π0 = 0.1π, verify the operation of the above digital oscillator using the filtic and the filter function. (Hint: Check one-sided z-transform in supplement)
6. In this problem we illustrate the numerical evaluation of DTFS using MATLAB.
(a) Write a function c=dtfs0(x) which computes the DTFS coefficients (4.67) of a periodic signal and verify the result with dtfs function.
(b) Write a function x=idtfs0(c) which computes the inverse DTFS (4.63) and verify the result with idtfs function.
7. Determine and plot the magnitude and phase spectra of the following periodic sequences:
(b) x2[n] = {1, 1, 0, 1, 1, 1, 0, 1}, (one period)
↑
(one period)
8. Consider a noncausal finite length sequence x[n] = δ[n + 1] + δ[n] + δ[n − 1], we can compute the DTFT in MATLAB using following scripts:
x=[1 1 1]; % n=-1,0,1 om=linspace(-pi, pi, 60); X1=dtft12(x, -1, om); X2=freqz(x, 1, om);
(a) Use subplot to plot the magnitude |X1|, |X2| and phase ∠X1, ∠X2 in one graph respectively.
(b) Is the magnitude |X1| = |X2| ? Is the phase ∠X1 = ∠X2 ? If not, Explain.
9. In this problem use the image file “DSP.png” which has 100×300 pixels (unsigned 8 bits per pixel). You can use the following MATLAB script to load, show and store the image files:
img = imread('DSP.png'); imshow(img); imwrite(img, 'DSP0.png');
(a) Consider the 5×5 impulse response h[m, n] given as follow:
π, π ≤ 2
,
0 , ππ‘βπππ€ππ π
filter the “DSP.png” using (2.78) and display the resulting image, comment on the result. (Hint:
You can directly use conv2 function, and make sure the data format is double before filtering). (b) Repeat part (a) and try two different kernels β1[π, π] and β2[π, π]: (known as Sobel filter)
1 0 −1 1 2 1
β1[π, π] = [2 0 −2], β2[π, π] = [ 0 0 0 ],
1 0 −1 −1 −2 −1
what is the difference between the two results? (Hint: You should do abs and uint8 before imshow) (c) Repeat (b) by using filter2 function, what is the difference between the two functions? (Hint: Check the pixel values before abs)
10. This problem uses the sound file “handel.wav” available in MATLAB. This sound is sampled at Fs = 8192 samples per second using 8-bits per sample. You can use the following MATLAB script to load, play and store the audio files:
[y,Fs] = audioread('handel.wav'); playerObj = audioplayer(y, Fs); play(playerObj); audiowrite('handel0.wav', y, Fs);
(a) Select every other sample in audio signal y which reduces the sampling rate by a factor of two. Now listen to the new sound array using the sound function at half the sampling rate. (Hint: You can use the logical array to index array elements)
(b) Select every fourth sample in audio signal y which reduces the sampling rate by a factor of four. Listen to the resulting sound array using the sound function at quarter the sampling rate.
(c) From the results of (a) and (b), what do you discover?
II Reference
1. Formula 2.36
2. Formula 3.97
3. Figure 3.10
4. Table 3.1
5. Formula 4.67
6. Formula 4.63
7. Formula 2.78
III Supplement
Β One-Sided Z Transform (It is not included in this course, but important in realistic discrete system) In some practical case (only have one-sided sequence x[n] and initial condition), our solutions require the one-sided or unilateral z-transform, defined by the formula:
The one-sided z-transform has the following characteristics:
1. It does not contain information about the signal π₯[π] for negative values of time (i.e., for n<0)
2. It is unique only for causal signals, because only these signals are zero for n<0.
3. The one-sided z-transform π+(π§) of π₯[π] is identical to the two-sided z-transform X(π§) of the signal π₯[π]π’[π].
4. ROC of π+(π§) is always the exterior of the circle, so it is not necessary to refer to their ROC.
(More details in the textbook, chapter 3.8)
β» One-Sided Z-Transform of Two-Order LCCDE
We can define two-order linear constant-coefficient difference equation (LCCDE) as follows:
π¦[π] = π0π₯[π] + π1π₯[π − 1] + π2π₯[π − 2] − π1π¦[π − 1] − π2π¦[π − 2],
Apply one-sided z-transform, we have
π+(π§) = π 0+π1π§−−11++ππ2π§π§−−22 π+(π§) + ( π2π₯[−1]−π2π¦[−1])π§−1+1+(ππ1π₯π§[−−11+]+ππ2π§π₯−[2−2]−π1π¦[−1]−π2π¦[−2])
1+π π§
,
1 2 1 2