Hadamard code

From HandWiki
Short description: Error-correcting code
Hadamard code
Named afterJacques Hadamard
Classification
TypeLinear block code
Block length[math]\displaystyle{ n=2^k }[/math]
Message length[math]\displaystyle{ k }[/math]
Rate[math]\displaystyle{ k/2^k }[/math]
Distance[math]\displaystyle{ d=2^{k-1} }[/math]
Alphabet size[math]\displaystyle{ 2 }[/math]
Notation[math]\displaystyle{ [2^k,k,2^{k-1}]_2 }[/math]-code
Augmented Hadamard code
Named afterJacques Hadamard
Classification
TypeLinear block code
Block length[math]\displaystyle{ n=2^k }[/math]
Message length[math]\displaystyle{ k+1 }[/math]
Rate[math]\displaystyle{ (k+1)/2^k }[/math]
Distance[math]\displaystyle{ d=2^{k-1} }[/math]
Alphabet size[math]\displaystyle{ 2 }[/math]
Notation[math]\displaystyle{ [2^k,k+1,2^{k-1}]_2 }[/math]-code
Matrix of the Augmented Hadamard code [32, 6, 16] for the Reed–Muller code (1, 5) of the NASA space probe Mariner 9
XOR operations
Here the white fields stand for 0
and the red fields for 1

The Hadamard code is an error-correcting code named after Jacques Hadamard that is used for error detection and correction when transmitting messages over very noisy or unreliable channels. In 1971, the code was used to transmit photos of Mars back to Earth from the NASA space probe Mariner 9.[1] Because of its unique mathematical properties, the Hadamard code is not only used by engineers, but also intensely studied in coding theory, mathematics, and theoretical computer science. The Hadamard code is also known under the names Walsh code, Walsh family,[2] and Walsh–Hadamard code[3] in recognition of the American mathematician Joseph Leonard Walsh.

The Hadamard code is an example of a linear code of length [math]\displaystyle{ 2^m }[/math] over a binary alphabet. Unfortunately, this term is somewhat ambiguous as some references assume a message length [math]\displaystyle{ k = m }[/math] while others assume a message length of [math]\displaystyle{ k = m+1 }[/math]. In this article, the first case is called the Hadamard code while the second is called the augmented Hadamard code.

The Hadamard code is unique in that each non-zero codeword has a Hamming weight of exactly [math]\displaystyle{ 2^{k-1} }[/math], which implies that the distance of the code is also [math]\displaystyle{ 2^{k-1} }[/math]. In standard coding theory notation for block codes, the Hadamard code is a [math]\displaystyle{ [2^k,k,2^{k-1}]_2 }[/math]-code, that is, it is a linear code over a binary alphabet, has block length [math]\displaystyle{ 2^k }[/math], message length (or dimension) [math]\displaystyle{ k }[/math], and minimum distance [math]\displaystyle{ 2^k/2 }[/math]. The block length is very large compared to the message length, but on the other hand, errors can be corrected even in extremely noisy conditions.

The augmented Hadamard code is a slightly improved version of the Hadamard code; it is a [math]\displaystyle{ [2^k,k+1,2^{k-1}]_2 }[/math]-code and thus has a slightly better rate while maintaining the relative distance of [math]\displaystyle{ 1/2 }[/math], and is thus preferred in practical applications. In communication theory, this is simply called the Hadamard code and it is the same as the first order Reed–Muller code over the binary alphabet.[4]

Normally, Hadamard codes are based on Sylvester's construction of Hadamard matrices, but the term “Hadamard code” is also used to refer to codes constructed from arbitrary Hadamard matrices, which are not necessarily of Sylvester type. In general, such a code is not linear. Such codes were first constructed by Raj Chandra Bose and Sharadchandra Shankar Shrikhande in 1959.[5] If n is the size of the Hadamard matrix, the code has parameters [math]\displaystyle{ (n,2n,n/2)_2 }[/math], meaning it is a not-necessarily-linear binary code with 2n codewords of block length n and minimal distance n/2. The construction and decoding scheme described below apply for general n, but the property of linearity and the identification with Reed–Muller codes require that n be a power of 2 and that the Hadamard matrix be equivalent to the matrix constructed by Sylvester's method.

