← All tutorials

LTI Systems and Convolution

What a filter or a room does to a sound.

On this page

1 What a system is 2 Linear systems scale and add 3 The same reply at any time 4 The reply to one click 5 Convolution stacks copies of h 6 Order does not matter 7 One multiply per frequency 8 Cost and where it runs 9 Convolution in code 10 When the output looks wrong 11 References

A filter, a microphone and a room change a sound in the same way: each output sample is a weighted sum of current and past input samples. For a linear, time-invariant (LTI) system, its reply to one click, the impulse response h, tells what it does to any input.

input x system h output y 2Linear systems scale and add 3The same reply at any time 4The reply to one click 5Convolution stacks copies of h 6Order does not matter
Figure 1. Sections 2 to 6 each describe the middle box; each row opens its section.

1 What a system is

A system takes a signal in and gives one out: an equalizer (EQ) in a music app, the microphone in a phone, the room a voice travels through. Write the input as x[n] and the output as y[n], where n counts samples, and write H{x} for the output the system gives for input x. The definitions follow chapter 2 of Anushiravani (2016), which models a recording’s EQ and room this way. The same model later describes a room’s echoes and an adaptive filter, one that keeps learning while it runs.

2 Linear systems scale and add

A second microphone, one sample farther from the talker, hears each sample one step late at half the amplitude. Its impulse response is h = [0, 0.5]. Figure 2 sends three inputs through it (illustrative numbers).

input output one talker 1 2 3 h 0 0.5 1 1.5 twice the amplitude 2 4 6 h 0 1 2 3 plus a second talker 1 3 3 h 0 0.5 1.5 1.5
Figure 2. 1Twice the input, twice the output. 2A second talker adds its own output.

So speech and noise that reach one microphone come out as two parts that add, the starting point of spectral subtraction.

A linear system gives the same output whether inputs are mixed before or after it.
H{a x1 + b x2} = a H{x1} + b H{x2}
x1 and x2 are two inputs and a, b any two numbers. Scaling and adding the inputs first gives the same output as scaling and adding the two outputs. Row 2 of Figure 2 is a = 2; row 3 is a = b = 1. Section 3 asks the same of a delay.

3 The same reply at any time

Now the first input arrives one sample later (Figure 3, illustrative numbers).

input output now 1 2 3 0 h 0 0.5 1 1.5 0 one sample later 0 1 2 3 h 0 0 0.5 1 1.5
Figure 3. 1Same input one sample later, same output one sample later.
In a time-invariant system, a delay in is the same delay out.
if H{x[n]} = y[n] then H{x[n − r]} = y[n − r]
r is a delay in samples, and x[n − r] is the input started r samples late. The system acts the same at every moment, so its reply only shifts; Figure 3 is r = 1. A system that follows this rule and the one in section 2 is LTI.

Two familiar systems break the rules. A microphone preamplifier (preamp) driven past its range clips, so twice the input is no longer twice the output: not linear. A phone moved during a call changes the path to its microphone, so the reply depends on when a sound arrives: not time-invariant. An adaptive filter, which keeps re-learning, handles that case.

4 The reply to one click

A unit impulse δ[n] is one click: 1 at n = 0 and 0 everywhere else. A system’s output for it is its impulse response h[n]. A hand clap is close to a click, so a clap recorded in a room is close to the room’s impulse response. This page uses a stand-in room, h = [1, 0.5, 0.25]: the direct sound, then two echoes at half and a quarter height, one sample apart, 62.5 μs for audio sampled at 16 kHz (illustrative numbers; real reflections are milliseconds apart). Any signal is a row of clicks, each scaled by one sample value (Figure 4).

a signal is a row of scaled clicks 1 0 0 + 0 2 0 + 0 0 3 = 1 2 3 one click in, the impulse response out 1 one click room 1 0.5 0.25 h, direct then two echoes
Figure 4. 1Three scaled clicks add up to x. 2One click into the room gives h.
Any signal is a sum of shifted, scaled clicks.
x[n] = Σk x[k] δ[n − k]
δ[n − k] is a click at sample k, and x[k] scales it to that sample’s value. The sum over every k rebuilds the signal: Figure 4 is 1·δ[n] + 2·δ[n − 1] + 3·δ[n − 2]. Sections 2 and 3 say what an LTI system does with each click; section 5 puts the two together.

5 Convolution stacks copies of h

Each click in x comes out as a copy of h, scaled by the click’s height (linear) and starting at the click’s time (time-invariant). The output is the copies added, column by column.

Convolution adds shifted, scaled copies of h.
y[n] = Σk x[k] h[n − k] = (x ∗ h)[n]
Term k is copy k: h started at sample k and scaled by x[k]. h[n − k] reads h backwards as k grows; that is the flip in convolution. The star ∗ names the whole sum. Column n = 2 collects x[0]h[2] + x[1]h[1] + x[2]h[0], so h runs 2, 1, 0 while k runs 0, 1, 2.
length of y = N + M − 1
N is the number of input samples and M the number of values in h, called taps. The last copy starts at sample N − 1 and runs M samples, so three samples through three taps give five. Section 6 chains two such systems.

