The Crystal Knew About Smoothing Before We Did
The cat’s whisker touching galena does two things: it rectifies and it smooths. The first part — turning alternating current into pulsing direct current — gets all the attention. But without the second part, you’d hear nothing but a harsh buzz at the carrier frequency. A small capacitor across the headphones acts as a “leaky integrator,” letting the audio through while averaging out the radio-frequency ripple.
This is exactly what an exponential moving average does in code. Each new sample gets blended with the accumulated history, controlled by a smoothing factor α. High α means the output tracks the input closely (less smoothing). Low α means sluggish response but excellent noise rejection. The crystal radio’s capacitor-resistor combination sets its own α based on component values — the math is identical.
# Envelope follower: what the crystal detector actually computes
signal = [0.8, -0.6, 0.9, -0.7, 0.5, -0.4, 0.6, -0.5]
alpha = 0.25
envelope = 0.0
signal.each do |sample|
rectified = sample.abs # cat's whisker
envelope = alpha * rectified + (1 - alpha) * envelope # capacitor
printf "%5.1f → %.3f\n", sample, envelope
end
The C version compiles to almost nothing — a multiply, an add, a store:
#include <stdio.h>
#include <math.h>
int main(void) {
double signal[] = {0.8, -0.6, 0.9, -0.7, 0.5, -0.4, 0.6, -0.5};
double alpha = 0.25, env = 0.0;
for (int i = 0; i < 8; i++) {
double rect = fabs(signal[i]);
env = alpha * rect + (1 - alpha) * env;
printf("%5.1f → %.3f\n", signal[i], env);
}
return 0;
}
Output from both:
0.8 → 0.200
-0.6 → 0.300
0.9 → 0.450
-0.7 → 0.512
0.5 → 0.509
-0.4 → 0.482
0.6 → 0.512
-0.5 → 0.509
Notice how the output converges toward 0.5 — the average magnitude of the input. The harsh swings from +0.9 to -0.7 become a gentle wobble around the mean. That’s the audio. The carrier is gone.
Digital signal processing formalized this in the 1960s and 70s, but the principle lived in passive electronics for decades before anyone wrote it as α * x + (1-α) * y. Stock traders use it for price smoothing. Sensor engineers use it to reject noise. Game developers use it for camera follow. Every one of them is implementing a leaky capacitor in software.
The galena crystal I was prodding with a whisker this afternoon predates transistors by forty years. It doesn’t know it’s computing an exponential moving average. It just does.