ECE4330 Lecture 21 Linear Discrete-Time Systems: Solution of Difference Equations by Iteration, by the Z-transform and by Convolution Prof. Mohamad Hassoun

Linear Time-Invariant Discrete-Time (LTID) System Analysis Consider a linear discrete-time system. We are interested in solving for the complete response 푦[푘] given the difference equation governing the system, its associated initial conditions and the input 푓[푘].

It will be shown that 푦[푘] is a sequence of numbers that can be obtained explicitly by simple recursion (iteration). Alternatively, an analytic solution of the linear difference equation can be obtained based on the Z- transform method. The analytic solution can also be obtained based on a systematic time-domain method, as covered in the next lecture.

There are two equivalent formulations for a difference equation: The advance operator formulation and the delay operator formulation. The following analysis illustrates how to convert one formulation to the other.

Delay Operator Formulation The following is an example of a delay formulation, second-order linear difference equation. Here, the 푦[푘] appears right shifted,

푦[푘] − 5푦[푘 − 1] + 6푦[푘 − 2] = 푓[푘 − 1] − 5푓[푘 − 2] (1) with the initial conditions 푦[−1] = 2 and 푦[−2] = 1. Let the input signal be the causal signal 푓[푘] = (3푘 + 5)푢[푘]. Solve for 푦[푘], 푘 ≥ 0

Advance Operator Formulation The advance operator formulation for the above difference equation can be obtained by simply shifting the difference equation so that the largest difference term 푦[푘 − 2] becomes 푦[푘]. Which requires replacing 푘 by 푘 + 2 throughout the equation, to obtain:

푦[푘 + 2] − 5푦[푘 + 1] + 6푦[푘] = 푓[푘 + 1] − 5푓[푘] (2)

Next, we need to establish a set of appropriate initial conditions, 푦[0] and 푦[1]. This can be done by setting 푘 to 0 and then to 1 in Equation (1) and solving for 푦[0] and 푦[1], respectively, as follows. Set 푘 = 0 in Eqn. (1) to obtain 푦[0],

푦[0] = 5푦[−1] − 6푦[−2] + 푓[−1] − 5푓[−2] 푦[0] = 5(2) − 6(1) + 0 − 0 = 10 − 6 → 푦[0] = 4 Set 푘 = 1 in Eqn. (1) to obtain 푦[1], 푦[1] = 5푦[0] − 6푦[−1] + 푓[0] − 5푓[−1] 푦[1] = 5(4) − 6(2) + 5 − 0 = 13 → 푦[1] = 13 It is important to note that when we derived the initial conditions for this system, one of them (푦[1]) depended on the input value 푓[0]. So we say that the initial conditions are tainted by the input. When that occurs, the advance formulation should be avoided if we are looking for decoupled solutions of the form 푦[푘] = 푦푧푠[푘] + 푦푧𝑖[푘]. This will be illustrated through an example later in this lecture.

Analysis Methods for Computing 푦[푘]  Iterative method (numerical solution; also works for non-linear systems)

 Z-transform method; allows for finding 푦푧푠[푘] and 푦푧𝑖[푘].  Time-domain convolution for finding 푦푧푠[푘]. (Refer to the last section.)  Time-domain analysis. (Refer to the classical method of solution of difference equations covered in Lecture 22.) Solve the above advance-formulation, second-order linear difference equation using the iterative method. First, we solve for the highest delay term in the difference equation to arrive at the recursion formula 푦[푘 + 2] = 5푦[푘 + 1] − 6푦[푘] + [3(푘 + 1) + 5]푢[푘 + 1] −5(3푘 + 5)푢[푘] and then start iterating with 푦[0] = 4 and 푦[1] = 13, as is shown below. 푘 = 0: 푦[2] = 5푦[1] − 6푦[0] + (3 + 5)(1) − 5(0 + 5)(1) 푦[2] = 5(13) − 6(4) + 8 − 25 = 24 푘 = 1: 푦[3] = 5푦[2] − 6푦[1] + (6 + 5)(1) − 5(3 + 5)(1) 푦[3] = 5(24) − 6(13) + 11 − 40 = 13 Repeat for 푘 = 2, 3, 4, … to generate the solution sequence (푘 ≥ 0) 푦[푘] = 4, 13, 24, 13, −120, …

Next, we illustrate the iterative solution applied to the delay formulation equation, Eqn. (1). First, we obtain the recursion formula for 푦[푘] as,

푦[푘] = 5푦[푘 − 1] − 6푦[푘 − 2] + (3푘 + 2)푢[푘 − 1] − 5(3푘 − 1)푢[푘 − 2] and start iterating with 푦[−1] = 2 and 푦[−2] = 1 as follows,

