When Voices Overlap: Digital Convolution
Picture four choir voices entering one by one, each singing the same morse-coded melody but offset by two beats. The first voice taps out ”… --- …”, the second joins two beats later with the same pattern, then the third, then the fourth. What you hear isn’t just parallel lines—it’s the mathematical marriage of overlapping waveforms, each dot and dash smearing into its neighbours across time.
This is convolution in action: a fundamental operation that captures how signals blend when they meet. In Lua, we can model this overlap with surprising elegance:
function convolve(signal1, signal2)
local result = {}
for i = 1, #signal1 + #signal2 - 1 do
result[i] = 0
for j = math.max(1, i - #signal2 + 1), math.min(#signal1, i) do
result[i] = result[i] + signal1[j] * signal2[i - j + 1]
end
end
return result
end
-- Morse "S" convolved with echo pattern
print(table.concat(convolve({1,0,1,0,1}, {0.8,0.3}), " "))
-- Output: 0.8 0.3 0.8 0.3 0.8 0.3
The nested loops capture the essence: every sample of the first signal mingles with every sample of the second, weighted by how they align in time. But Lua’s interpreted nature makes this expensive for real-time audio. When you need convolution at 44.1kHz sample rates, you reach for C:
void convolve(float *x, int xlen, float *h, int hlen, float *y) {
for (int n = 0; n < xlen + hlen - 1; n++) {
y[n] = 0;
for (int k = 0; k < hlen; k++) {
if (n-k >= 0 && n-k < xlen)
y[n] += x[n-k] * h[k];
}
}
}
Here the mathematics strips down to pure arithmetic—no bounds checking overhead, just floating-point operations racing through memory. This is how your audio interface processes those overlapping choir voices in real-time, each canon entry convolved with room acoustics, microphone responses, and digital reverb impulses.
Every dot and dash in your morse canon becomes a tiny impulse, spreading its energy across time through convolution’s mathematical web. The result isn’t just addition—it’s transformation, where overlapping patterns create entirely new harmonic relationships that no single voice could achieve alone.