The Hadamard code is a locally decodable code, which provides a way to recover parts of the original message with high probability, while only looking at a small fraction of the received word. This gives rise to applications in computational complexity theory and particularly in the design of probabilistically checkable proofs. Since the relative distance of the Hadamard code is 1/2, normally one can only hope to recover from at most a 1/4 fraction of error. Using list decoding, however, it is possible to compute a short list of possible candidate messages as long as fewer than [math]\displaystyle{ \frac{1}{2}-\epsilon }[/math] of the bits in the received word have been corrupted.

In code-division multiple access (CDMA) communication, the Hadamard code is referred to as Walsh Code, and is used to define individual communication channels. It is usual in the CDMA literature to refer to codewords as “codes”. Each user will use a different codeword, or “code”, to modulate their signal. Because Walsh codewords are mathematically orthogonal, a Walsh-encoded signal appears as random noise to a CDMA capable mobile terminal, unless that terminal uses the same codeword as the one used to encode the incoming signal.[6]

History

Hadamard code is the name that is most commonly used for this code in the literature. However, in modern use these error correcting codes are referred to as Walsh–Hadamard codes.

There is a reason for this:

Jacques Hadamard did not invent the code himself, but he defined Hadamard matrices around 1893, long before the first error-correcting code, the Hamming code, was developed in the 1940s.

The Hadamard code is based on Hadamard matrices, and while there are many different Hadamard matrices that could be used here, normally only Sylvester's construction of Hadamard matrices is used to obtain the codewords of the Hadamard code.

James Joseph Sylvester developed his construction of Hadamard matrices in 1867, which actually predates Hadamard's work on Hadamard matrices. Hence the name Hadamard code is disputed and sometimes the code is called Walsh code, honoring the American mathematician Joseph Leonard Walsh.

An augmented Hadamard code was used during the 1971 Mariner 9 mission to correct for picture transmission errors. The binary values used during this mission were 6 bits long, which represented 64 grayscale values.

Because of limitations of the quality of the alignment of the transmitter at the time (due to Doppler Tracking Loop issues) the maximum useful data length was about 30 bits. Instead of using a repetition code, a [32, 6, 16] Hadamard code was used.

Errors of up to 7 bits per 32-bit word could be corrected using this scheme. Compared to a 5-repetition code, the error correcting properties of this Hadamard code are much better, yet its rate is comparable. The efficient decoding algorithm was an important factor in the decision to use this code.

The circuitry used was called the "Green Machine". It employed the fast Fourier transform which can increase the decoding speed by a factor of three. Since the 1990s use of this code by space programs has more or less ceased, and the NASA Deep Space Network does not support this error correction scheme for its dishes that are greater than 26 m.

Constructions

While all Hadamard codes are based on Hadamard matrices, the constructions differ in subtle ways for different scientific fields, authors, and uses. Engineers, who use the codes for data transmission, and coding theorists, who analyse extremal properties of codes, typically want the rate of the code to be as high as possible, even if this means that the construction becomes mathematically slightly less elegant.

On the other hand, for many applications of Hadamard codes in theoretical computer science it is not so important to achieve the optimal rate, and hence simpler constructions of Hadamard codes are preferred since they can be analyzed more elegantly.

Construction using inner products

When given a binary message [math]\displaystyle{ x\in\{0,1\}^k }[/math] of length [math]\displaystyle{ k }[/math], the Hadamard code encodes the message into a codeword [math]\displaystyle{ \text{Had}(x) }[/math] using an encoding function [math]\displaystyle{ \text{Had} : \{0,1\}^k\to\{0,1\}^{2^k}. }[/math] This function makes use of the inner product [math]\displaystyle{ \langle x , y \rangle }[/math] of two vectors [math]\displaystyle{ x,y\in\{0,1\}^k }[/math], which is defined as follows:

