Suppose I want to send you a message composed of three-digit binary "words." In three binary digits, you can represent the eight numbers $0$ through $7$:MATHFor example, I have a "black and white" photo, made up of a rectangle of dots called pixels, each one of which represents a shade of gray, ranging from 0 = pure black through 7 = pure white. If the picture is $100\times 100$ ($100$ rows by $100$ columns), I would have to send you $10,000$ words representing $100$ rows, each of $100 $ pixels.




Now, the problem is, when I send this information, some of the words may get corrupted by interference or static. I may send the word $011$ (= $3$), but you may receive it as $010$ (= $2$) because of this transmission error. If this happens fairly frequently the image may get too distorted to be usable. What to do?




One possibility is to waste time and energy by resending the entire message, but there is no guarantee that similar serious data losses won't take place in that transmission. A solution that computer scientists have used for decades is to send more data, but in such a way that the receiver can detect errors and automatically compensate for them. This is called an error-correcting code, and I'll explain how one of them works.




The first thing to note is that, for any power of $2$, $N=2^{k}$, it is possible to find a list of $N$ binary words of length $N\,\ $such that any two of them differ in exactly $N/2$ binary places. Here are some examples:MATH(These lists of words are actually arrays of $0$s and $1$s called Hadamard matrices $H_{k}$). If you look at the $N=8$ list of eight words, you can see that words $2$ and $5$, for example, differ in exactly $N/2=4$ places:

MATHWe can define the "distance" --- actually the "Hamming distance" --- between any two binary words to be the number of places in which they differ. Thus, any two words in the $N=8$ list above have distance $4$ from each other, since they always differ in exactly 4 binary places.




Ok, suppose I want to send the gray pixel represented by the $3$ bits $011$ ($=3$). Instead of sending just the $3$ bits $011$, I send instead the entire row $3$ of the Hadamard matrix $H_{3}$. That is, I send the bits $10011001$. Unfortunately, because of interference, you receive the bits $10111001$. Compare:MATHThe Hamming distance between the correct word and the one you received is $1$, since these differ in only the single bit shown. Furthermore, since pairs of rows or words in $H_{3}\,\ $have distance $4$, the received word must be closer to $10011001$ than it is to any of the other rows. Thus, when you receive the word, if there is only one bit in error, you can simply find the row the received word is closest to and that will be the word that was sent.




In general, then, here's how it works. If we agree to communicate using words of $k$ binary digits, then we each set up the square Hadamard matrix $H_{k}$of length (and width) $N=2^{k}$. The rows will differ from each other in exactly $d=N/2$ binary places. Thus, each of the $N$ rows will have distance $d$ from any other row. To send the binary word of length $k$, I send instead the row of $H_{k}$ numbered by that binary word. When you receive this word, you look in your copy of $H_{k}$ and find the row which has smallest distance from the received word. The number of that row (in binary) will then be the word I originally sent, providing there are fewer than $(d-1)/2$ errors.




(If I am sending $5$ bit words (so $k=5$, $N=32$), for example, then we use the $32\times 32$ matrix $H_{5}$, whose rows have Hamming distance $16$ from each other. If I want to send the number $10110=22$, then I send the $22$nd row of $H_{5}$, which happens to be MATH. If there were fewer than $(d-1)/2=7.5$ errors, then whatever you receive will be closer to row $22$ than to any other row of $H_{5}$, so that's what you assume I sent (and you'll be correct).




In real life, such coding is used, among other things, to communicate images from space probes. Once the digital image is saved in the probe, the encoding and decoding using the Hadamard matrix is done at high speed by computers in the craft and on the ground. Occasionally there will be more errors than permissible, so that pixel may be received incorrectly. Most of the time, or for most of the pixels, things work fine; the bad pixels are simply averaged or otherwise processed out.