Convolution Lab

Computer Systems Modelling · Sections 5.1.4 and 5.1.5 · Interactive lab

Convolution: flip, then slide

To find the convolution x(t) ⊗ y(t) at one instant t, flip y about the origin, slide it so that its origin sits at t, multiply it point by point with x, and add up (or integrate) the products. Each value of t gives one value of the output.

How it works and what to try

How it works: In two tabs. (1) Discrete time: type in x and y, or load the book’s Example 5.4, a delta, or a shifted delta. Five stacked plots show x, y, y flipped and slid to t, the products, and the output, with the sum written out term by term (Equation 5.11). (2) Continuous time: pick two functions, such as the triangle and rectangle of Example 5.5, and watch the overlap and its area trace out the output (Equation 5.16). A narrow unit-area pulse shows the Dirac delta in the limit. Python code for each case updates as you go.

Try this: Step t from 0 to 4 in Example 5.4 and check the values 3, 10, 25, 36, 69. Convolve with δ(t − 2) and see x shift. Load an asymmetric y and switch to Slide only to see why the flip matters. Shrink the pulse width and watch the output turn into a copy of x.

Section, example and equation numbers refer to Chapter 5 of S. Keshav, Mathematical Foundations of Computer Networking, Addison-Wesley, 2012.

Building a signal out of impulses

Let x(t) be the number of HTTP requests a Web server receives in each 1-second interval. Over 10 seconds it is 1, 3, 5, 2, 5, 8, 7, 3, 9, 4 (Figure 5.3(a)). The same histogram is also the sum of ten smaller histograms, one per interval (Figure 5.3(b)). Each small histogram is the product of x(t) with a selector function sel(t, τ), which is 1 when t = τ and 0 otherwise. Adding them up gives back x:

x(t) = ∞∑τ = 0 x(t) sel(t, τ)(EQ 5.7)

A short digression on shifting. The series x(t − a) is x(t) shifted a steps to the right, taken to be 0 before time a. For a = 2, its value at time 2 is x(0) = 1 and at time 3 is x(1) = 3 (Figure 5.4).

Now define the impulse function δ(t), with δ(0) = 1 and δ(t) = 0 for every other t. Then sel(t, 0) = δ(t), and by the shifting rule sel(t, 1) = δ(t − 1). In general

sel(t, τ) = δ(t − τ)(EQ 5.8)

so Equation 5.7 becomes

x(t) = ∞∑τ = 0 x(t) δ(t − τ)(EQ 5.9)

Each term is zero except when τ = t, so we may replace x(t) inside the sum by x(τ). Extending the sum over all integers gives x(t) = ∑ x(τ) δ(t − τ), which is Equation 5.10, the convolution of x with δ. The lab below generalises this from δ to any second function y.

x(t)the whole histogram, Figure 5.3(a); the highlighted bar is the term selected below
2
x(t) δ(t − 2)one small histogram from Figure 5.3(b) (solid), and the sum of the terms up to τ (faint)
2
x(t − 2)x shifted a steps to the right, Figure 5.4; the outline is x(t)

These plots use the x(t) typed into the lab below, which starts as the series above.

Load an example for y(t)
3

Equation 5.11

x(t) ⊗ y(t) = ∑τ x(τ) y(t − τ)

Both functions are taken to be zero outside the range where they are given, as in Example 5.4.

x(τ)the first function, fixed in place
y(τ)the second function, as given
y(−τ)y flipped about τ = 0, before any sliding
y(t − τ)y(t − τ) = y(−(τ − t)), so it is y(−τ) from the row above shifted t steps to the right. As t increases, it slides to the right.
x(τ) y(t − τ)the products; their sum is one output value
z(t) = x(t) ⊗ y(t)the output; the highlighted stem is the sum above
—
Python · Equation 5.11 directly, and with NumPy

    

What to notice

With Example 5.4 loaded, step t from 0 to 4 and compare the sum line with the text: 3, 10, 25, 36, 69. Only the stems where both functions are nonzero contribute.

Load δ(t): the output is x itself, which is Equation 5.10. Load δ(t − 2): the output is x shifted two steps to the right, as in Figure 5.4. Load 3, 2, 1 and press “Show the flip, then slide”. Because 3, 2, 1 is not symmetric, you can see it reverse to 1, 2, 3 before it slides.