[math]\displaystyle{ \langle x , y \rangle = \sum_{i=1}^{k} x_i y_i\ \bmod\ 2\,. }[/math]

Then the Hadamard encoding of [math]\displaystyle{ x }[/math] is defined as the sequence of all inner products with [math]\displaystyle{ x }[/math]:

[math]\displaystyle{ \text{Had}(x) = \Big(\langle x , y \rangle\Big)_{y\in\{0,1\}^k} }[/math]

As mentioned above, the augmented Hadamard code is used in practice since the Hadamard code itself is somewhat wasteful. This is because, if the first bit of [math]\displaystyle{ y }[/math] is zero, [math]\displaystyle{ y_1=0 }[/math], then the inner product contains no information whatsoever about [math]\displaystyle{ x_1 }[/math], and hence, it is impossible to fully decode [math]\displaystyle{ x }[/math] from those positions of the codeword alone. On the other hand, when the codeword is restricted to the positions where [math]\displaystyle{ y_1=1 }[/math], it is still possible to fully decode [math]\displaystyle{ x }[/math]. Hence it makes sense to restrict the Hadamard code to these positions, which gives rise to the augmented Hadamard encoding of [math]\displaystyle{ x }[/math]; that is, [math]\displaystyle{ \text{pHad}(x) = \Big(\langle x , y \rangle\Big)_{y\in\{1\}\times\{0,1\}^{k-1}} }[/math].

Construction using a generator matrix

The Hadamard code is a linear code, and all linear codes can be generated by a generator matrix [math]\displaystyle{ G }[/math]. This is a matrix such that [math]\displaystyle{ \text{Had}(x)= x\cdot G }[/math] holds for all [math]\displaystyle{ x\in\{0,1\}^k }[/math], where the message [math]\displaystyle{ x }[/math] is viewed as a row vector and the vector-matrix product is understood in the vector space over the finite field [math]\displaystyle{ \mathbb F_2 }[/math]. In particular, an equivalent way to write the inner product definition for the Hadamard code arises by using the generator matrix whose columns consist of all strings [math]\displaystyle{ y }[/math] of length [math]\displaystyle{ k }[/math], that is,

[math]\displaystyle{ G = \begin{pmatrix} \uparrow & \uparrow & & \uparrow\\ y_1 & y_2 & \dots & y_{2^k} \\ \downarrow & \downarrow & & \downarrow \end{pmatrix}\,. }[/math]

where [math]\displaystyle{ y_i \in \{0,1\}^k }[/math] is the [math]\displaystyle{ i }[/math]-th binary vector in lexicographical order. For example, the generator matrix for the Hadamard code of dimension [math]\displaystyle{ k=3 }[/math] is:

[math]\displaystyle{ G = \begin{bmatrix} 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1\\ 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1\\ 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \end{bmatrix}. }[/math]

The matrix [math]\displaystyle{ G }[/math] is a [math]\displaystyle{ (k\times 2^k) }[/math]-matrix and gives rise to the linear operator [math]\displaystyle{ \text{Had}:\{0,1\}^k\to\{0,1\}^{2^k} }[/math].

The generator matrix of the augmented Hadamard code is obtained by restricting the matrix [math]\displaystyle{ G }[/math] to the columns whose first entry is one. For example, the generator matrix for the augmented Hadamard code of dimension [math]\displaystyle{ k=3 }[/math] is:

