10.07.2015 Views

Digital Signal Processing

Digital Signal Processing

Digital Signal Processing

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Digital</strong> <strong>Signal</strong> <strong>Processing</strong>/林 Reference: <strong>Digital</strong> <strong>Signal</strong> <strong>Processing</strong> Laboratory Using MatlabAuthor: Sanjit K. Mitra


Chapter 2 Discrete-Time Systems in the Time-Domain2.1 IntroductionA discrete-time system processes an input signal in the time-domain to generate an outputsignal with more desirable properties by applying an algorithm composed of simpleoperations on the input signal and its delayed versions.2.2 Background ReviewC1. For a linear discrete-time system, if y1[ n] and y2[ n ] are the responses to the inputsequences x1[ n] and x2[ n ] , respectively, then for an inputx[ n] = α x1[ n]+β x2[ n](2.1)the response is given byyn [ ] = α y1[ n]+β y2[ n](2.2)The superposition property of Eq. (2.2) must hold for any arbitrary constant α and βand for all possible inputs x1[ n] and x2[ n ].C2. For a time-invariant discrete-time system, if y[ n ] is the responses to an input x [ n ],1 1then the response to an inputx[ n] = x1[ n−n0]is simplyyn [ ] = y1[ n−n0]where n0is any positive or negative integer.C3. A linear time-invariant (LTI) discrete-time system satisfies both the linearity andthe time-invariance properties.C4. If y1[ n] and y2[ n ] are the responses of a causal discrete-time system to the inputsu1[ n] and u2[ n ], respectively, thenu1[ n] = u2[ n] for n


esponse hn [ ] to an input signal x[ n ] is given by∞yn [ ] = ∑ hkxn [ ] [ −k](2.3)k =−∞which can be alternately∞yn [ ] = ∑ hn [ −kxk] [ ](2.4)k =−∞The sum in Eqs. (2.3) and (2.4) is called the convolution sum of the sequences x[ n ]and hn [ ], and is represented compactly as:yn [ ] = hn [ ] ∗ xn [ ] = xn [ ] ∗ hn [ ](2.5)C8. The overall impulse response by hn [ ] of the LTI discrete-time system obtained by acascade connection of two LTI discrete-time systems with impulse responses h 1[ n ]and h [ ] 2n , respectively, and as shown in Figure 2.1, is given byhn [ ] = h1[ n] ∗ h2[ n](2.6)If the two LTI systems in the cascade connection of Figure 2.1 are such thath1[ n] ∗ h2[ n] = δ[ n](2.7)then the system h 2[ n ] is said to be the inverse of the LTI system h 1[ n ] and viceverse.h[ n ] 1h [ n]≡ h [ n]h[ n]≡ h2 2 1 1[ n] ∗h2[n]Figure 2.1 The cascade connectionC9. An LTI discrete-time system is BIBO stable if and only if its impulse responsesequence { hn [ ]}is absolutely summable, that is∞∑ hn [ ] < ∞(2.8)n=−∞C10. An LTI discrete-time system is causal if and only if its impulse response sequence{ hn [ ]}satisfies the conditionhk [ ] = 0 for k< 0(2.9)C11. The class of LTI discrete-time systems with which we shall be mostly concerned inthis lecture is characterized by a linear constant coefficient difference equation ofthe formNM∑d y[ n− k] = ∑ pkx[ n−k](2.10)kk= 0 k=0where x[ n] and y[ n ] are, respectively, the input and the output of the system,d and p are constants. The order of the discrete-time systemand { k} { k}is max ( NM , ), which is the order of the difference equation characterizing thesystem. If we assume the system to be causal, then we can rewrite Eq. (2.9) to3


