Signals and Systems
Homework: Discrete Time Convolution
You are required to use a Java program called J-DSP at http://jdsp.engineering.asu.edu/JDSP-HTML5/JDSP.html in this assignment. To become familiar with it, it is recommended that you first work through the PDF file βIntroduction on J-DSP HTML5β posted along with this document.
Convolution is a very important technique in signals and systems. While continuous-time convolution is important for theoretical analysis, you have to understand how to do discrete-time convolution in order to write a program to implement it on a computer or a DSP chip. This assignment will help you understand how to perform discrete time convolution operation with delta, window, unit step and exponential functions.
For a discrete time Linear and Time Invariant (LTI) system with impulse response h[n] as shown in Fig. 1, the output y[n] can be obtained through the convolution of input signal x[n] and impulse response h[n] as defined in Eqn. 1
LTI
h[n]
x[n] y[n]
Figure 1. discrete time LTI system
π¦π¦[ππ] = π₯π₯[ππ] β β[ππ] = οΏ½ π₯π₯[ππ]β[ππ β ππ]
β
ππ=ββ
(1)
Convolution with a Delta Function
Let us first look at two special cases of a discrete time signal convoluting with delta functions (sifting
property). Recall πΏπΏ[ππ] = 1 for n = 0 and πΏπΏ[ππ] = 0 for all other values.
β[ππ] β πΏπΏ[ππ] = οΏ½ β[ππ]πΏπΏ[ππ β ππ]
β
ππ=ββ
= β[ππ]πΏπΏ[0] = β[ππ] (2)
Note in Eqn. 2, since only when k = n, πΏπΏ[0] = 1 and all other πΏπΏ[ππ β ππ] = 0, the summation reduces to a single term β[ππ]. This is the reason why h[n] is called the impulse response, i.e., the system response (output) to an input delta function.
Likewise in Eqn. 3 when convoluting with a shifted version of delta function, only the term when ππ = ππ β ππ 0 remains in the summation, all other terms are zeros due to the delta function terms being zeros.
Note Eqn. 3 can also be obtained by applying the time-invariant property of the LTI system, i.e., shifting input in Eqn. 2 results in an identical shift in the output.
β[ππ] β πΏπΏ[ππ β ππ 0] = οΏ½ β[ππ]πΏπΏ[ππ β ππ 0 β ππ]
β
ππ=ββ
= β[ππ β ππ 0]πΏπΏ[0] = β[ππ β ππ 0] (3)
It is important to understand that every discrete time signal can be represented as a sum of a series of shifted and scaled delta functions (Textbook 2.1.1), i.e.,
π₯π₯[ππ] = οΏ½ π₯π₯[ππ]πΏπΏ[ππ β ππ]
β
ππ=ββ
(4)
For example if π₯π₯[ππ] = οΏ½
1 ππππππ ππ = β1
2 ππππππ ππ = 0
β1 ππππππ ππ = 1
0 ππππβππππππππππππ
(5), then based on Eqn. 4,
π₯π₯[ππ] = πΏπΏ[ππ + 1] + 2πΏπΏ[ππ] β πΏπΏ[ππ β 1] (6)
There are two ways to look at the convolution equation. First we can decompose the input signal into delta functions. Based on signal decomposition (Eqn. 4) and convolution Eqn. 2 and 3, we can represent output as a sum of a series of shifted and scaled (based on each of the input signal value) versions of impulse response functions:
π¦π¦[ππ] = β[ππ] β π₯π₯[ππ] = β[ππ] β οΏ½ π₯π₯[ππ]πΏπΏ[ππ β ππ]
β
ππ=ββ
= οΏ½ π₯π₯[ππ]β[ππ β ππ]
β
ππ=ββ
(7)
For x[n] defined in Eqn. 5, we have
π¦π¦[ππ] = π₯π₯[ππ] β β[ππ] = β[ππ] β (πΏπΏ[ππ + 1] + 2πΏπΏ[ππ] β πΏπΏ[ππ β 1]) = β[ππ + 1] + 2β[ππ] β β[ππ β 1] (8)
Eqn. 7 and 8 represent convolution output from the viewpoint of the input signal, i.e., how the input signal is decomposed into impulses, with each impulse passing through the LTI system, and then the individual outputs are added to generate the final output. (Think about how the LTI property can be used to generate the output in Eqn. 8.) The contribution of each sample/impulse in the input signal to many samples in the output signal is evident from Eqn. 7 and 8. For example, in Eqn. 8, x[-1]=1 contributes h[n+1] to the output, x[0]=2 contributes 2h[n] to the output, and x[1]=-1 contributes βh[n-1] to the output.
Task:
Calculate the convolution of the following two signals π¦π¦[ππ] = π₯π₯[ππ] β β[ππ]
h[n] x[n]
Figure 2. h[n] and x[n]
Write x[n] as a sum of delta functions similar to Eqn. 6.
Compute convolution using the method shown in Eqn. 8. Plot your y[n] in a figure similar to Fig. 2.
Go to http://jdsp.engineering.asu.edu/JDSP-HTML5/JDSP.html. Build the simulation diagram as shown in Fig. 3.
Figure 3. Convolution as a sum of shifted and scaled input signals
Note blocks Sig. Gen. (Signal Generator) and Plot is on the left. Convolution and Adder blocks are under βBasic Blocksβ in the drop down menu at the top.
Define the signals as shown in Figure 4. Click βUpdateβ. For βUser-Definedβ signal, click βEdit Signalβ to enter values and then click βUpdateβ.
Figure 4. Define x[n] (as a sum of delta functions) and h[n]
Open up Plot 6, 7 and 9. Choose βPlot Quantityβ as βRealβ at the top and βPlotβ as βDiscreteβ at the bottom. Take a screen shot. Verify Plot 9 is a sum of Plot 6 and 7, as y[n] is a sum of scaled and shifted h[n]βs. Compare your own plot y[n] with Plot 9. Are they the same? You can also see values of y[n] by clicking βGraph Valuesβ.
To verify your answer, reload the page and build the simulation as shown in Fig. 5. Define the signals as shown in Fig. 6. Open up Plot 4. Choose βPlot Quantityβ as βRealβ at the top and βPlotβ as βDiscreteβ at the bottom. Take a screen shot.
Figure 5. Direct convolution
Figure 6. Define x[n] and h[n]
Decomposing the input signal reinforces our understanding of how LTI systems work. As a matter of fact, this is how the convolution equation is derived. Passing an impulse through the system, we get the impulse response. Any input can be decomposed into a sum of shifted and scaled impulses. Because of the linear and time-invariant properties of LTI system, the shifted and scaled impulse responses get superimposed, and we get the output, which is our convolution equation.
We can also view convolution from the other perspective by decomposing the impulse response.
Decomposing the impulse response doesnβt have any physical meaning. However, it gives us insight into how each individual sample in the output signal gets contributions from the many samples of input signal, i.e., it helps us understand how to calculate independently each output sample. More importantly it shows how the LTI system manipulates input to get the output.
Convolution with a Window Function
Here a window function is informally defined as a finite number of impulses. Suppose the impulse response is a simple two-impulse window function:
β[ππ] = 1
2 (πΏπΏ[ππ] + πΏπΏ[ππ β 1]) = 1
2 (π’π’[ππ] β π’π’[ππ β 2]) (9)
Note π’π’[ππ] = 1 for ππ β₯ 0 and π’π’[ππ] = 0 for ππ < 0, and π’π’[ππ β 2] = 1 for ππ β₯ 2 and π’π’[ππ β 2] = 0 for ππ <
Verify for yourself the sum of the delta functions and the difference of the unit step functions in Eqn. 9 represent the same function. Plug Eqn. 9 into Eqn. 1, we have
π¦π¦[ππ] = π₯π₯[ππ] β β[ππ] = οΏ½ π₯π₯[ππ]β[ππ β ππ]
β
ππ=ββ
= 1
2 οΏ½ π₯π₯[ππ](πΏπΏ[ππ β ππ] + πΏπΏ[ππ β 1 β ππ])
β
ππ=ββ
= 1
2 οΏ½ π₯π₯[ππ]πΏπΏ[ππ β ππ]
β
ππ=ββ
+ 1
2 οΏ½ π₯π₯[ππ]πΏπΏ[ππ β 1 β ππ]
β
ππ=ββ
= 1
2 π₯π₯[ππ] β πΏπΏ[ππ] + 1
2 π₯π₯[ππ] β [ππ β 1]
= 1
2 (π₯π₯[ππ] + π₯π₯[ππ β 1]) (10)
Now by decomposing the impulse response, we can represent the output signal as a sum of scaled and
shifted input functions. Specifically, at any time n, y[n] can be calculated by adding up the current input
x[n] and the previous input x[n-1] and divided by 2. The LTI system is simply a two-point averaging (low pass) filter!
How to calculate each y[n] can be illustrated using a convolution machine as shown in Fig. 7. The convolution machine is based on the convolution definition equation π¦π¦[ππ] = π₯π₯[ππ] β β[ππ] = β π₯π₯[ππ]β[ππ β ππ]β ππ=ββ . In the figure, imagine the input signal x[n] at the top and the output signal y[n] at the bottom are fixed on the page. The convolution machine inside the dashed box glides from left to right to generate the output. The convolution machine is positioned so that its output is aligned with the output sample being calculated. Note inside the machine is h[-k], which is h[k] flipped left-for-right. Fig. 7 shows two positions of the convolution machine calculating y[0] and y[4]. Note the convolution machine is consistent with Eqn. 10, i.e., y[n] can be calculated by adding up the current input x[n] and the previous input x[n-1] and divided by 2. When one of x[n] or x[n-1] is missing, it is set to be zero. The convolution machine concept is the same as the flip and shift concept taught in the textbook.
0 1 2 3
0-1
1
2
3
0.5
x[n]
h[n]
(flipped)
xx
+
0 1 2 3
0.5
2
1.5
2.5
y[n]
4
0-1
xx
+
Figure 7. Convolution machine with window function
Task:
Calculate the convolution of the two signals π¦π¦[ππ] = π₯π₯[ππ] β β[ππ], where x[n] is defined in Fig. 7 and h[n] is defined in Eqn. 9.
In Fig. 7, move the convolution machine from left to right and calculate y[n] by hand.
Go to http://jdsp.engineering.asu.edu/JDSP-HTML5/JDSP.html. Build the simulation diagram in Fig. 5. Define Sig. Gen. 1 and 2 as x[n] and h[n] using βUser-Definedβ signal. Open up Sig.
Gen. 1, 2 and Plot 4, make sure all three plots are visible. Take a screenshot. (Take separate screenshots if they cannot fit on the same window.) Is y[n] the same as you calculated in Part a?
Convolution with a Shifted Window Function
Now letβs look at a shifted version of the two-impulse window function:
β[ππ] = 1
2 (πΏπΏ[ππ β 2] + πΏπΏ[ππ β 3]) = 1
2 (π’π’[ππ β 2] β π’π’[ππ β 4]) (11)
First derive using the definition equation:
π¦π¦[ππ] = π₯π₯[ππ] β β[ππ] = οΏ½ π₯π₯[ππ]β[ππ β ππ]
β
ππ=ββ
= 1
2 οΏ½ π₯π₯[ππ](πΏπΏ[ππ β 2 β ππ] + πΏπΏ[ππ β 3 β ππ])
β
ππ=ββ
= 1
2 οΏ½ π₯π₯[ππ]πΏπΏ[ππ β 2 β ππ]
β
ππ=ββ
+ 1
2 οΏ½ π₯π₯[ππ]πΏπΏ[ππ β 3 β ππ]
β
ππ=ββ
= 1
2 π₯π₯[ππ] β πΏπΏ[ππ β 2] + 1
2 π₯π₯[ππ] β [ππ β 3] = 1
2 (π₯π₯[ππ β 2] + π₯π₯[ππ β 3]) (12)
With the shift, y[n] is the average of the two input x[n] at two and three samples ago. Eqn. 12 shows that the time shift in h[n] (h[n] shifts right by 2 from Eqn. 9 to Eqn. 11) results in the exact same shift in y[n] (y[n] also shifts right by 2 from Eqn. 10 to Eqn. 12).
Fig. 8 illustrates the change in convolution machine. Again it is consistent with Eqn. 12.
Fig. 7 and Fig. 8 also illustrate two important facts. First the length of the output signal is equal to the length of the input signal, plus the length of the impulse response, minus one, i.e., πππ¦π¦ = πππ₯π₯ + ππβ β 1.
Second, if the indices of the first and last sample of input signal is πΌπΌπ₯π₯1and πΌπΌπ₯π₯2 and the indices of the first and last sample of impulse response is πΌπΌβ1and πΌπΌβ2, then the indices of the first and last sample of output signal is πΌπΌπ₯π₯1 + πΌπΌβ1and πΌπΌπ₯π₯2 + πΌπΌβ2. For example, in Fig. 8, x[n] is from 0 to 3, h[n] is from 2 to 3 from Eqn. 11, then y[n] is from 2 to 6.
0 1 2 3
-2-3
1
2
3
0.5
x[n]
h[n]
(flipped)
xx
+
0 1 2 3
0.5
2
1.5
2.5
y[n]
4
0-1
5 6
Figure 8. Convolution machine with time-shifted window function
On a side note, for Eqn. 9 and Eqn. 11, we have β[ππ] = 0 for n < 0. From Eqn. 10 and Eqn. 12, we derived that y[n] can be calculated from only current and past input x[n]βs. Based on the textbook definition, the two systems are causal, i.e., the two definitions of causality are equivalent.
Task:
Calculate the convolution of the two signals π¦π¦[ππ] = π₯π₯[ππ] β β[ππ], where x[n] is defined in Fig. 8 and h[n] is defined in Eqn. 11.
In Fig. 8, move the convolution machine from left to right and calculate y[n] by hand.
Go to http://jdsp.engineering.asu.edu/JDSP-HTML5/JDSP.html. Build the simulation diagram in Fig. 5. Define Sig. Gen. 1 and 2 as x[n] and h[n] using βUser-Definedβ signal. Open up Sig.
Gen. 1, 2 and Plot 4, make sure all three plots are visible. Take a screenshot. (Take separate screenshots if they cannot fit on the same window.) Is y[n] the same as you calculated in Part a?
Suppose β[ππ] = 1
2 (πΏπΏ[ππ] + πΏπΏ[ππ + 1]), derive y[n] in terms of x[n] similar to Eqn. 12. Draw the convolution machine similar to Fig. 8. Is the system causal? Why?
Convolution with a Unit Step Function
Now what if the impulse response is a unit step function as shown in Eqn. 13?
β[ππ] = π’π’[ππ] = οΏ½ πΏπΏ[ππ β ππ]
β
ππ=0
(13)
First convince yourself the unit step function is simply a sum of infinite number of shifted impulses as shown in Eqn. 13. By applying the sifting property of Eqn. 2 and 3, we have
π¦π¦[ππ] = π₯π₯[ππ] β β[ππ] = π₯π₯[ππ] β οΏ½ πΏπΏ[ππ β ππ]
β
ππ=0
= οΏ½ π₯π₯[ππ β ππ]
β
ππ=0
(14)
Eqn. 14 shows y[n] is the sum of all current and previous input x[n]βs. The convolution machine of a unit step function is illustrated in Fig. 9. Imagine the convolution machine inside the dashed box is extended infinitely to the left. As the machine glides from left to right, initially, y[0] = x[0], then y[1] = x[0] + x[1],
y[2] = x[0] + x[1] + x[2], y[3] = x[0] + x[1] + x[2] + x[3], then y[n] reaches steady state, it simply sums up all values in x[n], i.e., y[n] = y[3] for n β₯ 3.
0 1 2 3
0-1
1
2
3
1
x[n]
h[n]
(flipped)
xx
+
0 1 2 3
1
6
4
7
y[n]
4
…
…
x …
…
Figure 9. Convolution machine with unit step function
Task:
Calculate the convolution of the two signals π¦π¦[ππ] = π₯π₯[ππ] β β[ππ], where x[n] is defined in Fig. 9 and h[n] is defined in Eqn. 13.
In Fig. 9, move the convolution machine from left to right and calculate y[n] by hand.
Go to http://jdsp.engineering.asu.edu/JDSP-HTML5/JDSP.html. Build the simulation diagram in Fig. 5. Define Sig. Gen. 1 as x[n] using βUser-Definedβ signal. Define Sig. Gen. 2 as h[n] using βRectangularβ signal. Set βGainβ to 1, βPulsewidthβ to 20 (from 0 to 19), βTime Shiftβ to Open up Sig. Gen. 1, 2 and Plot 4, make sure all three plots are visible. Take a screenshot.
(Take separate screenshots if they cannot fit on the same window.) Is y[n] the same as you calculated in Part a? Why does y[n] start to drop at n = 20?
Convolution with an Exponential Function
When the impulse response is an exponential function such as
Textbook Problems
Convolution (DT):
Complete the tasks in hw convolution.pdf The simulator tutorial is J-DSP HTML5 getting started document.pdf y . Note you should use the HTML5 version of the simulator. No download is needed. It works in the web browser.
Convolution (CT): 2.22 (a) (c), 2.23 (b) (c) (d) System Properties (DT): 2.28 (c) (d) System Properties (CT): 2.29 (b) (e)