Convolution Calculator (Discrete)
Compute the discrete linear convolution y = x * h of two finite sequences.
Used in DSP, image filtering, CNNs.
Shows the full output and an overlap chart.
Convolution is the operation that combines an input signal x[n] with a system’s impulse response h[n] to produce the system’s output y[n]:
y[n] = Σ x[k] h[n − k] (summed over all k)
For finite sequences of length L_x and L_h, the output has length L_y = L_x + L_h − 1. The sum is just a multiply-and-add over all the index combinations that line up to produce y[n].
The “flip and slide” picture. Reverse h to get h[−k], slide it past x one position at a time, and at each position multiply the overlapping samples and sum the products. That sum is one output sample. The output starts as soon as the two sequences first touch, peaks where they overlap most, and tapers off as h slides past the end of x.
Why this matters. Every linear time-invariant (LTI) system is fully characterised by its impulse response h. Once you know h, the output for any input is just x * h. This single operation underlies almost all of signal processing.
Worked example. Convolve x = [1, 2, 3] with h = [1, 0, −1] (a one-dimensional edge detector):
- y[0] = x[0]·h[0] = 1·1 = 1
- y[1] = x[0]·h[1] + x[1]·h[0] = 1·0 + 2·1 = 2
- y[2] = x[0]·h[2] + x[1]·h[1] + x[2]·h[0] = 1·(−1) + 2·0 + 3·1 = 2
- y[3] = x[1]·h[2] + x[2]·h[1] = 2·(−1) + 3·0 = −2
- y[4] = x[2]·h[2] = 3·(−1) = −3
Full output: y = [1, 2, 2, −2, −3]. The sign change in the middle is where the input “changed” (rose then fell) — the kernel detected the edge.
Where it shows up:
- Audio DSP. Reverb is x convolved with a measured room impulse response. EQ filters, FIR low-pass filters, and audio compressors are all convolutions.
- Image processing. 2D convolution with kernels like the Sobel operator [[−1,0,1],[−2,0,2],[−1,0,1]] detects vertical edges. Gaussian blur is convolution with a 2D Gaussian kernel. The entire convolutional neural network (CNN) family is built on stacked 2D convolutions.
- Radar and sonar. Matched filtering is cross-correlation, the close cousin of convolution.
- Probability. The probability distribution of the sum of two independent random variables is the convolution of their individual distributions. Roll two dice: the distribution of the sum is the convolution of two flat 1-to-6 distributions, which gives the familiar triangle peaking at 7.
The convolution theorem. Convolution in the time domain equals multiplication in the frequency domain: F{x * h} = F{x} · F{h}. For long sequences, FFT-multiply-IFFT is dramatically faster than direct convolution. This calculator does direct convolution (good for sequences up to a few hundred elements); for production DSP code with thousands of samples, use FFT.
Caveats.
- This is linear convolution, the form you usually want. Circular convolution (wrapping the output back into the input length) is a different operation used in FFT-based signal processing — it’s not what’s computed here.
- For an L-point impulse response and an N-point input, full output is L + N − 1 points. Truncating to N points (called “same” mode) discards the start-up and tail transients.