express yn [ ] explicitly as a function of x[ n ]:NMdkpkyn [ ] =−∑ yn [ − k] + ∑ xn [ −k](2.11)k= 1 d0 k=0 d0provided d0 ≠ 0 . The output yn [ ] can be computed using Eq. (2.10) for all n≥n0knowing x[ n ] and the initial conditions yn [0−1], yn [0−2], , yn [0−N]C12. A discrete-time system is called a finite impulse response (FIR) system if itsimpulse response hn [ ] is of finite length. Otherwise, it is an infinite impulseresponse (IIR) system. The causal system of Eq. (2.11) represents an FIR system ifd = 0 for k > 0 . Otherwise, it is IIR system.k2.3 Simulation of Discrete-time SystemsFor the simulation of causal LTI discrete-time systems described by Eq. (2.10), thecommand filter can be used. If we denotenum = [ p0 p1 pM]den = [ d0 d1 dN]then y = filter(num, den, x) generates an output vector y of the same length as thespecified input vector x with zero initial conditions i.e., y[ − 1] = y[ − 2] = = y[ − N] = 0.The output can also be computed using y = filter(num, den, x, ic) where ic is the vectorof initial conditions. i.e., ic = [ y[ −1], y[ −2], , y[ −N]]. Access to final conditions isobtained using [y, fc] = filter(num, den, x, ic)Project 1: The Moving Average SystemA causal M-point smoothing FIR filter is defined asM −11yn [ ] = ∑ xn [ −k](2.12)M k = 0The system of Eq. (2.12) is also known as a moving average filter. We illustrate its usein filtering high-frequency components from a signal composed of a sum of severalsinusoidal signals.Program P2_1:% Program P2_1% Simulation of an M-point Moving Average Filter% Generate the input signaln = 0:100;s1 = cos(2*pi*0.05*n); % A low-frequency sinusoids2 = cos(2*pi*0.47*n); % A high frequency sinusoidx = s1+s2;% Implementation of the moving average filterM = input('Desired length of the filter = ');num = ones(1,M);4


y = filter(num,1,x)/M;% Display the input and output signalsclf;subplot(2,2,1);plot(n, s1);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('<strong>Signal</strong> #1');subplot(2,2,2);plot(n, s2);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('<strong>Signal</strong> #2');subplot(2,2,3);plot(n, x);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('Input <strong>Signal</strong>');subplot(2,2,4);plot(n, y);axis([0, 100, -2, 2]);xlabel('Time index n'); ylabel('Amplitude');title('Output <strong>Signal</strong>');axis;Questions:Q1 Run the above program for M = 2 to generate the output signal withx[ n] = s1[ n] + s2[ n]as the input. Which component of the input x[ n ] is suppressedby the discrete-time system simulated by this program?Q2 If the linear time-invariant system is changed from yn [ ] = 0.5( xn [ ] + xn [ −1])toyn [ ] = 0.5( xn [ ] −xn[ −1]),what is its effect on the input x[ n] = s1[ n] + s2[ n]?Q3 Run Program P2_1 for other values of filter length M, and various values of thefrequencies of the sinusoidal signals s1[ n] and s2[ n ]. Comment on your results..Project 2: A Simple Nonlinear Discrete-time SystemGiven the nonlinear system as follows:2yn [ ] = xn [ ] −xn [ − 1] xn [ + 1](2.13)The following program is used to generate the output signal yn [ ] for different types ofthe input x[ n ].5


Program P2_2:%Program P2_2clf;n = 0:200;x = cos(2*pi*0.05*n);% Compute the output signalx1 = [x 0 0]; % x1[n] = x[n+1]x2 = [0 x 0]; % x2[n] = x[n]x3 = [0 0 x]; % x3[n] = x[n-1]y = x2.*x2-x1.*x3;y = y(2:202);% Plot the input and output signalssubplot(2,1,1)plot(n, x)xlabel('Time index n');ylabel('Amplitude');title('Input <strong>Signal</strong>')subplot(2,1,2)plot(n,y)xlabel('Time index n');ylabel('Amplitude');title('Output signal');Questions:Q4 Use sinusoidal signals with different frequencies as the input signals and computethe output signal for each input. How do the output signals depend on thefrequencies of the input signals? Verify your observation mathematically.Q5 Use sinusoidal signals of the form x[ n] = sin(ω0n)+ k as the input signal andcompute the output signal? How does the output signal yn [ ] depend on the DCvalue kProject 3: Linear and Nonlinear SystemsWe now investigate the linearity property of a causal system of the type described by Eq.(2.10). Consider the system given byyn [ ] −0.4 yn [ − 1] + 0.75 yn [ − 2] = 2.2403 xn [ ] + 2.4908 xn [ − 1] + 2.2403 xn [ − 2] (2.14)Program P2_3: To generate three different input sequences x1[ n], x2[ n ] andx[ n] = ax1[ n] + bx2[ n],and to compute and plot the correspondingoutput sequences y 1[ n], y 2[ n ] and yn [ ].% Program P2_3% Generate the input sequencesclf;6


