Convolution
Example:
The impulse response of an LTI system is
h(n) [ 1, 1, 2, 1]
Solution:
Given the convolution expression
y ( n) x ( k ) h( n k )
k
we replace the time variable n with k to have x(k) and h(k) to suit the expression. We then fold
h(k) to get h(k)
h( k ) [1, 2, 1, 1]
We get the sum of the product sequence for all values of n to get y(n). We shift h(k) to the
right.
At n = 0:
x(k) 1 2 1 2
h(0 k) 1 2 1 1
2 2 1 y(0) = 5
At n = 1:
x(k) 1 2 1 2
h(1 k) 1 2 1 1
1 4 1 2 y(1) = 2
At n = 2:
x(k) 1 2 1 2
h(2 k) 1 2 1 1
2 2 2 y(2) = 2
1
Solutions to Examples and Exercises
(3 DT-LTI Systems)
At n = 3:
x(k) 1 2 1 2
h(3 k) 1 2 1 1
1 4 y(3) = 3
At n = 4:
x(k) 1 2 1 2
h(4 k) 1 2 1 1
2 y(4) = 2
Shifting h(k) past n = 5 produces a product sequence of all zeros since x(k) and h(k) do not
anymore overlap. We then shift h(k) to the left until we have no more overlap with x(k).
At n = 1:
x(k) 1 2 1 2
h(1 k) 1 2 1 1
1 2 y(1) = 1
At n = 2:
x(k) 1 2 1 2
h(2 k) 1 2 1 1
1 y(2) = 1
Exercise:
Given h(n) [ 1, 1 2] x(n) [1, 0 1]
Find y(n).
Solution:
Obtain h(k): h( k ) [2, 1 1]
Obtain product sequence then take the sum for all values of n:
2
Solutions to Examples and Exercises
(3 DT-LTI Systems)
x(k) 1 0 1
h(0 k) 2 1 1
2 0 1 y(0) = 1
At n = 1:
x(k) 1 0 1
h(1 k) 2 1 1
0 1 y(1) = 1
At n = 2:
x(k) 1 0 1
h(2 k) 2 1 1
0 2 y(2) = 2
x(k) 1 0 1
h(1 k) 2 1 1
1 0 y(1) = 1
At n = 1:
x(k) 1 0 1
h(2 k) 2 1 1
1 y(2) = 1
y (n) [ 1, 1, 1, 1, 2]
Alternative solution:
A procedure using a shorter solution is presented below:
1. Assume initially that both signals are causal (disregard the arrows pertaining to n = 0).
2. Choose a signal that you will shift. The other signal shall remain static. Let a be the
shifted signal and b the static signal.
*Tip: Choose the longer of the two signals to shift.
3. Make a ((a + b 1) b) matrix.
3
Solutions to Examples and Exercises
(3 DT-LTI Systems)
5. On the first column, write other signal a (the one to be shifted) below the first vertically.
b1 b2 b3
a1
a2
a3
6. Copy the vertical signal onto the next column by shifting it one row down. Continue
doing this until you reach the last column.
b1 b2 b3
a1
a2 a1
a3 a2 a1
a3 a2
a3
7. Multiply the elements of each row (starting with the second) with the top row then get
their sum. Write the result on the right side of the table in line with the row.
b1 b2 b3
a1 c1 = a1b1
a2 a1
a3 a2 a1
a3 a2
a3
4
Solutions to Examples and Exercises
(3 DT-LTI Systems)
b1 b2 b3
a1 c1 = a1b1
a2 a1 c2 = (a2b1) + (a1b2)
a3 a2 a1 c3 = (a3b1) + (a2b2) + (a1b3)
a3 a2 c4 = (a3b2) + (a2b3)
a3 c5 = a3b3
Both signals have a shift of k = 1 giving a total shift of k = 2. The output is therefore
y (n) [ 1, 1, 1, 1, 2]
5
Solutions to Examples and Exercises
(3 DT-LTI Systems)
Example:
Find the response of the system y(n) given
x(n) [2 1 0 4 3 2] h2 (n) [1 0 3 2 1]
h1 (n) [3 2 2 1 1 5] h3 (n) [ 1 1 2 0 1]
x(n) H1
+ y(n)
H2 H3
h1(n) 3 2 2 1 1 5
+ h23(n) 1 1 1 1 10 3 1 2 1
h(n) 2 3 3 2 9 8 1 2 1
6
Solutions to Examples and Exercises
(3 DT-LTI Systems)
Finally we convolve the system impulse response h(n) with the input signal x(n).
x(n) 2 1 0 4 3 2
2 4
3 2 4
3 3 2 9
2 3 3 2 15
9 2 3 3 2 22
8 9 2 3 3 2 18
1 8 9 2 3 3 5
h(n) 2 1 8 9 2 3 39
1 2 1 8 9 2 3
1 2 1 8 9 37
1 2 1 8 11
1 2 1 12
1 2 1
1 2
MATLAB has a convolve function conv. As with our shorthand solution, conv disregards the
shifts attributed to the signal. The user has the responsibility to note the location of n = 0 (the
arrow) especially when dealing with parallel-connected systems, where the impulse responses
are added together.
Convolve h2(n) and h3(n)
>> h2 = [1 0 3 2 -1];
>> h3 = [-1 1 2 0 1];
>> h23 = conv(h2,h3)
h23 =
-1 1 -1 1 10 3 1 2 -1
Remember that the total shift is k = 1. We now add this to h1(n). To add the two responses we
must align their time indices (aligned at n = 0). Also, matrix addition in MATLAB must have
the same sizes. We pad zeros at the end of h1(n) before adding to h23(n).
>> h1 = [3 2 -2 1 -1 5];
>> h = h23 + [h1 0 0 0]
h =
2 3 -3 2 9 8 1 2 -1
Using conv to get the convolution sum of h(n) and x(n)
>> x = [2 -1 0 4 -3 -2];
>> y = conv(h,x)
7
Solutions to Examples and Exercises
(3 DT-LTI Systems)
y =
Columns 1 to 13
4 4 -9 15 22 -18 5 39 -3 -37 -11 -12 -1
Column 14
2
Numerically the answers are equal. Just note the n = 0 is at 9.
Correlation
Example:
Given x(n) [1 0 1 1 2] y (n) [1 0 1 1 3]
1. Determine the cross-correlation sequence rxy(l). What is the point of maximum relation?
2. Solve for ryx(l) and compare it with rxy(l).
Solution:
Since correlation is similar to convolution, we can use the method solution for convolution but
with the folding step omitted.
We use the shorthand solution but with some slight modifications:
Since the order of the subscripts denote the reference (static) and compared (shifted)
signals, the signals are not interchangeable.
Instead of writing the vertical signal normally (step 5), write its folded version.
To determine l = 0, find the row where the arrows (n = 0) for both signals coincide.
1. For rxy(l), x(n) is static and y(n) is shifted with respect to it.
x(n) 1 0 1 1 2
3 3
1 3 1
1 1 3 4
0 1 1 3 4
y(n) 1 0 1 1 3 7
1 0 1 1 3 l=0
1 0 1 1
1 0 1
1 2
rxy (l ) [ 3 1 4 4 7 3 1 1 2]
The point of maximum relation is the maximum (largest positive) value in the correlation
sequence.
maxrxy (l ) 4 , l 2
8
Solutions to Examples and Exercises
(3 DT-LTI Systems)
ryx (l ) [2 1 1 3 7 4 4 1 3]
Comparing ryx(l) to rxy(l) it is clear that ryx(l) is the folded version of rxy(l), or ryx(l) = rxy(l).
Autocorrelation
Example:
Determine the autocorrelation sequence of x(n).
x(n) [1 0 1 1 2]
Solution:
We perform correlation on x(n) and x(n).
x(n) 1 0 1 1 2
2 2
1 2 1
1 1 2 3
0 1 1 2 3
x(n) 1 0 1 1 2 7 l=0
1 0 1 1 3
1 0 1 3
1 0 1
1 2
rxx (l ) [2 1 3 3 7 3 3 1 2]
We can see that the autocorrelation rxx(l) function attains its maximum value at l = 0. Also, the
autocorrelation function is an even function
MATLAB has a similar function xcorr for correlation as conv is for convolution.
9
Solutions to Examples and Exercises
(3 DT-LTI Systems)
Solution:
We start by rearranging the terms in order to solve for y(n).
y(n) = y(n 1) + nu(n)
Since the system is initially relaxed, y(n) = 0 for n < 0.
We solve for the value of y(n) at any time n by substituting n into the equation.
At n = 0: y(0) = y(0 1) + x(0)
= y(1) + (0)u(0)
= 0 + (0)(1)
y(0) = 0
10
Solutions to Examples and Exercises
(3 DT-LTI Systems)
Example 2:
Determine y(4) for a DT system characterized by the LCCDE
2y(n) y(n 1) + y(n 2) = x(n)
where: x(n) = n2u(n)
y(0) = 1
y(1) = 3
Solution:
Again we rearrange the equation, and normalize it by dividing the equation with a0.
y(n) = y(n 1) y(n 2) x(n)
We solve for y(n) iteratively starting at n = 2.
At n = 2: y(2) = y(2 1) y(2 2) x(2)
= y(1) y(0) (22)u(2)
= (3) (1) (4)(1)
y (2) 1
Solution:
Since the homogeneous solution yh(n) is a solution homogeneous in the output variable y, we set
the input x(n) = 0.
We substitute the general form of the homogeneous solution yh(n) = Cn into the DE.
n n 1 2n 2 = 0
We factor out n 2 to obtain an expression with positive exponents.
n 2 (2 2) = 0
11
Solutions to Examples and Exercises
(3 DT-LTI Systems)
To solve for , we solve for the roots of the equation using quadratic formula.
(1) (1) 2 4(1)(2)
(2)(1)
1 1 8 1 3
2 2
2, 1
The homogeneous solution is therefore
y h (n) C1 (2) n C 2 (1) n
Example 2:
Determine yh(n) for the DE
y(n) y(n 1) + 2y(n 2) = x(n)
Solution:
The DE looks similar to the previous one, but closer inspection reveals that the coefficients of y
are different. We take the general solution of the DE as
n n 1 + 2n 2 = 0
n 2 (2 + 2) = 0
Solving for
(1) (1) 2 4(1)(2)
(2)(1)
1 1 8 1 j 7
2 2
1 7
j
2 2
We express in polar form
7
2 tan 1 2
1 7
2 1
r
2
2 2 1.2094
0.385
2
2e j 0.385
The homogeneous solution becomes
y h (n) C1 2e j 0.385 C
n
2 2e j 0.385
n
C1 2 e j 0.385 n C 2 2 e j 0.385 n
n n
n
y h (n) 2 C1 e j 0.385 n C 2 e j 0.385 n
12
Solutions to Examples and Exercises
(3 DT-LTI Systems)
Example 3:
Determine yzi(n) for the DE
6y(n) + y(n 1) 2y(n 2) = x(n)
given the initial conditions:
y(2) = 0 and y(1) = 1.
Solution:
The zero-input solution yzi(n) is the output of the system with the input set to zero. In other
words, the output of the system is from a prior excitation (initial condition) and not from an
input signal.
Since we set the input x(n) to zero to obtain the homogeneous solution, therefore yzi(n) is just
yh(n) evaluated using the initial conditions. The homogeneous solution is
y (n) 1 6 y (n 1) 1 3 y (n 2) 0
n 1 6 n1 1 3 n2 0
n 2 (2 1 6 1 3 ) 0
16 16 2 4(1) 13 16 7 6
2(1) 2
2 1
,
3 2
n n
2 1
yh (n) C1 C2
3 2
The zero-input solution yzi(n) is the homogeneous solution yh(n) evaluated at the initial
conditions.
y zi (n) y h (n) I .C .
We evaluate yh(n) using the initial conditions to solve for the arbitrary constants.
At n = 1:
1 1
2 1
y (1) 1 C1 C 2
3 2
3
1 C1 C 2 2 Eq. 1
2
At n = 2:
2 2
2 1
y (2) 0 C1 C 2
3 2
9
0 C1 C2 4 Eq. 2
4
13
Solutions to Examples and Exercises
(3 DT-LTI Systems)
Solution:
We start by using the iterative solution to find y(2).
y (n) 2 y (n 1) x(n)
2 y (n 1) 2u (n) 4 n u (n)
At n = 0:
y (0) 2 y (0 1) 2u (0) 4 0 u (0)
2 y (1) (2)(1) (1)(1)
2(1) 3
y (0) 1
At n = 1:
y (1) 2 y (1 1) 2u (1) 41 u (1)
2 y (0) (2)(1) (4)(1)
2(1) 6
y (1) 4
At n = 2:
y (2) 2 y (2 1) 2u (2) 4 2 u (2)
2 y (1) (2)(1) (16)(1)
2(4) 18
y (2) 10
14
Solutions to Examples and Exercises
(3 DT-LTI Systems)
For the total solution, we start with the homogeneous solution yh(n).
y (n) 2 y (n 1) 0
n 2n1 0
n1 ( 2) 0
2
y h (n) C (2) n
For the particular solution, we take a look at the input signal x(n)
x(n) 2u (n) 4 n u (n)
Applying the property of linearity
x(n) x1 (n) x2 (n) y p (n) y1 p (n) y 2 p (n)
We have
y p (n) K1u (n) K 2 4 n u (n)
At n = 2:
K u(2) K
1 2
4 2 u (2) 2 K1u (1) K 2 41 u (1) 2u (2) 4 2 u (2)
K1 16 K 2 2K1 4 K 2 18
3K1 24 K 2 18
K1 8 K 2 6 Eq. 2
Solving the Eq. 1 and Eq. 2 simultaneously
2 2
K1 and K2
3 3
The particular solution yp(n) is
2 2
y p (n) u ( n ) ( 4 n )u ( n )
3 3
15
Solutions to Examples and Exercises
(3 DT-LTI Systems)
y p ( n)
2
3
1 4 n u ( n)
C (2) n
2
3
1 4 n u ( n)
To solve for C, we evaluate the equation with the value of y(0) taken from the iterative solution.
y (0) 1 C (2) 0
2
3
1 4 0 u (0)
2
C (2)(1)
3
1
C
3
1
3
2
yt (n) (2) n 1 4 n u (n)
3
We check the validity of the solution by substituting n = 2.
1
3
2
yt (2) (2) 2 1 4 2 u (2)
3
(4) 1 16(1)
1 2
3 3
4 34
3 3
30
3
yt(2) = 10
Solution:
We start with the zero-input solution, yzi(n). We take the homogeneous solution from the
previous example and evaluate it using the initial condition.
y zi (n) y h (n) y ( 1)1
16
Solutions to Examples and Exercises
(3 DT-LTI Systems)
1 C (2) 1
1
1 C
2
C 2
y zi (n) 2(2) n
For the zero-state solution yzs(n), we take the total solution yt(n) and evaluate using zero initial
conditions (initially relaxed).
y zs (n) yt (n) y ( 1)0
yt (n) C (2) n
2
3
1 4 n u ( n)
We solve for the zero-state output using the iterative solution with y(n) = 0
At n = 0:
y (0) 2 y (0 1) 2u (0) 4 0 u (0)
2 y (1) (2)(1) (1)(1)
2(0) 3
y (0) 3
y (0) 3 C (2) 0
2
3
1 4 0 u (0)
2
3 C (1) (2)(1)
3
5
C
3
5
3
2
y zs (n) (2) n 1 4 n u (n)
3
The total solution is the sum of yzi(n) and yzs(n).
y zi (n) 6
(2) n
3
y zs (n) 5
3
2
(2) n 1 4 n u (n)
3
y t ( n) 1
3
2
(2) n 1 4 n u (n)
3
It is the same for the classical solution.
17
Solutions to Examples and Exercises
(3 DT-LTI Systems)
Draw its Direct Form I implementation and compare the response with the Direct Form II
implementation.
0.1498
x(n) + + y(n)
z1 z1
0.1498 1.0368
+ +
z1 z1
0.114 0.437
We interchange the recursive and non-recursive systems, then remove the redundant delays in
the middle for the direct form II (DF2) implementation.
0.1498
x(n) + + y(n)
z1
1.0368 0.1498
+ +
z1
0.437 0.114
To determine the values for the step response, we use Simulink a model-based simulation tool
for MATLAB. For more information on Simulink, you may consult the MATLAB reference.
To start Simulink, enter simulink at the command prompt.
18
Solutions to Examples and Exercises
(3 DT-LTI Systems)
19
Solutions to Examples and Exercises
(3 DT-LTI Systems)
In the Solver menu, change the Solver in Solver options section to discrete. Leave the
Simulation Stop time at 10.0 (default). Click on Ok when youre done.
Save the model before proceeding with the simulation.
To simulate the model, click on Simulation Run (or click on the Play button on the menu
bar). When the simulation is done, switch to the MATLAB desktop and view the result by
typing y on the command prompt.
>> y
y =
0.114000000000000
0.381995200000000
0.724046023360000
0.961597214139648
1.058448284014003
1.055077358008106
1.009268149497086
0.963245919684837
0.935544115013962
0.926929996136171
0.930101796144381
0.937153826930602
0.943079613026168
0.946142435799550
0.946728994505841
Repeat the procedure for the DF2 model but change the Variable name of the To Workspace
Sink block to y1. Save your work as Ch3ExDF2.mdl then run the simulation.
We compare the outputs of the two by typing [y y1] on the MATLAB command prompt.
>> [y y1]
ans =
0.114000000000000 0.114000000000000
0.381995200000000 0.381995200000000
0.724046023360000 0.724046023360000
0.961597214139648 0.961597214139648
1.058448284014003 1.058448284014003
1.055077358008106 1.055077358008106
1.009268149497086 1.009268149497086
21
Solutions to Examples and Exercises
(3 DT-LTI Systems)
0.963245919684837 0.963245919684837
0.935544115013962 0.935544115013962
0.926929996136171 0.926929996136171
0.930101796144381 0.930101796144381
0.937153826930602 0.937153826930602
0.943079613026168 0.943079613026168
0.946142435799550 0.946142435799550
0.946728994505841 0.946728994505841
We can see that the outputs of the two models are exactly the same, and therefore the DF1 and
DF2 structures are similar.
Mathematical solution
0.5184 j 0.4102
0.66106e j 0.21308
y h (n) C1 0.66106e j 0.21308
n
C 2 0.66106e j 0.21308
n
0.66106 C1e j 0.21308 n C 2 e j 0.21308 n
n
For yp(n), since x(n) = u(n) (step response), therefore yp(n) = Ku(n). We substitute this into the
LCCDE.
Ku (n) 1.0368Ku (n 1) 0.437Ku (n 2) 0.114u (n) 0.1498u (n 1) 0.114u (n 2)
Evaluating at n = 2 to solve for K
Ku (2) 1.0368Ku (2 1) 0.437Ku (2 2) 0.114u (2) 0.1498u (2 1) 0.114u (2 2)
Ku (2) 1.0368Ku (1) 0.437Ku (0) 0.114u (2) 0.1498u (1) 0.114u (0)
K (1) 1.0368 K (1) 0.437 K (1) 0.114(1) 0.1498(1) 0.114(1)
0.4002 K 0.3778
K 0.94403
y p (n) 0.94403u (n)
22
Solutions to Examples and Exercises
(3 DT-LTI Systems)
y (0) 0.114 0.66106 C1e j 0.21308 ( 0) C 2 e j 0.21308 ( 0) 0.94403u (0)
0
At n = 1:
y (1) 1.0368 y (0) 0.437 y (1) 0.114u (1) 0.1498u (0) 0.114u (1)
1.0368(0.114) 0.437(0) 0.114(1) 0.1498(1) 0.114(0)
y (1) 0.382 0.66106 C1e j 0.21308 (1) C 2 e j 0.21308 (1) 0.94403u (1)
1
0.56203 0.66106 C1e j 0.21308 C 2 e j 0.21308
0.8502 C1e j 0.21308 C 2 e j 0.21308 Eq. 2
23
Solutions to Examples and Exercises
(3 DT-LTI Systems)
We compare the response from our mathematical solution with our Simulink output.
>> n = (0:14);
>> y2 = 0.89*(0.66106.^n).*cos(0.21308.*pi.*n+0.88248*pi)+0.94403;
>> [y y2]
ans =
0.114000000000000 0.114001447708508
0.381995200000000 0.382000709726754
0.724046023360000 0.724046364628476
0.961597214139648 0.961560135309563
1.058448284014003 1.058337989875235
1.055077358008106 1.054882712824498
1.009268149497086 1.009008362162859
0.963245919684837 0.962956248598765
0.935544115013962 0.935256981119231
0.926929996136171 0.926663444470153
0.930101796144381 0.929858339948219
0.937153826930602 0.936926154117632
0.943079613026168 0.942857823233304
0.946142435799550 0.945919081729676
0.946728994505841 0.946500822785331
The slight differences (error) between the two outputs is due to rounding (truncation) errors.
24
Solutions to Examples and Exercises
(3 DT-LTI Systems)
Given that our particular solution is yp(n) =Ku(n), we can use solve after substituting yp(n)
into the LCCDE and evaluating at n = 2.
>> K = solve(K-1.0368*K+0.438*K=0.114+0.1498+0.114)
K =
0.94402798600699650174912543728136
Solving the zero-state step response from the LCCDE using an iterative solution we have
y(0) = 0.114
y(1) = 0.382
We write Eq. 1 and Eq. 2 as
0.114 C1 C2 K Eq. 1
0.382 C1 (1 ) C 2 (2 ) K Eq. 2
This system of equations can be written as
b1 a11 a12 C1
b a a 22 C 2
2 21
Therefore
0.114 K 1 1 C1
0.382 K C
1 2 2
25
Solutions to Examples and Exercises
(3 DT-LTI Systems)
>> w_C = angle(C)/pi
0.8828
-0.8828
26
Solutions to Examples and Exercises
(3 DT-LTI Systems)
Appendix
27