푘 = 0: 푦[0] = 5푦[−1] − 6푦[−2] + 2푢[−1] − 5(−1)푢[−2] 푦[0] = 5(2) − 6(1) + 0 + 0 푦[0] = 4 푘 = 1: 푦[1] = 5푦[0] − 6푦[−1] + 5푢[0] − 5(2)푢[−1] 푦[1] = 5(4) − 6(2) + 5 − 0 푦[1] = 13 Repeat for 푘 = 2, 3, 4, … to generate the solution sequence (푘 ≥ 0) 푦[푘] = 4, 13, 24, 13, −120, … This sequence is identical to the one obtained earlier using the advance formulation. Mathcad numerical solution for the advance operator difference equation (note: press ‘[‘ to input the subscript):

Mathcad numerical solution for the delay operator difference equation

Note how the above Mathcad solution automatically performs the required iterations to compute the sequence (vector) 푦. Mathcad allows the user to redefine the array origin. For the above delay operator recursion we had to set the origin at −2 in the Math Options menu, as illustrated below. (For the advance formulation solution the array origin has to be set to 0.)

Solving for the Complete Response 푦[푘] = 푦푧푠[푘] + 푦푧𝑖[푘] using the Z-Transform Method

The Z-transform method can be applied to the difference equation to (analytically) generate the complete response. However, if we intend to use it to generate the decoupled response 푦[푘] = 푦푧푠[푘] + 푦푧𝑖[푘], we have to make sure that the initial conditions we use are not dependent on the input signal. As pointed out earlier, one of the advance formulation initial conditions (for our example system) is dependent on the input. Therefore, for that advance formulation system the Z-transform method can be applied to generate 푦[푘], but not 푦푧푠[푘] and 푦푧𝑖[푘]. On the other hand, the Z- transform method can be used to generate 푦[푘] = 푦푧푠[푘] + 푦푧𝑖[푘] for the delay formulation system. Example. Z-transform analysis for the delay formulation system: 푦[푘] − 5푦[푘 − 1] + 6푦[푘 − 2] = 푓[푘 − 1] − 5푓[푘 − 2] 푦[−1] = 2 , 푦[−2] = 1 푓[푘] = (3푘 + 5)푢[푘]

We will find 푦푧푠[푘] first by Z-transforming the difference equation, assuming zero initial conditions, to obtain 퐻(푧) and then employ the formula,

−1 푦푧푠[푘] = 푍 {퐻(푧)퐹(푧)} But first, we must be clear about the meaning of the shifted 푦[푘 − 1] and 푦[푘 − 2]. Do they mean 푦[푘 − 1]푢[푘] and 푦[푘 − 2]푢[푘] or 푦[푘 − 1]푢[푘 − 1] and 푦[푘 − 2]푢[푘 − 2]? Well, since our Z-transform is one-sided it means that we are considering the situation for 푘 ≥ 0. So, every signal is assumed to be causal and is counted from 푘 = 0. Therefore, the terms 푦[푘 − 푚] mean 푦[푘 − 푚]푢[푘], for integer 푚. Transforming (and using the right-shift property) we obtain 1 1 1 푌(푧) − 5 ( 푌(푧) + 푦[−1]) + 6 ( 푌(푧) + 푦[−1] + 푦[−2]) 푧 푧2 푧 1 1 1 = ( 퐹(푧) + 푓[−1]) − 5 ( 퐹(푧) + 푓[−1] + 푓[−2]) 푧 푧2 푧 which, with the requirement that the initial conditions are zero (zero-state) and by noting that 푓[푘] is a causal signal {푓[−1] = 푓[−2] = 0}, reduces to 5 6 1 5 (1 − + ) 푌 (푧) = ( − ) 퐹(푧) 푧 푧2 푧푠 푧 푧2 Next, multiplying the above equation by 푧2, leads to

2 (푧 − 5푧 + 6)푌푧푠(푧) = (푧 − 5)퐹(푧) which has the form 푄(푧)푌푧푠(푧) = 푃(푧)퐹(푧). The is then, 푌 (푧) 푃(푧) 퐻(푧) ≜ 푧푠 = 퐹(푧) 푄(푧) which results in

푧−5 퐻(푧) = → The poles are at 푧 = 2 , 푧 = 3 (푧−2)(푧−3) 1 2

The system is unstable since |푧𝑖| > 1.

Before we proceed to solve for 푦푧푠[푘], let us determine the unit-, ℎ[푘] = 푍−1{퐻(푧)} 퐻(푧) First, perform partial fraction expansion on (say, using Mathcad): 푧 z  5 5 3 2 convert parfrac z    z(z  2) (z  3) 6z 2(z  2) 3(z  3) Next, multiply by z and use the table of Z-transforms to find the inverse Z- transform:

3 2 5 푧 푧 퐻(푧) = − + 2 − 3 6 푧 − 2 푧 − 3 5 3 2 ℎ[푘] = − 훿[푘] + (2)푘푢[푘] − (3)푘푢[푘] 6 2 3

The zero-state response 푦푧푠[푘] may now be obtained using convolution sums,

푦푧푠[푘] = ℎ[푘] ∗ 푓[푘] , where 푓[푘] = 3푘푢[푘] + 5푢[푘]

[Your turn: Employ the Convolution Table for discrete-time signals,

Page 590, to solve for 푦푧푠[푘]. Refer to the last section (last three slides of this lecture) for an example.]

Alternatively, we may use the inverse Z-transform to obtain 푦푧푠[푘] as follows,

−1 −1 푦푧푠[푘] = 푍 {푌푧푠(푧)} = 푍 {퐻(푧)퐹(푧)} 푧 − 5 푧(5푧 − 2) 푦 [푘] = 푍−1 { } 푧푠 (푧 − 2)(푧 − 3) (푧 − 1)2 where the following transform pair was used to obtain 퐹(푧), 3푧 5푧 푧(5푧 − 2) 푓[푘] = (3푘 + 5)푢[푘] ↔ 퐹(푧) = + = (푧 − 1)2 푧 − 1 (푧 − 1)2

푌 (푧) Your turn: Apply partial fraction expansion to 푧푠 , multiply the result 푧 by 푧, then employ the Z-transform Table to obtain the following result, 35 13 푦 [푘] = (− − 6푘 − (3)푘 + 24(2)푘) 푢[푘] 푧푠 2 2

Next, we solve for the zero-input response, 푦푧𝑖[푘].

Set 푓[푘] = 0 in the difference equation, 푦[푘] − 5푦[푘 − 1] + 6푦[푘 − 2] = 0 Apply the Z-transform (include the contribution due to initial conditions), 1 1 1 푌 (푧) − 5 ( 푌 (푧) + 푦[−1]) + 6 ( 푌 (푧) + 푦[−1] + 푦[−2]) = 0 푧𝑖 푧 푧𝑖 푧2 푧𝑖 푧 Rearrange terms so as to keep the equation in the form

푄(푧)푌푧𝑖(푧) + 퐼(푧) = 0 5 6 12 (1 − + ) 푌 (푧) + (−10 + + 6) = 0 푧 푧2 푧𝑖 푧 Multiply the equation by 푧2, 2 2 ⏟(푧 − 5푧 + 6 ) 푌푧𝑖(푧) + (−⏟ 4 푧 + 12 푧) = 0

푄(푧) 퐼(푧)

Now we solve for 푌푧𝑖(푧) in the form of a to obtain,

−퐼(푧) 4푧2 − 12푧 4푧(푧 − 3) 4푧 푌 (푧) = = = = 푧𝑖 푄(푧) 푧2 − 5푧 + 6 (푧 − 2)(푧 − 3) 푧 − 2

푘 and readily observe that the solution is 푦푧𝑖[푘] = 4(2) 푢[푘]. It is interesting to note that the specific initial conditions that we used have only excited one of the natural modes of the system [due to the cancellation of the (푧 − 3) term]. The complete (decoupled) response can now be expressed as,

푦[푘] = 푦푧푠[푘] + 푦푧𝑖[푘]

35 13 푦[푘] = (− − 6푘 − (3)푘 + 24(2)푘) 푢[푘] + ⏟4( 2 ) 푘푢 [푘 ] ⏟ 2 2

푦푧푠 푦푧𝑖

Mathcad Verification

Do not forget to multiply the above Mathcad answers by the discrete unit- step function, 푢[푘].

Suppose that we are only interested in the (coupled) complete response. Then, the solution is obtained as

Next, we apply the Z-transform method to the advance formulation system, 푦[푘 + 2] − 5푦[푘 + 1] + 6푦[푘] = 푓[푘 + 1] − 5푓[푘] where, 푦[0] = 4, 푦[1] = 13 and 푓[푘] = (3푘 + 5)푢[푘]. Remember that the signals 푦[푘 + 푚] and 푓[푘 + 푚] in the advance formulation stand for 푦[푘 + 푚]푢[푘] and 푓[푘 + 푚]푢[푘], respectively.

Because, in this case, one of the initial conditions depends on the input to the system, we can only obtain the coupled solution as follows, 푦[푘 + 2]푢[푘] ↔ 푧2푌(푧) − 푧2푦[0] − 푧푦[1] = 푧2푌(푧) − 4푧2 − 13푧 −5푦[푘 + 1]푢[푘] ↔ −5(푧푌(푧) − 푧푦[0]) = −5(푧푌(푧) − 4푧) 6푦[푘]푢[푘] ↔ 6푌(푧) 푧(5푧 − 2) 푓[푘]푢[푘] = (3푘 + 5)푢[푘] ↔ 퐹(푧) = (푧 − 1)2 푧(5푧 − 2) 푓[푘 + 1]푢[푘] ↔ 푧퐹(푧) − 푧푓[0] = 푧 − 5푧 (푧 − 1)2 Substituting the above expressions in the difference equation we get 푧(5푧 − 2) (푧2 − 5푧 + 6)푌(푧) + (−4푧2 − 13푧 + 20푧) = (푧 − 5) − 5푧 (푧 − 1)2

Solve (Your turn) for 푌(푧) as one lumped rational function to obtain 푁(푧) 푧(4푧3 − 15푧2 + 푧 − 2) 푌(푧) = = 퐷(푧) (푧 − 1)2(푧 − 2)(푧 − 3) 푌(푧) which, after applying partial fraction expansion to and then 푧 multiplying the result by 푧, leads to

35 13 6푧 푧 28푧 푧 푌(푧) = − − 2 + − 2 (푧 − 1)2 푧 − 1 푧 − 2 푧 − 3 Using the Z-transform Table leads to the following final result 35 13 푦[푘] = 푍−1{푌(푧)} = −6푘푢[푘] − 푢[푘] + 28(2)푘푢[푘] − 3푘푢[푘] 2 2 By inspecting the above solution, we can identify the natural and forced responses (but not the zero-state and zero-input. Why?) as 13 푦 [푘] = 28(2)푘푢[푘] − 3푘푢[푘] 푛 2 35 푦 [푘] = − 푢[푘] − 6푘푢[푘] 푓 2

Your turn: Show that if you are to find 푦푧푠[푘] and 푦푧𝑖[푘] using the advance formulation for this system it would result in the following wrong decomposition (it does not agree with the decoupled delay formulation solution that we obtained earlier):

푘 푘 푦푧𝑖[푘] = 5(3) 푢[푘] − (2) 푢[푘] 35 23 푦 [푘] = − 푢[푘] − 6푘푢[푘] − 3푘푢[푘] + 29(2)푘푢[푘] 푧푠 2 2 However, the total (coupled) response obtained by adding these two signals would still be correct:

푦[푘] = 푦푧𝑖[푘] + 푦푧푠[푘] = 35 13 = −6푘푢[푘] − 푢[푘] + 28(2)푘푢[푘] − 3푘푢[푘] 2 2 Example. Consider the three-point moving average LTID system 1 푦[푘] = (푓[푘] + 푓[푘 − 1] + 푓[푘 − 2]) 3 and the discrete-time input signal shown below.

a. Find the impulse-response ℎ[푘]. Is the system an FIR or IIR system? b. Find the zero-state response 푦[푘]. c. Verify and plot 푦[푘] employing Mathcad.

Solution: Applying the 푧-transform to the given recursion formula and using Pair 1 in the 푧-Transform Table we obtain (note that 푓[−1] = 푓[−2] = 0) 1 1 푌(푧) = [퐹(푧) + 푧−1퐹(푧) + 푧−2퐹(푧)] = (1 + 푧−1 + 푧−2)퐹(푧) 3 3 The transfer function is then 푌(푧) 1 퐻(푧) = = (1 + 푧−1 + 푧−2) 퐹(푧) 3 The impulse response is obtained by applying the inverse 푧-transform to the above expression to obtain 1 ℎ[푘] = ([훿] + 훿[푘 − 1] + 훿[푘 − 2]) 3 1 So, ℎ[푘] = for 푘 = 0,1,2 and zero otherwise. Therefore, the system has 3 a finite impulse response (FIR). The input is given by 푓[푘] = 훿[푘] + 2훿[푘 − 1] − 훿[푘 − 2] + 훿[푘 − 3] + 2훿[푘 − 4] which has a 푧-transform given by 퐹(푧) = 1 + 2푧−1 − 푧−2 + 푧−3 + 2푧−4 The zero-state response in the 푧-domain is 1 푌(푧) = 퐻(푧)퐹(푧) = (1 + 푧−1 + 푧−2)(1 + 2푧−1 − 푧−2 + 푧−3 + 2푧−4) 3 1 = (1 + 3푧−1 + 2푧−2 + 2푧−3 + 2푧−4 + 3푧−5 + 2푧−6) 3 Applying the inverse 푧-tarnsform gives the zero-state response 1 2 2 2 푦[푘] = 훿[푘] + 훿[푘 − 1] + 훿[푘 − 2] + 훿[푘 − 3] + 훿[푘 − 4] + 훿[푘 − 5] 3 3 3 3 2 + 훿[푘 − 6] 3 From the definition of the discrete-time unit-impulse function, we can express the response as the sequence (starting at 푘 = 0) 1 2 2 2 2 푦[푘] = { , 1, , , , 1, , 0,0, … } 3 3 3 3 3

Your turn: Show that the above sequence is identical to the one obtained using manual averaging of the input signal. Mathcad verification session for the three-point moving average system:

Since averaging is a form of low-pass filtering we see how the system supresses the sharp variations in the input signal.

Example. Determine the unit-impulse response for the following difference equation, 푦[푘] − 2푦[푘 − 1] + 2푦[푘 − 2] = 푓[푘] We will first obtain the transfer function employing the formula 푌(푧) 퐻(푧) = | 퐹(푧) 퐼.퐶.=0 Z-transforming the equation (while setting initial conditions to zero) gives 1 1 푌(푧) − 2 ( 푌(푧)) + 2 ( 푌(푧)) = 퐹(푧) 푧 푧2 2 2 ( − + 1) 푌(푧) = 퐹(푧) 푧2 푧 푌(푧) 1 푧2 퐻(푧) = = 2 2 = 퐹(푧) − + 1 푧2 − 2푧 + 2 푧2 푧

The poles are at 푧1,2 = 1 ± 푗. This system is unstable since |푧𝑖| = √2 > 1. 퐻(푧) has complex conjugate poles. Therefore, we employ the Z-transform Pair 12c to find the unit-impulse response ℎ[푘], 퐴푧2 + 퐵푧 ↔ 푟푏푘 cos(훽푘 + 휃) 푢[푘], 푏 > 0 푧2 + 2푎푧 + 푏2 where,

퐴2푏2 + 퐵2 − 2퐴푎퐵 −푎 푟 = √ , 훽 = cos−1 ( ) 푏2 − 푎2 푏

퐴푎 − 퐵 휃 = tan−1 ( ) 퐴√푏2 − 푎2 By matching coefficients in 퐴푧2 + 퐵푧 푧2 = 푧2 + 2푎푧 + 푏2 푧2 − 2푧 + 2 we obtain,

퐴 = 1, 퐵 = 0, 푏2 = 2 → 푏 = +√2 and 푎 = −1. Then we use the above formulas to compute 푟, 훽 and 휃, as follows, 1 휋 푟 = √2, 훽 = cos−1 ( ) = √2 4 −1 − 0 휋 휃 = tan−1 ( ) = tan−1(−1) = − 1√2 − 1 4 Therefore,

푘 휋 휋 휋 휋 ℎ[푘] = √2(√2) cos ( 푘 − ) 푢[푘] = (√2)푘+1cos ( 푘 − ) 푢[푘], 푘 ≥ 0 4 4 4 4

The system has an infinite impulse response (IIR). The first six output values are

We can employ Simulink to solve the system (numerically) as shown below.

Alternative time-domain Simulink solution:

Your turn: Solve numerically for the first 10 terms of the sequence generated by the following recursion formula, 푢푛+2 = 4푢푛+1 − 8푢푛. Assume that 푢0 = 푢1 = 1. Then, employ the Z-transform method to find the expression for the 푛th term, 푢푛. Note: The above recursion formula can also be represented as the second-order homogeneous LTI difference equation 푦[푛 + 2] − 4푦[푛 + 1] + 8푦[푛] = 0, with 푦[0] = 푦[1] = 1.

3푛 −1 푛휋 푛휋 Ans. 푢 = 2 2 [2cos ( ) − sin ( )] , 푛 ≥ 0 푛 4 4 The Amortization Problem. If you purchase a car, or a house, and take a loan of 푑 dollars, with fixed annual interest rate, 푅 (i.e., a rate of 푟 = 푅/12 per month), then the loan is paid back through the process known in economics as amortization. Let us say you will be making fixed payments of 푝 dollars every month. What should your monthly payment be if you want to pay the entire loan within 푁 months? (Typically, 푁 = 48 for a car and 푁 = 180, 240 or 360 for a house).

Well, the outstanding principal at the end of a given month, 푦[푘 + 1], is equal to the outstanding principal from the previous month, 푦[푘], plus the monthly interest accrued on that principal, 푟푦[푘], minus the monthly payment, 푓[푘]. We may express the above statement analytically as a recursive formula (difference equation): 푦[푘 + 1] = 푦[푘] + 푟푦[푘] − 푓[푘] which amounts to the difference equation 푦[푘 + 1] − (1 + 푟)푦[푘] = −푓[푘] With monthly payments (system input) 푓[푘] = 푝푢[푘] and initial principal, 푦[0] = 푑. Applying the Z-transform to the difference equation we get 푧푌(푧) − 푧푦[0] − (1 + 푟)푌(푧) = −퐹(푧)

푝푧 Solving for 푌(푧) and substituting 퐹(푧) = and 푦[0] = 푑, we obtain 푧−1 −푝푧 푑푧 푌(푧) = + [푧 − (1 + 푟)](푧 − 1) 푧 − (1 + 푟) 푌(푧) Performing pfe on , we get 푧

푌(푧) 푝 1 푝 1 푑 = (− ) + ( ) + 푧 푟 푧 − (1 + 푟) 푟 푧 − 1 푧 − (1 + 푟) 푝 1 푝 1 = (푑 − ) ( ) + ( ) 푟 푧 − (1 + 푟) 푟 푧 − 1

Next, applying the inverse Z-transform 푝 푧 푝 푧 푦[푘] = 푍−1 {(푑 − ) ( ) + ( ) } 푟 푧 − (1 + 푟) 푟 푧 − 1 leads to the desired solution for the owed principal after 푘 months, 푝 푝 푦[푘] = ((푑 − ) (1 + 푟)푘 + ) 푢[푘] 푟 푟 If the loan is supposed to be paid back in full after 푁 months, then we can solve for the required monthly payment by setting 푦[푁] = 0 in the above equation to obtain, 푝 푝 ((푑 − ) (1 + 푟)푁 + ) = 0 푟 푟 which has the following solution for the monthly payment 푟(1 + 푟)푁 푝 = 푑 (1 + 푟)푁 − 1

For example, assume you get approved for a 30 year (360 months) $300,000 mortgage at an annual rate, 푅 = 4%. Then, the monthly payment would be

0.04 0.04 360 ( ) (1 + ) 푝 = 12 12 (300,000) = $1,432.25 0.04 360 (1 + ) − 1 12

The principal after 20 years is 1,432.25 1,432.25 푦[240] = (300,000 − ) (1 + 0.04/12)240 + = $141,461.67 0.04/12 0.04/12 The total cost of the mortgage is 360푝 = 360($1432.25) = $515,610 which means that in this scenario your $300,000 house will coast you an additional $515,610 − $300,000 = $215,610 in interest!

Online calculators are available to solve the amortization problem. They use the same equations that were derived above. Here is one example:

Your turn. National income is the total value a country’s output of all new goods and services produced in one year. The national income for year 푘, 푦[푘], is governed by the following (Samuelson model) set of difference equations [Paul Samuelson (1915-2009) a Nobel Prize-winning economist]: 푦[푘] = 푐[푘] + 푖[푘] + 푓[푘] 푐[푘] = 푎푦[푘 − 1] 푖[푘] = 푏(푐[푘] − 푐[푘 − 1]) where 푎 and 푏 are positive constants, 푐[푘] represents consumer expenditures, 푖[푘] is the induced private investment (new investment stimulated by an increase in demand), and 푓[푘] represents government expenditures.

Apply the Z-transform to the above system of equations and show that the transfer function is given by 푌(푧) 푧2 퐻(푧) = = 퐹(푧) 푧2 − 푎(1 + 푏)푧 + 푎푏 Assume that the government makes a sustained expenditure of 1 (trillion dollars), 푓[푘] = 푢[푘]. Also, assume that the consumer’s “propensity to consume coefficient” is 푎 = 0.8 (i.e., consumer expenditures are 80% of the national income). Solve for and plot 푦푧푠[푘] for 푏 = 0, 0.25, 0.5 and 0.9. Discuss the effects of the induced private investment “acceleration coefficient” 푏 on the national income. What will the national income be after many years? How does 푏 affect that value? Numerical Integration: Trapezoidal Rule as a LTID System Consider the integral (for convenience, we set the lower limit to zero)

푡 푦푡푟푢푒(푡) = ∫ 푓(휏)푑휏 0 The trapezoidal rule for numerical integration leads to a discrete-time ( ) ( )| approximation 푦 푡푘 ≅ 푦푡푟푢푒 푡 푡푘 according to the recursion ℎ 푦(푡 ) = 푦(푡 ) + [푓(푡 ) + 푓(푡 )] 푘+1 푘 2 푘+1 푘 where 푘 is an integer representing the iteration number, and 푦(0) = 0. The idea is to approximate the incremental area under the curve using a ℎ trapezoid of area [푓(푡 ) + 푓(푡 )]. The trapezoid’s base, ℎ = 푡 − 2 푘+1 푘 푘+1 푡푘, is a small positive constant (sampling period, ℎ = 푇푠) defined by the user, as shown in the figure below.

An analysis based on Taylor series expansion leads to the total relative truncation error after 푛 iterations, at time 푡푘 = 푛ℎ, for (refer to Lecture 19 of Prof. Hassoun’s Numerical Methods course for detailed derivation)

We may compute an expression for the absolute relative error at 푡푘 as,

푦 (푡 ) − 푦(푡 ) 1 푓′(푡 ) − 푓′(0) | 푡푟푢푒 푘 푘 | ≅ ℎ2 | 푘 | ( ) 푦푡푟푢푒 푡푘 12 푦푡푟푢푒(푡푘)

This result holds for any differentiable function 푓(푡). The important thing to realize is that the trapezoidal rule has an error that is proportional to ℎ2; i.e., the error is 푂(ℎ2). It is interesting to note that if 푓(푡) is linear (its derivative is a constant for all 푡) then 푓′(푡) − 푓′(0) = 0. Thus, the trapezoidal rule is exact when integrating linear functions.

If we assume the sinusoid 푓(푡) = sin(휔표푡), then the true value of the integral is 푡 1 푦푡푟푢푒(푡) = ∫ sin(휔표휏) 푑휏 = (1 − cos(휔표푡)) 0 휔표 and it can be easily shown that

( ) ( ) 푦푡푟푢푒 푡푘 − 푦 푡푘 1 2 2 | | ≅ ℎ 휔표 푦푡푟푢푒(푡푘) 12

This last result makes qualitative sense: as 휔표 increases it causes the signal to have sharper variations and, therefore, the sampling interval, ℎ must be reduced in order for the error not to increase. This result is consistent with sampling theory (refer to Lecture 13).

Next, we treat the trapezoidal rule as a difference equation and solve it for one specific function, 푓(푡) = sin(휔표푡) 푢(푡). In order to arrive at the difference equation, we transform the discrete-time signals 푦(푡푘) and 푓(푡푘) into the sequences 푦[푘] and 푓[푘].

The iterative version of the trapezoidal rule is given by, ℎ 푦[푘 + 1] = 푦[푘] + {푓[푘 + 1] + 푓[푘]} 2 Now, we are ready to solve for 푦[푘]. Employing the Z-transform we obtain ℎ 푧푌(푧) − 푧푦[0] − 푌(푧) = [푧퐹(푧) − 푧푓[0] + 퐹(푧)] 2 or, since we had assumed 푦[0] = 푦(0) = 0 and 푓[0] = sin(0) = 0, ℎ (푧 − 1)푌(푧) = (푧 + 1)퐹(푧) 2 which leads to ℎ 푧 + 1 푌(푧) = 퐹(푧) 2 푧 − 1 The transfer function of the discrete-time system is given by 푌(푧) ℎ 푧 + 1 퐻(푧) = = 퐹(푧) 2 푧 − 1

Letting 푓(푡) = sin(휔표푡)푢(푡) leads to the sampled input sequence 푓[푘] = sin(휔표ℎ푘)푢[ℎ푘] = sin(Ω표푘) 푢[푘], with Ω표 ≜ 휔표ℎ. The Z-transform of 푓[푘] is (using Pair 11b with 훾 = 1)

푧 sin(Ω표) 퐹(푧) = 2 푧 − 2푧 cos(Ω표) + 1 Then,

ℎ 푧 + 1 푧 sin(Ω표) 푌(푧) = 퐻(푧)퐹(푧) = ( ) 2 2 푧 − 1 푧 − 2푧 cos(Ω표) + 1 푌(푧) Performing partial fraction expansion on we obtain (try it) 푧

푌(푧) ℎ − sin(Ω표) 1 ℎ sin(Ω표) 푧 − cos(Ω표) = ( ) + ( ) 2 푧 2 cos(Ω표) − 1 푧 − 1 2 cos(Ω표) − 1 푧 − 2푧 cos (Ω표) + 1

Finally, we employ the Z-transform Table to perform the inverse Z- transform of 푌(푧) (Pairs 2 and 11a), and obtain the solution ( ) ( ( )) −1 −ℎ sin Ω표 −1 푧 푧 푧 − cos Ω표 푦[푘] = 푍 {푌(푧)} = ( ) 푍 { − 2 } 2(cos(Ω표) − 1) 푧 − 1 푧 − 2푧 cos(Ω표) + 1

−ℎ sin(Ω표) 푦[푘] = [1 − cos(Ω표푘)]푢[푘] (1) 2[cos(Ω표) − 1]

By employing the earlier definition Ω표 ≜ 휔표ℎ, we may write the (exact) sampled solution of the integral as 1 푦푡푟푢푒[푘] = (1 − cos(Ω표푘)) (2) 휔표

For demonstration purposes, let us choose 휔표 = 10 and ℎ = 0.08 (leading to Ω표 = ℎ휔표 = 0.8. The following plot compares the exact solution in (2) 휋 휋 to the approximate one in (1), for 푡 ∈ [0 ]. Here, represents half of Ω표 Ω표 the full period, 2휋/Ω표. The following Mathcad worksheet uses 푎 for Ω표.

We chose to plot the sampled exact solution as a continuous (red) curve for clarity. Obviously, if we reduce the value of ℎ we improve the approximation [recall that the error for the trapezoidal rule is proportional to ℎ2. The following figure compares the results for ℎ = 0.02, 0.08 and 0.2 over two periods of the input.

Comparison between the Transfer Function of an Integrator and the Trapezoidal Rule-Based 퐻(푧) We saw earlier that the trapezoidal integration rule can be viewed as a discrete-time LTI system with transfer function 푇 푧 + 1 퐻(푧) = (1) 2 푧 − 1 The analog (exact) integrator transfer function is determined by applying the to the integration

푡 푦(푡) = ∫ 푓(휏)푑휏 0− which by means of the integration property of the Laplace transform gives 1 푌(푠) = 퐹(푠) 푠 Therefore, the integrator transfer function is 푌(푠) 1 퐻(푠) = = (2) 퐹(푠) 푠 Comparing (1) and (2) we conclude that we can arrive at 퐻(푧) by using 2 푧−1 the mapping, 푠 = . This is called the bilinear transformation and will 푇 푧+1 be used in Lecture 24 in connection with digital filter design. We can also 2+푠푇 express the inverse of this transformation (your turn) as 푧 = and 2−푠푇 show that the left half 푠-plane is mapped inside the unit circle in the 푧- plane. Your Turn: Write a Matlab (or Mathcad) script that generates 1,000 random points in the left half 푠-plane (including the 푗휔 axis) and maps and plots these points in the 푧-plane. Assume 푇 = 1 푠푒푐. According to your plot, where does the whole left half 푠-plane map into the 푧-plane?

We may also map a whole analog system to a discrete-time system using the bilinear transformation as demonstrated in the following example.

2 Example. Let 퐻(푠) = and 푇 = 0.1. Then, we can arrive at the 푠+1 corresponding discrete-time transfer function using the substitution 2 푧 − 1 푠 = 푇 푧 + 1 to get

2 2 푧 + 2 21 21 ( ) | 2 푧−1 퐻1 푧 = 퐻(푠) 푠= = 푧−1 = 19 0.1 푧+1 20 ( ) + 1 푧 − 푧+1 21 In Lecture 20, we employed the mapping 푧 = 푒푠푇 and arrived at the following discrete-time system transfer function approximation for the 2 analog system 퐻(푠) = (in the limit of very small 푇 and the use of 푠+1 Taylor series approximation) 2푇푧 2푇 퐻 (푧) = = 2 푧 − 푒−푇 1 − 푒−푇푧−1

The following Mathcad simulation compares the step-response of the analog system, 퐻(푠), and its two discrete-time system representations,

퐻1(푧) and 퐻2(푧). It is interesting to note that the bilinear approximation is more accurate than the Taylor expansion-based approximation.

Your turn: Repeat the above simulations for the transfer function 퐻(푠) = 1 with 푇 = 0.1. 푠2+1

Your turn: a. Show that Euler’s integration rule 푦[푘 + 1] = 푦[푘] + 푇푓[푘 + 1]

1 Leads to the mapping 푧 = . 1−푠푇 b. Write a Matlab (or Mathcad) script that generates 1,000 random points in the left half 푠-plane (including the 푗휔 axis) and maps and 1 plots these points in the 푧-plane according to 푧 = . Assume 푇 = 1−푠푇 1 푠푒푐. According to your plot, where does the whole left half 푠-plane map into the 푧-plane?

Convolution Sums and LTI System Analysis

Note: For Pair 1 in the above table, 푗 is a positive integer. Just as we employed the convolution integral in the continuous-time domain to obtain the zero-state response of a LTI system, we can employ convolution sums to obtain the zero-state response of a discrete-time system, 푦푧푠[푘] = 푓[푘] ∗ ℎ[푘]. The convolution sum generates a discrete- time signal according to the expression (refer to the section before last for derivation.) ∞

푦푧푠[푘] = 푓[푘] ∗ ℎ[푘] = ∑ 푓[푛]ℎ[푘 − 푛] 푛=−∞ It should be emphasized that the convolution operation is linear, which means that the commutative property, distributive (over addition and subtraction) property, associative property, scaling property, shift property and superposition property apply. The following example illustrates the convolution analysis method.

Example. Employ convolution sums from the above Table to solve for the zero-state response of a LTID system to the input 푓[푘] = 2푘푢[푘]. Assume 1 푘 the system’s unit-impulse response is given by ℎ[푘] = 훿[푘] + ( ) 푢[푘]. 2 Solution. In the following we employ the distributive property of convolution, Convolution Pair 1 (with 푗 = 0) and Pair 6 (with 훾1 = 1)

1 푘 푦 [푘] = 푓[푘] ∗ ℎ[푘] = 2푘푢[푘] ∗ [훿[푘] + ( ) 푢[푘]] 푧푠 2

1 푘 = 2푘푢[푘] ∗ 훿[푘] + 2푘푢[푘] ∗ ( ) 푢[푘] 2

1 1 (1) ( ) 1 푘 1 − = 2푘푢[푘] + 2 2 (( ) − 1푘 + 2 푘(1)푘) 푢(푘) 1 2 2 1 (1 − ) 2 2 1 푘 = 2푘푢[푘] + 4 (( ) − 1 + 푘) 푢[푘] 2

1 푘 푦 [푘] = (4 ( ) + 6푘 − 4) 푢[푘] 푧푠 2

Mathcad verification employing the 푧-transform method:

Example: Employ the definition of the convolution sum to solve for the zero-state sequence for the three-point moving average system. Solution: The input signal and the impulse response are (as determined earlier) given by 1 ℎ[푘] = ([훿] + 훿[푘 − 1] + 훿[푘 − 2]) 3 푓[푘] = 훿[푘] + 2훿[푘 − 1] − 훿[푘 − 2] + 훿[푘 − 3] + 2훿[푘 − 4] The zero-state response is given by ∞ 푦[푘] = 푓[푘] ∗ ℎ[푘] = ∑ 푓[푛]ℎ[푘 − 푛] 푛=−∞ Which can be written as (due to the causal and finite nature of the input),

4 푦[푘] = ∑ 푓[푛]ℎ[푘 − 푛] 푛=0 For 푘 = 0, we obtain

4 푦[0] = ∑ 푓[푛]ℎ[−푛] = 푓[0]ℎ[0] + 푓[1]ℎ[−1] + 푓[2]ℎ[−2] + ⋯ + 푓[4]ℎ[−4] 푛=0 1 1 푦[0] = (1) ( ) + (2)(0) + (−1)(0) + (1)(0) + (2)(0) = 3 3 For 푘 = 1:

4 푦[1] = ∑ 푓[푛]ℎ[1 − 푛] = 푓[0]ℎ[1] + 푓[1]ℎ[0] + 푓[2]ℎ[−1] + ⋯ + 푓[4]ℎ[−3] 푛=0 1 1 = (1) ( ) + (2) ( ) + (−1)(0) + (1)(0) + (2)(0) = 1 3 3 For 푘 = 2:

4 푦[2] = ∑ 푓[푛]ℎ[2 − 푛] 푛=0 = 푓[0]ℎ[2] + 푓[1]ℎ[1] + 푓[2]ℎ[0] + 푓[3]ℎ[−1] + 푓[4]ℎ[−2] 1 1 1 2 = (1) ( ) + (2) ( ) + (−1) ( ) + (1)(0) + (2)(0) = 3 3 3 3

Your turn: Finish the above example by determining 푦[3], 푦[4] and 푦[5].

Your turn: Employ the Table of Convolution Sums to determine the zero- 1 푘 state response of the system ℎ[푘] = ( ) 푢[푘] to the following input 푓[푘]: 2 a. 푢[푘]

1 푘 b. ( ) 푢[푘] 3

1 푘−2 1 푘−4 c. 5 ( ) 푢[푘 − 2] − 4 ( ) 푢[푘 − 4] 3 3 Hint: employ the result from Part b, shift and superposition. +1 푖푓 푘 = 0 −1 푖푓 푘 = 1 d. { −1 푖푓 푘 = 2 0 표푡ℎ푒푟푤푖푠푒 Hint: express the function as the sum of unit-steps and use the result form Part a, shift and superposition.

Your turn: Verify your solutions to the above problem employing the 푧- tarnsform and Mathcad. Plot the responses as stem plots.

Derivation of the Convolution Sum for the Zero-State Response We start by assuming a LTID system with unit-impulse response ℎ[푘]. That is, for the input 훿[푘] the system responds with ℎ[푘], 훿[푘] → 푠푦푠푡푒푚 → ℎ[푘] We are interested in showing that ∞

푦푧푠[푘] = 푓[푘] ∗ ℎ[푘] = ∑ 푓[푛]ℎ[푘 − 푛] 푛=−∞ Let us express the signal 푓[푘] as the sum 푓[푘] = ⋯ + 푓[−1]훿[푘 + 1] + 푓[0]훿[푘] + 푓[1]훿[푘 − 1] + ⋯ ∞ = ∑ 푓[푛]훿[푘 − 푛] 푛=−∞

Next, we employ the scaling and shift properties of linear systems and find the response to single sample input 푓[푛]훿[푘 − 푛] to be 푓[푛]ℎ[푘 − 푛].

푓[푛]훿[푘 − 푛] → 푠푦푠푡푒푚 → 푓[푛]ℎ[푘 − 푛]

Finally, applying the superposition property we obtain the zero-state response as the convolution sum ∞

푦푧푠[푘] = ∑ 푓[푛]ℎ[푘 − 푛] 푛=−∞

Derivation of the Convolution Property of the Z-transform In a similar fashion to the way we had derived the convolution property of the Laplace transform we shall derive the convolution property for the 푧- transform. Assuming causal signals and Z-transforming the convolution sum that we have just derived, we obtain ∞ ∞ −푘 푌푧푠(푧) = ∑ ∑ 푓[푛]ℎ[푘 − 푛] 푧 푘=0 푛=0 Interchanging the order of the summations in the above expression gives ∞ ∞ −푘 푌푧푠(푧) = ∑ 푓[푛] ∑ ℎ[푘 − 푛] 푧 푛=0 푘=0 The right hand side sum is the 푧-transform of a right-shifted signal by 푛 units, and can be represented as (employing the shift property of the 푧- transform) ∞ ∑ ℎ[푘 − 푛] 푧−푘 = 푧−푛퐻(푧) 푘=0

Substituting the above sum in the expression for 푌푧푠(푧) gives ∞ ∞ −푛 −푛 푌푧푠(푧) = ∑ 푓[푛]퐻(푧) 푧 = 퐻(푧) ∑ 푓[푛] 푧 = 퐻(푧)퐹(푧) 푛=0 푛=0 We have just proved that 푓[푛] ∗ ℎ[푛] ↔ 퐹(푧)퐻(푧)