[math]\displaystyle{ G' = \begin{bmatrix} 1 & 1 & 1 & 1\\ 0 & 0 & 1 & 1\\ 0 & 1 & 0 & 1 \end{bmatrix}. }[/math]

Then [math]\displaystyle{ \text{pHad}:\{0,1\}^k\to\{0,1\}^{2^{k-1}} }[/math] is a linear mapping with [math]\displaystyle{ \text{pHad}(x)= x \cdot G' }[/math].

For general [math]\displaystyle{ k }[/math], the generator matrix of the augmented Hadamard code is a parity-check matrix for the extended Hamming code of length [math]\displaystyle{ 2^{k-1} }[/math] and dimension [math]\displaystyle{ 2^{k-1}-k }[/math], which makes the augmented Hadamard code the dual code of the extended Hamming code. Hence an alternative way to define the Hadamard code is in terms of its parity-check matrix: the parity-check matrix of the Hadamard code is equal to the generator matrix of the Hamming code.

Construction using general Hadamard matrices

Hadamard codes are obtained from an n-by-n Hadamard matrix H. In particular, the 2n codewords of the code are the rows of H and the rows of −H. To obtain a code over the alphabet {0,1}, the mapping −1 ↦ 1, 1 ↦ 0, or, equivalently, x ↦ (1 − x)/2, is applied to the matrix elements. That the minimum distance of the code is n/2 follows from the defining property of Hadamard matrices, namely that their rows are mutually orthogonal. This implies that two distinct rows of a Hadamard matrix differ in exactly n/2 positions, and, since negation of a row does not affect orthogonality, that any row of H differs from any row of −H in n/2 positions as well, except when the rows correspond, in which case they differ in n positions.

To get the augmented Hadamard code above with [math]\displaystyle{ n=2^{k-1} }[/math], the chosen Hadamard matrix H has to be of Sylvester type, which gives rise to a message length of [math]\displaystyle{ \log_2(2n)=k }[/math].

Distance

The distance of a code is the minimum Hamming distance between any two distinct codewords, i.e., the minimum number of positions at which two distinct codewords differ. Since the Walsh–Hadamard code is a linear code, the distance is equal to the minimum Hamming weight among all of its non-zero codewords. All non-zero codewords of the Walsh–Hadamard code have a Hamming weight of exactly [math]\displaystyle{ 2^{k-1} }[/math] by the following argument.

Let [math]\displaystyle{ x\in\{0,1\}^k }[/math] be a non-zero message. Then the following value is exactly equal to the fraction of positions in the codeword that are equal to one:

[math]\displaystyle{ \Pr_{y\in\{0,1\}^k} \big[ (\text{Had}(x))_y = 1 \big] = \Pr_{y\in\{0,1\}^k} \big[ \langle x,y\rangle = 1 \big]\,. }[/math]

The fact that the latter value is exactly [math]\displaystyle{ 1/2 }[/math] is called the random subsum principle. To see that it is true, assume without loss of generality that [math]\displaystyle{ x_1=1 }[/math]. Then, when conditioned on the values of [math]\displaystyle{ y_2,\dots,y_k }[/math], the event is equivalent to [math]\displaystyle{ y_1 \cdot x_1 = b }[/math] for some [math]\displaystyle{ b\in\{0,1\} }[/math] depending on [math]\displaystyle{ x_2,\dots,x_k }[/math] and [math]\displaystyle{ y_2,\dots,y_k }[/math]. The probability that [math]\displaystyle{ y_1=b }[/math] happens is exactly [math]\displaystyle{ 1/2 }[/math]. Thus, in fact, all non-zero codewords of the Hadamard code have relative Hamming weight [math]\displaystyle{ 1/2 }[/math], and thus, its relative distance is [math]\displaystyle{ 1/2 }[/math].

The relative distance of the augmented Hadamard code is [math]\displaystyle{ 1/2 }[/math] as well, but it no longer has the property that every non-zero codeword has weight exactly [math]\displaystyle{ 1/2 }[/math] since the all [math]\displaystyle{ 1 }[/math]s vector [math]\displaystyle{ 1^{2^{k-1}} }[/math] is a codeword of the augmented Hadamard code. This is because the vector [math]\displaystyle{ x=10^{k-1} }[/math] encodes to [math]\displaystyle{ \text{pHad}(10^{k-1}) = 1^{2^{k-1}} }[/math]. Furthermore, whenever [math]\displaystyle{ x }[/math] is non-zero and not the vector [math]\displaystyle{ 10^{k-1} }[/math], the random subsum principle applies again, and the relative weight of [math]\displaystyle{ \text{Had}(x) }[/math] is exactly [math]\displaystyle{ 1/2 }[/math].

Local decodability

A locally decodable code is a code that allows a single bit of the original message to be recovered with high probability by only looking at a small portion of the received word.

A code is [math]\displaystyle{ q }[/math]-query locally decodable if a message bit, [math]\displaystyle{ x_i }[/math], can be recovered by checking [math]\displaystyle{ q }[/math] bits of the received word. More formally, a code, [math]\displaystyle{ C: \{0,1\}^k \rightarrow \{0,1\}^n }[/math], is [math]\displaystyle{ (q, \delta\geq 0, \epsilon\geq 0) }[/math]-locally decodable, if there exists a probabilistic decoder, [math]\displaystyle{ D:\{0,1\}^n \rightarrow \{0,1\}^k }[/math], such that (Note: [math]\displaystyle{ \Delta(x,y) }[/math] represents the Hamming distance between vectors [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math]):

[math]\displaystyle{ \forall x \in \{0,1\}^k, \forall y \in \{0,1\}^n }[/math], [math]\displaystyle{ \Delta(y, C(x)) \leq \delta n }[/math] implies that [math]\displaystyle{ Pr[D(y)_i = x_i] \geq \frac{1}{2} + \epsilon, \forall i \in [k] }[/math]

Theorem 1: The Walsh–Hadamard code is [math]\displaystyle{ (2, \delta, \frac{1}{2}-2\delta) }[/math]-locally decodable for all [math]\displaystyle{ 0\leq \delta \leq \frac{1}{4} }[/math].

Lemma 1: For all codewords, [math]\displaystyle{ c }[/math] in a Walsh–Hadamard code, [math]\displaystyle{ C }[/math], [math]\displaystyle{ c_i+c_j=c_{i+j} }[/math], where [math]\displaystyle{ c_i, c_j }[/math] represent the bits in [math]\displaystyle{ c }[/math] in positions [math]\displaystyle{ i }[/math] and [math]\displaystyle{ j }[/math] respectively, and [math]\displaystyle{ c_{i+j} }[/math] represents the bit at position [math]\displaystyle{ (i+j) }[/math].

Proof of lemma 1


Let [math]\displaystyle{ C(x) = c = (c_0,\dots,c_{2^n-1}) }[/math] be the codeword in [math]\displaystyle{ C }[/math] corresponding to message [math]\displaystyle{ x }[/math].

Let [math]\displaystyle{ G = \begin{pmatrix} \uparrow & \uparrow & & \uparrow\\ g_0 & g_1 & \dots & g_{2^n-1} \\ \downarrow & \downarrow & & \downarrow \end{pmatrix} }[/math] be the generator matrix of [math]\displaystyle{ C }[/math].

By definition, [math]\displaystyle{ c_i = x\cdot g_i }[/math]. From this, [math]\displaystyle{ c_i+c_j = x\cdot g_i + x\cdot g_j = x\cdot(g_i+g_j) }[/math]. By the construction of [math]\displaystyle{ G }[/math], [math]\displaystyle{ g_i + g_j = g_{i+j} }[/math]. Therefore, by substitution, [math]\displaystyle{ c_i + c_j = x\cdot g_{i+j} = c_{i+j} }[/math].

Proof of theorem 1


To prove theorem 1 we will construct a decoding algorithm and prove its correctness.

Algorithm

Input: Received word [math]\displaystyle{ y = (y_0, \dots, y_{2^n-1}) }[/math]

For each [math]\displaystyle{ i \in \{1, \dots, n\} }[/math]:

  1. Pick [math]\displaystyle{ j \in \{0, \dots, 2^n-1\} }[/math] uniformly at random.
  2. Pick [math]\displaystyle{ k \in \{0, \dots, 2^n-1\} }[/math] such that [math]\displaystyle{ j+k = e_i }[/math], where [math]\displaystyle{ e_i }[/math] is the [math]\displaystyle{ i }[/math]-th standard basis vector and [math]\displaystyle{ j+k }[/math] is the bitwise xor of [math]\displaystyle{ j }[/math] and [math]\displaystyle{ k }[/math].
  3. [math]\displaystyle{ x_i \gets y_j+y_k }[/math].

Output: Message [math]\displaystyle{ x = (x_1, \dots, x_n) }[/math]

Proof of correctness

For any message, [math]\displaystyle{ x }[/math], and received word [math]\displaystyle{ y }[/math] such that [math]\displaystyle{ y }[/math] differs from [math]\displaystyle{ c = C(x) }[/math] on at most [math]\displaystyle{ \delta }[/math] fraction of bits, [math]\displaystyle{ x_i }[/math] can be decoded with probability at least [math]\displaystyle{ \frac{1}{2}+(\frac{1}{2}-2\delta) }[/math].

By lemma 1, [math]\displaystyle{ c_j+c_k = c_{j+k} = x\cdot g_{j+k} = x\cdot e_i = x_i }[/math]. Since [math]\displaystyle{ j }[/math] and [math]\displaystyle{ k }[/math] are picked uniformly, the probability that [math]\displaystyle{ y_j \not = c_j }[/math] is at most [math]\displaystyle{ \delta }[/math]. Similarly, the probability that [math]\displaystyle{ y_k \not = c_k }[/math] is at most [math]\displaystyle{ \delta }[/math]. By the union bound, the probability that either [math]\displaystyle{ y_j }[/math] or [math]\displaystyle{ y_k }[/math] do not match the corresponding bits in [math]\displaystyle{ c }[/math] is at most [math]\displaystyle{ 2\delta }[/math]. If both [math]\displaystyle{ y_j }[/math] and [math]\displaystyle{ y_k }[/math] correspond to [math]\displaystyle{ c }[/math], then lemma 1 will apply, and therefore, the proper value of [math]\displaystyle{ x_i }[/math] will be computed. Therefore, the probability [math]\displaystyle{ x_i }[/math] is decoded properly is at least [math]\displaystyle{ 1-2\delta }[/math]. Therefore, [math]\displaystyle{ \epsilon = \frac{1}{2} - 2\delta }[/math] and for [math]\displaystyle{ \epsilon }[/math] to be positive, [math]\displaystyle{ 0 \leq \delta \leq \frac{1}{4} }[/math].

Therefore, the Walsh–Hadamard code is [math]\displaystyle{ (2, \delta, \frac{1}{2}-2\delta) }[/math] locally decodable for [math]\displaystyle{ 0\leq \delta \leq \frac{1}{4} }[/math].

Optimality

For k ≤ 7 the linear Hadamard codes have been proven optimal in the sense of minimum distance.[7]

See also

  • Zadoff–Chu sequence — improve over the Walsh–Hadamard codes

References

  1. "Hadarmark Codes". Coding Theory. 2006. http://www.mcs.csueastbay.edu/~malek/TeX/Hadamard.pdf. 
  2. "On the assignment of Walsh and quasi-orthogonal codes in a multicarrier DS-CDMA system with multiple classes of users". Global Telecommunications Conference, 2002. GLOBECOM'02. IEEE. 1. IEEE. 2002-11-17. pp. 841–845. doi:10.1109/GLOCOM.2002.1188196. ISBN 0-7803-7632-3. 
  3. "Section 19.2.2". Computational Complexity: A Modern Approach. Cambridge University Press. 2009. ISBN 978-0-521-42426-4. http://www.cs.princeton.edu/theory/complexity/. 
  4. List decoding of binary codes. 2009. p. 3. https://www.cs.cmu.edu/~venkatg/pubs/papers/ld-binary-ms.pdf. 
  5. "A note on a result in the theory of code construction". Information and Control 2 (2): 183–194. June 1959. doi:10.1016/S0019-9958(59)90376-6. 
  6. "CDMA Tutorial: Intuitive Guide to Principles of Communications". Complex to Real. 2002. http://complextoreal.com/wp-content/uploads/2013/01/CDMA.pdf. 
  7. "Optimal binary linear codes of dimension at most seven". http://www.math.unl.edu/~djaffe2/papers/sevens.html. 

Further reading

de:Walsh-Code ja:直交符号