Figure 5. 1y[2] adds one bar per copy, h read backwards (illustrative).

A convolution layer in a convolutional neural network (CNN) computes the same sums without the flip, so strictly it is a cross-correlation, the same sliding sum with h read forwards. A learned kernel, the layer’s own h, absorbs the flip; a fixed filter or a measured room does not.

6 Order does not matter

Speech front ends, the first steps that turn audio into features for a model, often apply pre-emphasis, h2 = [1, −0.97], a filter that lifts high frequencies (the 0.97 default on the audio features page). Put it after a single echo, h1 = [1, 0.5], and send x = [1, 2, 3] through both (Figure 6, illustrative numbers).

in a chain, order does not matter x echo pre-emphasis y x pre-emphasis echo y x both as one h y each gives [1, 1.53, 1.575, −2.38, −1.455] side by side, paths add into one h x direct [1] wall [0, 0, 0.5] + y one h = [1, 0, 0.5] gives the same y [1, 2, 3.5, 1, 1.5]
Figure 6. 1Any order gives the same y. 2Side-by-side paths add.
Three rules for combining systems.
(x ∗ h1) ∗ h2 = x ∗ (h1 ∗ h2)
Two systems in a chain act as one (the associative rule), with impulse response h1 ∗ h2 = [1, −0.47, −0.485].
h1 ∗ h2 = h2 ∗ h1
Swapping the two stages gives the same chain (the commutative rule), rows 1 and 2 of Figure 6.
x ∗ (ha + hb) = x ∗ ha + x ∗ hb
Two paths side by side, the direct sound ha = [1] and a wall echo hb = [0, 0, 0.5], act as one system ha + hb = [1, 0, 0.5] (the distributive rule). Section 10 shows where these rules stop: at a stage that clips.

7 One multiply per frequency

An LTI system changes each sine wave only in size and in timing, the starting point of finite and infinite impulse response (FIR and IIR) filters. So in the frequency domain, convolution becomes one multiply per frequency bin, one frequency slot of the spectrum: the spectrum of y is the spectrum of x times the spectrum of h, as the Fourier page shows. A copy of a voice at half height 100 ms later, an h with 1 at n = 0 and 0.5 at n = 1,600 at 16 kHz, multiplies the spectrum by a comb, evenly spaced peaks and dips, 10 Hz apart (illustrative numbers).

8 Cost and where it runs

The direct sum costs N × M multiplies. One second of 48 kHz audio through a one-second room is 48,000 × 48,000, about 2.3 billion. The route through the fast Fourier transform (FFT), the quick way to compute a spectrum, uses the rule of section 7, that convolution in time becomes multiplication of spectra. It pads both signals with zeros to at least N + M − 1 = 95,999 samples, so no copy wraps around, rounded up to the power of two L = 217 = 131,072 that FFTs run fastest on. It then runs three FFTs, one for x, one for h and one inverse to get y back, each about L log2 L operations, about 6.7 million in all by this rough count (Figure 7).

operations, log scale direct sum, 2.3 billion FFT route, about 6.7 million 100k 1M 10M 100M 1B 10B
Figure 7. 1The FFT route is a few hundred times cheaper (about 345 by this rough count).

numpy.convolve computes the direct sum. scipy.signal.fftconvolve takes the FFT route, which its documentation calls much faster for arrays longer than about 500 samples. A short filter runs as a direct sum on every sample as audio streams in; a room response thousands of taps long goes through FFTs a block at a time.

9 Convolution in code

The stand-in room from section 4, with x and h three samples each, through both functions from section 8.

import numpy as np
import scipy.signal as sps

x = np.array([1.0, 2.0, 3.0])
h = np.array([1.0, 0.5, 0.25])

y = np.convolve(x, h)

y_fft = sps.fftconvolve(x, h)
assert np.allclose(y, y_fft)

ys = np.convolve(x, h, "same")
  1. 1x is three samples of a word; h is the stand-in room, the direct sound and two echoes.
  2. 2The full output, N + M − 1 = 5 values, [1, 2.5, 4.25, 2, 0.75]: the stacked copies of section 5.
  3. 3The FFT route gives the same values, up to rounding.
  4. 4Mode "same" keeps the middle N = 3 values, [2.5, 4.25, 2], so the output lines up with the input.

10 When the output looks wrong

What you seeCauseFix
Output longer than the inputFull convolution keeps every overlap, N + M − 1 samplesMode "same", or trim the tail
The tail wraps onto the startAn FFT multiply without padding is circular, so samples past the end wrap around to the startPad both with zeros to at least N + M − 1 (Fourier, section 9)
Twice the input is not twice the outputA stage clips, so the chain is not linearLower the gain before that stage
Figure 8. Three common faults, with cause and fix.

Convolution becomes multiplication in frequency; the spectrum itself is built on Fourier Transform and the FFT.

11 References