The Wire That Learned to Listen Selectively
The harmonic telegraph’s genius was selective deafness. Multiple operators keyed Morse on the same wire at different pitches, and each receiving station had a tuned reed that vibrated only at its assigned frequency. Everything else was noise. This is bandpass filtering—the signal processing equivalent of a dog who only hears one whistle.
Digital bandpass filters work by the same principle, just computed rather than mechanical. A simple approach: multiply the input signal by a reference sine wave at your target frequency, then average. Signals at that frequency reinforce; everything else cancels toward zero. The resonance detection that Edison patented in 1876 became the Goertzel algorithm a century later.
Here’s the core idea in Ruby—detecting whether a 440 Hz tone is present in a signal:
def goertzel_magnitude(samples, target_freq, sample_rate)
k = (0.5 + samples.length * target_freq / sample_rate).to_i
w = 2.0 * Math::PI * k / samples.length
coeff = 2.0 * Math.cos(w)
s0 = s1 = s2 = 0.0
samples.each do |x|
s0 = x + coeff * s1 - s2
s2, s1 = s1, s0
end
Math.sqrt(s1*s1 + s2*s2 - coeff*s1*s2)
end
And the C version, which you’d actually run on a microcontroller sniffing telegraph tones:
#include <math.h>
double goertzel(double *x, int n, double freq, double rate) {
double k = 0.5 + n * freq / rate;
double w = 2.0 * M_PI * (int)k / n;
double c = 2.0 * cos(w), s1 = 0, s2 = 0;
for (int i = 0; i < n; i++) {
double s0 = x[i] + c * s1 - s2;
s2 = s1; s1 = s0;
}
return sqrt(s1*s1 + s2*s2 - c*s1*s2);
}
Both implementations compute a single-frequency Discrete Fourier Transform bin. Feed it samples, tell it what frequency to listen for, and it returns a magnitude. High magnitude means the tone is present. Low means silence or a different pitch. Run multiple Goertzel filters in parallel—one for each harmonic telegraph channel—and you’ve recreated Bell’s multi-frequency receiver in code.
The Goertzel algorithm dates to 1958, optimized for exactly this use case: detecting specific tones without computing a full FFT. It’s how DTMF decoders work (those touch-tone phone beeps), how guitar tuners identify pitch, how modems negotiated handshakes. The algorithm needs only three state variables and one multiply per sample—lean enough to run on a 1970s microprocessor or a telegraph sounder’s modern companion circuit.
What makes bandpass filtering elegant is that it lets a system remain deaf on purpose. A telegraph reed doesn’t reject other frequencies through effort; it simply cannot move at any frequency but its own. The Goertzel filter does the same thing mathematically—the interference cancels, the target reinforces, and what remains is the signal you wanted. Edison’s tuned reeds and Gerald Goertzel’s algorithm are the same insight wearing different hats.
I tested the Ruby version on a recording of my restored sounder ringing at G4. The magnitude spiked at 392 Hz and dropped to noise everywhere else. The wire learned to listen selectively, just as Bell intended.