n = 0:40;a = 2;b = -3;x1 = cos(2*pi*0.1*n);x2 = cos(2*pi*0.4*n);x = a*x1 + b*x2;num = [2.2403 2.4908 2.2403];den = [1 -0.4 0.75];ic = [0 0]; % Set zero initial conditionsy1 = filter(num,den,x1,ic); % Compute the output y1[n]y2 = filter(num,den,x2,ic); % Compute the output y2[n]y = filter(num,den,x,ic); % Compute the output y[n]yt = a*y1 + b*y2;d = y - yt; % Compute the difference output d[n]% Plot the outputs and the difference signalsubplot(3,1,1)stem(n,y);ylabel('Amplitude');title('Output Due to Weighted Input: a \cdot x_{1}[n] + b \cdot x_{2}[n]');subplot(3,1,2)stem(n,yt);ylabel('Amplitude');title('Weighted Output: a \cdot y_{1}[n] + b \cdot y_{2}[n]');subplot(3,1,3)stem(n,d);xlabel('Time index n');ylabel('Amplitude');title('Difference <strong>Signal</strong>');Questions:Q6 Run Program P2_3 and compare yn [ ] obtained with weighted input withyt[ n]obtained by combining the two outputs y 1[ n] and y 2[ n ] with the sameweights. Are these two sequences equal? Is this system linear?Q7 Repeat Q6 with nonzero initial condition.Q8 Consider another system described by:yn [ ] = xnxn [ ] [ − 1]Modify Program P2_3 to compute yn [ ], y1[ n] and y2[ n ] of the above system.Compare yn [ ] with yt[ n ] . Are these two sequences equal? Is this system linear?Project 4: Time-Invariant and Time-Varying SystemsProgram P2_4 is used to simulate the system Eq. (2-14) to generate two different input7


