Calculate the convolution of the two signals 𝑦𝑦[𝑛𝑛] = π‘₯π‘₯[𝑛𝑛] βˆ— β„Ž[𝑛𝑛], where x[n] is defined in Fig. 9 and h[n] is defined in Eqn. 13.

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)

Calculate the convolution of the two signals 𝑦𝑦[𝑛𝑛] = π‘₯π‘₯[𝑛𝑛] βˆ— β„Ž[𝑛𝑛], where x[n] is defined in Fig. 9 and h[n] is defined in Eqn. 13.
Scroll to top