Measuring the distance to the Apollo spacecraft: a simulation

During the Apollo mission to the Moon, NASA needed to know the distance from Earth to the spacecraft. This was accomplished by a sending a signal from Earth to the spacecraft and receiving the response. Since the signal traveled at the speed of light, the distance could be determined from the time delay between the sent and received signals. They determined the delay by transmitting a pseudo-random bit sequence and correlating it with the returned signal. This web page demonstrates how this ranging algorithm worked.

Drag the Command/Service Module to the desired location. (Not to scale!)

Range:

Extracting the clock phase

The primitive electronics of the 1960s couldn't directly correlate two long bitstreams. Instead, the bitstream was generated by combining four short subcodes that could be rapidly correlated against the returned signal.

The first step is to examine the received bitstream and extract the 1-megahertz clock that was exclusive-ored into the original bit sequence. The clock phase can be determined because the received bitstream will match the correct clock phase about 75% of the time and wrong phase about 25% of the time. The diagram below shows the two potential clock phases with matches in green.

Finding the X subcode offset

The shortest subcode is called X. After removing the clock, the bitstream can be compared with the X' sequence to find the best match. With the right alignment, about 75% of the bits will match, but with the wrong alignment about 50% will match randomly. The X code repeats every 11 bits, so the X offset can be determined by trying all 11 offsets and finding the best match.


Finding the A subcode offset

The next step is to find the offset of the A subcode, which repeats every 31 bits. The A subcode offset is found by aligning X'·A with the bitstream. It will match 100% when X' is 0. Otherwise it will match about 75% when aligned and 50% when unaligned. Thus, the overall match will be about 87.5% when aligned and 75% when unaligned. The difference between a match and a mismatch is smaller than for the X subcode, but the difference is still visible.

Finding the B and C subcode offsets

The B and C subcode offsets are found similarly. The B subcode repeats every 63 bits while the C subcode repeats every 127 bits.

Chinese remainder theorem

Once the subcode offsets have been determined, the overall offset of the received code can be determined mathematically. While the subcodes are short and easy to correlate, the overall code is of length 5,456,682 (the product of the subcode lengths). Thus, the overall code repeats every 5.46 seconds, a long enough time to unambiguously measure distances up to 800,000 kilometers, well beyond the distance to the Moon.

Comparing the clock phases

The above analysis assumes the signal is delayed by an integer number of clock intervals. By comparing the phase of the transmitted clock and the received clock, more accuracy can be obtained.


The actual ranging system had an accuracy of about ±1 meter, which is remarkably accurate for a spacecraft that was hundreds of thousands of kilometers away.