sequences x[ n] and x[ n- d ] , and to compute and plot the corresponding output sequencesy1[ n] and y2[ n ], and the difference y 1[ n] − y 2[ n+ d].Program P2_4:% Program P2_4% Generate the input sequencesclf;n = 0:40; D = 10;a = 3.0;b = -2;x = a*cos(2*pi*0.1*n) + b*cos(2*pi*0.4*n);xd = [zeros(1,D) x];num = [2.2403 2.4908 2.2403];den = [1 -0.4 0.75];ic = [0 0]; % Set initial conditions% Compute the output y[n]y = filter(num,den,x,ic);% Compute the output yd[n]yd = filter(num,den,xd,ic);% Compute the difference output d[n]d = y - yd(1+D:41+D);% Plot the outputssubplot(3,1,1)stem(n,y);ylabel('Amplitude');title('Output y[n]'); grid;subplot(3,1,2)stem(n,yd(1:41));ylabel('Amplitude');title(['Output due to Delayed Input x[n ‘, num2str(D),']']); grid;subplot(3,1,3)stem(n,d);xlabel('Time index n'); ylabel('Amplitude');title('Difference <strong>Signal</strong>'); grid;Questions:Q9 Run Program P2_4 and compare the output sequences yn [ ] and ydn− [ 10] . Whatis the relation between these two sequences? Is this system time-invariant?Q10 Repeat Q9 for nonzero initial conditions. Is this system time-invariant?Q11 Consider another system described by:yn [ ] = nxn [ ] + xn [ − 1](2-15)8


Modify Program P2_4 to simulate the above system and determine whether thissystem is time-invariant or not?Q12 Modify Program P2_3 to test the linearity of the system of Eq. (2-15)?Project 5: Computation of Impulse Responses of LTI SystemsThe Matlab command y = impz( num, den, N)can be used to compute the first N samplesof the impulse response of the causal LTI discrete-time of Eq. (2-11)Program 2_5% Program P2_5% Compute the impulse response yclf;N = 40;num = [2.2403 2.4908 2.2403];den = [1 -0.4 0.75];y = impz(num,den,N);% Plot the impulse responsestem(y);xlabel('Time index n'); ylabel('Amplitude');title('Impulse Response'); grid;Questions:Q13 Run Program P2_5 and generate the impulse response of the discrete-timesystem of Eq. (2-14).Q14 Modify Program P2_5 to generate the first 45 samples of the impulse reponse ofthe following causal LTI systemyn [ ] + 0.71 yn [ −1] −0.46 yn [ −2] −0.63 yn [ −3](2.16)= 0.9 xn [ ] −0.45 xn [ − 1] + 0.35 xn [ − 2] + 0.002 xn [ −3]Project 6: Cascade of LTI SystemsIn practice a causal LTI discrete-time system of higher order is implemented as a cascadeof lower order causal LTI discrete-time systems. For example, the fourth-orderdiscrete-time system given belowyn [ ] + 1.6 yn [ − 1] + 2.28 yn [ − 2] + 1.325 yn [ − 3] + 0.68 yn [ −4](2.17)= 0.06 xn [ ] −0.19 xn [ − 1] + 0.27 xn [ −2] −0.26 xn [ − 3] + 0.12 xn [ −4]can be realized as a cascade of two second-order discrete-time systems:Stage No. 1y[ n] + 0.9 y[ n− 1] + 0.8 y[ n− 2] = 0.3 xn [ ] −0.3 xn [ − 1] + 0.4 xn [ − 2] (2.18)1 1 1Stage No. 1y [ n] + 0.7 y [ n− 1] + 0.85 y [ n− 2] = 0.2 y[ n] −0.5 y[ n− 1] + 0.3 y[ n− 2] (2.19)2 2 2 1 1 19


Program 2_6 simulates the fourth-order system of Eq. (2.17), and cascade system of Eqs.(2.18) and (2.19). Its first generates a sequence x[ n ], and then uses it as the input of thefourth-order system, generating the output yn [ ] . It then applies the same input x[ n ] toStage No. 1 and finds its output sequence y 1[ n ]. Next, it uses y 1[ n ] as the input of StageNo. 2 and finds its output y [ ] 2n . Finally, the difference between the two overalloutputs yn [ ] and y 2[ n ] are formed.Program 2_6% Program P2_6% Cascade Realizationclf;x = [1 zeros(1,40)]; % Generate the inputn = 0:40;% Coefficients of 4th order systemden = [1 1.6 2.28 1.325 0.68];num = [0.06 -0.19 0.27 -0.26 0.12];% Compute the output of 4th order systemy = filter(num,den,x);% Coefficients of the two 2nd order systemsnum1 = [0.3 -0.2 0.4];den1 = [1 0.9 0.8];num2 = [0.2 -0.5 0.3];den2 = [1 0.7 0.85];% Output y1[n] of the first stage in the cascadey1 = filter(num1,den1,x);% Output y2[n] of the second stage in the cascadey2 = filter(num2,den2,y1);% Difference between y[n] and y2[n]d = y - y2;% Plot output and difference signalssubplot(3,1,1);stem(n,y);ylabel('Amplitude');title('Output of 4th order Realization'); grid;subplot(3,1,2);stem(n,y2)ylabel('Amplitude');title('Output of Cascade Realization'); grid;subplot(3,1,3);stem(n,d)xlabel('Time index n');ylabel('Amplitude');10


title('Difference <strong>Signal</strong>'); grid;Questions:Q15 Run Program P2_6 to compute the output sequences yn [ ] and y2[ n ] and thedifference signal dn. [ ] Is yn [ ] the same as y2[ n ]?Q16 Repeat Q15 with the input changed to a sinusoidal sequence.Q17 Repeat Q15 with arbitrary nonzero initial condition vectors ic, ic1, and ic2.Project 7: ConvolutionThe convolution operation is implemented in MATLAB by the command conv, providedthe two sequences to be convolved are of finite length.Program 2_7% Program P2_7clf;h = [3 2 1 -2 1 0 -4 0 3]; % impulse responsex = [1 -2 3 -4 3 2 1]; % input sequencey = conv(h,x);n = 0:14;subplot(2,1,1);stem(n,y);xlabel('Time index n'); ylabel('Amplitude');title('Output Obtained by Convolution'); grid;x1 = [x zeros(1,8)];y1 = filter(h,1,x1);subplot(2,1,2);stem(n,y1);xlabel('Time index n'); ylabel('Amplitude');title('Output Generated by Filtering'); grid;Questions:Q18 Run Program P2_7 to generate yn [ ] obtained by the convolution of thesequences hn [ ] and x[ n ] , and to generate y1[ n ] obtained by the filtering theinput x[ n ] by the FIR filter hn [ ] . Is there any difference between yn [ ]and y1[ n ] . What is the reason for using x1[ n ] obtained by zero-padding x[ n ]as the input for generating y1[ n ] .Project 8: Stability of LTI SystemsAn LTI discrete-time system is BIBO stable if its impulse response is absolutelysummable. Program P2_8 is a simple program used to compute the sum of the absolutevalues of the impulse response samples of a causal IIR LTI system. Its compute N11


samples of the impulse response sequence, evaluatesKSK ( ) = ∑ hn [ ]n=0for increasing K, and checks the value of hK [ ] at each iteration step. If the value ofhK [ ] is smaller thanvery close to S( ∞ ) .Program 2_8610 − , then it is assumed that the sum SK ( ) has converged and is% Program P2_8% Stability test based on the sum of the absolute% values of the impulse response samplesclf;num = [1 -0.8]; den = [1 1.5 0.9];N = 200;h = impz(num,den,N+1);parsum = 0;for k = 1:N+1;parsum = parsum + abs(h(k));if abs(h(k)) < 10^(-6), break, endend% Plot the impulse responsen = 0:N;stem(n,h)xlabel('Time index n'); ylabel('Amplitude');% Print the value of abs(h(k))disp('Value =');disp(abs(h(k)));Questions:Q19 What are the purposes of the commands for, end and break?Q20 What is the discrete-time system whose impulse response is being determined byProgram P2_8? Run Program P2_8 to generate the impulse response. Is thissystem stable? If hK [ ] is not smaller than610 − but the plot shows a decayingimpulse response, run Program P2_8 again with a larger value of N.Q21 Consider the following discrete-time system characterized by the differenceequation:yn [ ] = xn [ ] −4 xn [ − 1] + 3 xn [ − 2] + 1.7 yn [ −1] − yn [ − 2]Modify Program P2_8 to compute and plot the impulse response of the above12


system. Is this system stable?Project 9: Illustration of the Filtering ConceptConsider the following two discrete-time systems characterized by the differenceequations:System No. 1yn [ ] = 0.5 xn [ ] + 0.27 xn [ − 1] + 0.77 xn [ − 2]System No. 2yn [ ] = 0.45 xn [ ] + 0.5 xn [ − 1] + 0.45 xn [ − 2] + 0.53 yn [ −1] −0.46 yn [ − 2]Program P2_9 is used to compute the outputs of the above two systems for an input⎛20πn⎞ ⎛200πn⎞xn [ ] = cos⎜ ⎟+ cos ⎜ ⎟, with 0 ≤ n


signal. Which filter has better characteristics for suppression of thehigh-frequency component of the input signal x[ n ]?Q23 Modify Program P2_9 by changing the input sequence to a swept sinusoidalsequence (length 301, minimum frequency 0, and maximum frequency 0.5).Which filter has better characteristics for suppression of the high-frequencycomponent?14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!