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 x\in\{0,1\}^k of length k, the Hadamard code encodes the message into a codeword \text{Had}(x) using an encoding function \text{Had} : \{0,1\}^k\to\{0,1\}^{2^k}. This function makes use of the
inner product \langle x , y \rangle of two vectors x,y\in\{0,1\}^k, which is defined as follows: :\langle x , y \rangle = \sum_{i=1}^{k} x_i y_i\ \bmod\ 2\,. Then the Hadamard encoding of x is defined as the sequence of
all inner products with x: :\text{Had}(x) = \Big(\langle x , y \rangle\Big)_{y\in\{0,1\}^k} 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 y is zero, y_1=0, then the inner product contains no information whatsoever about x_1, and hence, it is impossible to fully decode x from those positions of the codeword alone. On the other hand, when the codeword is restricted to the positions where y_1=1, it is still possible to fully decode x. Hence it makes sense to restrict the Hadamard code to these positions, which gives rise to the
augmented Hadamard encoding of x; that is, \text{pHad}(x) = \Big(\langle x , y \rangle\Big)_{y\in\{1\}\times\{0,1\}^{k-1}}.
Construction using a generator matrix The Hadamard code is a linear code, and all linear codes can be generated by a
generator matrix G. This is a matrix such that \text{Had}(x)= x\cdot G holds for all x\in\{0,1\}^k, where the message x is viewed as a
row vector and the vector-matrix product is understood in the
vector space over the
finite field \mathbb F_2. 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 y of length k, that is, :G = \begin{pmatrix} \uparrow & \uparrow & & \uparrow\\ y_1 & y_2 & \dots & y_{2^k} \\ \downarrow & \downarrow & & \downarrow \end{pmatrix}\,. where y_i \in \{0,1\}^k is the i-th binary vector in
lexicographical order. For example, the generator matrix for the Hadamard code of dimension k=3 is: : 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}. The matrix G is a (k\times 2^k)-matrix and gives rise to the
linear operator \text{Had}:\{0,1\}^k\to\{0,1\}^{2^k}. The generator matrix of the
augmented Hadamard code is obtained by restricting the matrix G to the columns whose first entry is one. For example, the generator matrix for the augmented Hadamard code of dimension k=3 is: : G' = \begin{bmatrix} 1 & 1 & 1 & 1\\ 0 & 0 & 1 & 1\\ 0 & 1 & 0 & 1 \end{bmatrix}. Then \text{pHad}:\{0,1\}^k\to\{0,1\}^{2^{k-1}} is a linear mapping with \text{pHad}(x)= x \cdot G'. For general k, the generator matrix of the augmented Hadamard code is a
parity-check matrix for the
extended Hamming code of length 2^{k-1} and dimension 2^{k-1}-k, 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 2
n 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 n=2^{k-1}, the chosen Hadamard matrix
H has to be of Sylvester type, which gives rise to a message length of \log_2(2n)=k. ==Distance==