Blog / Audio Basics

How a Shift Register Measures a Room: Maximum Length Sequences Explained

How a Shift Register Measures a Room: Maximum Length Sequences Explained

The classic method for measuring a room's impulse response is a starter pistol. Fire a blank, record the decay. The physics is correct: an impulse has flat frequency content and known timing. But the practical problems are severe. A single pistol shot delivers maybe 130 dB SPL at close range. Recording equipment saturates. The usable dynamic range is limited by both the peak level of the shot and the noise floor of the room. One measurement equals one shot, so averaging requires reloading.

Maximum length sequences solve this by spreading measurement energy across time without giving up the impulse-like properties that make impulse responses measurable in the first place.

What Makes a Sequence Maximum Length

A maximum length sequence (MLS) is a binary pseudorandom sequence of length 2^n - 1, generated by a linear feedback shift register (LFSR). The shift register has n stages connected so that the output of specific stages is XOR'd back into the input. The connection pattern is defined by a primitive polynomial over GF(2). For a 4-stage register, a polynomial like x^4 + x + 1 defines which stages contribute to the feedback.

The output is a repeating sequence of 1s and 0s (mapped to +1 and -1 for signal processing). It looks random. Every standard statistical test treats it like white noise: flat power spectrum, zero autocorrelation across lags, nearly equal numbers of +1 and -1 values (one more +1 than -1 for any order n). But it is entirely deterministic, repeatable, and generated by a few XOR operations.

The key property is the periodic autocorrelation:

R[k] = { L,    k = 0
        { -1,   k ≠ 0

For a sequence of length L = 2^n - 1, the autocorrelation is flat at -1 everywhere except at zero lag, where it spikes to L. This is the discrete analog of the Dirac delta function, scaled by L. It is precisely what you get from cross-correlating a perfect impulse with itself.

The Measurement Principle

Because MLS has Dirac-like autocorrelation, it acts as a stand-in for an impulse in any measurement context. Play the MLS sequence through a loudspeaker into a room. Record the output. Cross-correlate the recording with the original MLS. The result is the room's impulse response.

If the room has impulse response h[n] and the excitation is the MLS m[n], the recording y[n] = m[n] h[n] (convolution). Cross-correlating y[n] with m[n] gives m[n] ⊛ m[n] h[n] = δ[n] * h[n] = h[n], because the autocorrelation of MLS is a scaled Dirac delta. The room's response emerges cleanly from the correlation.

The SNR Gain

This is where the pistol starts to look crude. A single impulse concentrates all its energy in one sample. MLS spreads the same total energy across L samples. The processing gain, the SNR improvement from cross-correlating the full sequence, is exactly 10 log₁₀(L) dB.

For n = 10 (L = 1023), that is 30 dB of free dynamic range improvement over a single impulse at the same peak level. For n = 16 (L = 65535), it is 48 dB. You record a quiet, undistorted signal and reconstruct what would have been a very loud impulse, without ever playing that loud impulse into the room.

Rife and Vanderkooy formalized this in a landmark 1989 AES paper, "Transfer-Function Measurement with Maximum-Length Sequences" (JAES 37:6, pp. 419-444). That paper became the theoretical foundation for commercial acoustic measurement systems including MLSSA, which brought MLS measurement to recording studios and loudspeaker labs through the early 1990s.

The Fast Hadamard Transform

Computing the cross-correlation directly costs O(L²) operations. For L = 65535, that is over four billion multiplications. Impractical in 1989, and slower than necessary today.

The MLS correlation matrix is structurally related to the Walsh-Hadamard matrix, and this relationship makes the circular cross-correlation computable with the Fast Hadamard Transform (FHT). The FHT reduces the cost to O(L log L). Unlike the FFT, FHT uses no complex arithmetic, only additions and subtractions, which made it attractive for the DSP hardware of the era. For a sequence of length 65535, direct correlation requires roughly 4 billion operations; FHT requires about a million.

Where MLS Breaks Down

The elegance of MLS rests on one assumption: the system being measured is linear and time-invariant. Both conditions must hold throughout the measurement.

Time variance is the more practical problem. If anything moves during measurement, an HVAC unit cycles on, a door opens, someone coughs, air temperature shifts from a heating element, the time-invariance assumption is violated. The resulting error does not look like obvious corruption. It spreads across the impulse response as apparent broadband noise, degrading the usable dynamic range in a way that is difficult to detect or quantify.

Nonlinearity is subtler but just as damaging. Loudspeakers are not linear: they produce harmonic distortion. When the measurement signal contains a 200 Hz component, the loudspeaker also emits energy at 400 Hz, 600 Hz, and higher harmonics. Because MLS cross-correlation cannot distinguish between "room reflection at time T" and "loudspeaker harmonic at time T," the distortion products appear as spurious early reflections in the computed impulse response. A measured IR of a loudspeaker includes the driver's own distortion baked into the result, indistinguishable from the linear response.

Why Angelo Farina's 2000 Paper Changed the Field

At the 108th AES Convention in February 2000, Angelo Farina presented "Simultaneous Measurement of Impulse Response and Distortion with a Swept-Sine Technique." The exponential sine sweep (ESS) method he formalized there uses a sine wave whose frequency increases exponentially over the measurement duration. Because only one frequency is present at any given moment, each harmonic order arrives at a predictable time offset before the linear response. Cross-correlating the recording with the inverse filter separates the linear impulse response from each harmonic order into individually windowed results.

ESS also delivers roughly 15 dB more dynamic range than MLS under comparable conditions. The ESS power spectrum rolls off with frequency, a pink-noise-like character that concentrates energy in the low frequencies where rooms have the most absorption and the least signal-to-noise margin.

The combination of harmonic separation and higher effective dynamic range made ESS the default technique for room acoustics, speaker measurement, and HRTF capture. MLS did not disappear, but the field largely moved on.

What MLS Still Does Well

For applications where nonlinearity is low and the system is stable, MLS remains useful. Measuring a short acoustic path, testing a well-behaved electronic component, or screening speaker drivers on a production line, these scenarios fit MLS well. A 1023-sample sequence at 44.1 kHz takes 23 milliseconds. ESS measurements for comparable dynamic range run several seconds. Speed matters.

MLS is also computationally simple. The LFSR generates the sequence with trivial hardware logic. For microcontrollers and embedded DSP where a full FFT chain is impractical, FHT-based MLS correlation is a viable option. Consumer devices that measure their own acoustic environment, headphones running speaker protection or EQ calibration, use variants of MLS for exactly this reason.

The Wider Pattern

What makes MLS interesting beyond acoustics is what it reveals about structured randomness. A deterministic shift register with n flip-flops and a few XOR gates produces a sequence that passes every standard randomness test, has a flat power spectrum, and computes its own cross-correlation in O(N log N) time with no complex arithmetic.

The same mathematical object, pseudorandom sequences with perfect correlation structure, appears in spread-spectrum radio, CDMA cellular networks, and GPS timing signals. The code that synchronizes a satellite ranging signal and the sequence that measures an anechoic chamber share the same shift-register generator structure.

That is the real surprise in MLS: a technique simple enough to implement in a few logic gates turns out to be one of the most robust ways humans have found to distinguish signal from noise in a noisy world.