We decode a received word \(r\) by finding the nearest neighbor. So far, we have done so by searching through all the code words and finding the one that is closest to \(r\).
Question. Is there a better way to find the nearest neighbor?
A binary linear code \(C\) is a nonempty subset of \(\mathbb{Z}_2^n\) that is closed under addition in \(\mathbb{Z}_2^n\): If \(v_1, v_2 \in C\) are code words, then \(v_1+v_2 \in C\).
A binary linear code is an Abelian group with identity \(\mathbf{0} = \begin{bmatrix} 0&0&\cdots&0 \end{bmatrix}\).
A binary linear code is called an “\([n,k]\)-code” if it is generated (as an Abelian group) by a set of linearly independent vectors \(v_1, v_2, \ldots, v_k \in \mathbb{Z}_2^n\).
Linear Algebra: A binary linear code is a vector space over the field \(\mathbb{Z}_2\).
Linear Algebra: An \([n,k]\)-code is a \(k\)-dimensional subspace of \(\mathbb{Z}_2^n\).
If linearly independent vectors \(v_1, v_2, \ldots, v_k \in \mathbb{Z}_2^n\) generate a binary linear code \(C\), then the matrix \[ G = \begin{bmatrix} v_1 \\ v_2 \\ \vdots \\ v_k \end{bmatrix} \] is a generating matrix for \(C\), where the generating code words \(v_i\) are written as row vectors. If \(S\) is a \(2^k \times k\) matrix whose rows consist of all of the elements of \(\mathbb{Z}_2^k\), then the rows of \(SG\) consist of all the code words in \(C\).
If linearly independent vectors \(v_1, v_2, \ldots, v_k \in \mathbb{Z}_2^n\) generate a binary linear code \(C\), then the matrix \[ G = \begin{bmatrix} v_1 \\ v_2 \\ \vdots \\ v_k \end{bmatrix} \] is a generating matrix for \(C\), where the generating code words \(v_i\) are written as row vectors. If \(S\) is a \(2^k \times k\) matrix whose rows consist of all of the elements of \(\mathbb{Z}_2^k\), then the rows of \(SG\) consist of all the code words in \(C\).
Hamming \([7,4]\): \[ G = \begin{bmatrix} 1&0&0&0&1&1&0 \\ 0&1&0&0&1&0&1 \\ 0&0&1&0&0&1&1 \\ 0&0&0&1&1&1&1 \end{bmatrix} \]
8th-bit parity check: \[ G = \begin{bmatrix} 1&0&0&0&0&0&0&1 \\ 0&1&0&0&0&0&0&1 \\ 0&0&1&0&0&0&0&1 \\ 0&0&0&1&0&0&0&1 \\ 0&0&0&0&1&0&0&1 \\ 0&0&0&0&0&1&0&1 \\ 0&0&0&0&0&0&1&1 \end{bmatrix} \]
The Hamming weight \(\mbox{wt}(v)\) of a binary vector \(v\) is the number of \(1\)’s in \(v\).
Facts:
Definition. A linear binary code is called systematic if its generating matrix can be written in the form \(\begin{bmatrix} I_k & P \end{bmatrix}\), where \(I_k\) is the \(k\times k\) identity matrix.
Definition. If \(C\) is an \([n,k]\) linear code, then an \((n-k) \times n\) matrix \(H\) is called a parity check matrix if it has the property that \(vH^T = \mathbf{0}\) iff \(v\) is a code word.
Quiz: Construct a parity check matrix for the 8th-bit parity check code. (Hint: what are \(n\) and \(k\)?)
Theorem. If \(C\) is a systematic \([n,k]\) binary linear code with generating matrix \(G = \begin{bmatrix} I_k & P \end{bmatrix}\), then \(H = \begin{bmatrix} P^T & I_{n-k} \end{bmatrix}\) is a parity check matrix for \(C\).
Example: Hamming \([7,4]\): \[ G = \begin{bmatrix} 1&0&0&0&1&1&0 \\ 0&1&0&0&1&0&1 \\ 0&0&1&0&0&1&1 \\ 0&0&0&1&1&1&1 \end{bmatrix} \quad \quad H = \begin{bmatrix} 1&1&0&1&1&0&0 \\ 1&0&1&1&0&1&0 \\ 0&1&1&1&0&0&1 \end{bmatrix} \]
Theorem. If \(C\) is a systematic \([n,k]\) binary linear code with generating matrix \(G = \begin{bmatrix} I_k & P \end{bmatrix}\), then \(H = \begin{bmatrix} P^T & I_{n-k} \end{bmatrix}\) is a parity check matrix for \(C\).
Proof. Let \(v_i\) be one of the rows of the generator matrix \(C\). Then \[ v_i = \begin{bmatrix} 0 & \cdots & 0 & 1 & 0 & \cdots 0 & p_{i1} & p_{i2} & \cdots & p_{i\,n-k} \end{bmatrix} \] and the \(j\)th column of \(H^T\) looks like \[ \begin{bmatrix} p_{1j} & p_{2j} & \cdots & p_{kj} & 0 & \cdots & 0 & 1 & 0 & \cdots 0 \end{bmatrix}^T \] so the dot product of these two vectors will be \(p_{ij} + p_{ij} = 0\). So \(v_i H^T = \mathbf{0}\). Now use linearity.
Definition. Let \(C\) be an \([n,k]\) code, and let \(r \in \mathbb{Z}_2^n\). The coset of \(C\) in \(\mathbb{Z}_2^n\) represented by \(r\) is the set \(r + C = \{r+v \mid v \in C\}\) of all vectors that can be formed by adding codewords to \(r\).
Quiz: What is the coset represented by a codeword?
Definition. Suppose that \(r\) is a vector in \(\mathbb{Z}_2^n\), and \(C\) is an \([n,k]\) code with parity check matrix \(H\). The vector \(rH^T\) is called the syndrome of \(r\).
Quiz: What is the syndrome of a codeword?
Let \(C\) be the \([4,2]\) code with the following generator matrix.
\[ G = \begin{bmatrix} 1 & 0 & 1 & 1 \\ 0 & 1 & 1 & 0 \end{bmatrix} \]
Construct the parity check matrix \(H\).
List all of the cosets of \(C\) in \(\mathbb{Z}_2^4\).
Compute all the syndromes of the 16 vectors in \(\mathbb{Z}_2^4\). Find a shortcut.
Quiz: In an \([n,k]\) linear binary code,
A coset representative of minimal weight is called a coset leader.
To decode a received message \(r \in \mathbb{Z}_2^n\),
To decode a received message \(r \in \mathbb{Z}_2^n\),
Exercise: For the code with generator matrix
\[ G = \begin{bmatrix} 1 & 0 & 1 & 1 \\ 0 & 1 & 1 & 0 \end{bmatrix} \]
0111
.Just adding won’t do what you want:
[,1] [,2] [,3] [,4]
[1,] 0 0 0 0
[2,] 1 0 1 1
[3,] 0 1 1 0
[4,] 1 1 0 1
[,1] [,2] [,3] [,4]
[1,] 1 1 1 1
[2,] 1 0 1 1
[3,] 0 1 1 0
[4,] 1 1 0 1
[,1] [,2] [,3] [,4]
[1,] 0 0 0 0
[2,] 1 0 1 1
[3,] 0 1 1 0
[4,] 1 1 0 1
[,1] [,2] [,3] [,4]
[1,] 1 0 0 0
[2,] 0 0 1 1
[3,] 1 1 1 0
[4,] 0 1 0 1
[,1] [,2] [,3] [,4]
[1,] 0 0 0 0
[2,] 1 0 1 1
[3,] 0 1 1 0
[4,] 1 1 0 1
[,1] [,2] [,3] [,4]
[1,] 1 0 0 0
[2,] 0 0 1 1
[3,] 1 1 1 0
[4,] 0 1 0 1
For any \(m \geq 1\), there is a Hamming code with \(n = 2^m-1\) and \(k = 2^m-1-m\).
m <- 3
powersOf2 <- 2^(0:(m-1))
hamH <- sapply(c(setdiff(1:(2^m-1), powersOf2), powersOf2),
function(x){as.numeric(intToBits(x)[1:m])})
hamH
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 1 1 0 1 1 0 0
[2,] 1 0 1 1 0 1 0
[3,] 0 1 1 1 0 0 1
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 1 1 0 1 1 0 0
[2,] 1 0 1 1 0 1 0
[3,] 0 1 1 1 0 0 1
If \(H = \begin{bmatrix} P^T & I_{n-k} \end{bmatrix}\), then \(G = \begin{bmatrix} I_k & P \end{bmatrix}\).
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 1 0 0 0 1 1 0
[2,] 0 1 0 0 1 0 1
[3,] 0 0 1 0 0 1 1
[4,] 0 0 0 1 1 1 1
Given the parity check matrix \(H = \begin{bmatrix} P^T & I_{n-k} \end{bmatrix}\), it is easy to write down the generating matrix \(G = \begin{bmatrix} I_k & P \end{bmatrix}\).
generatorMatrix <- function(H) {
k <- ncol(H)-nrow(H)
n <- ncol(H)
return(cbind(diag(k),t(H[1:(n-k),1:k])))
}
generatorMatrix(hamH)
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 1 0 0 0 1 1 0
[2,] 0 1 0 0 1 0 1
[3,] 0 0 1 0 0 1 1
[4,] 0 0 0 1 1 1 1
Lemma. Let \(C\) be a systematic linear binary code, and let \(H\) be its parity check matrix.
The nonzero syndromes are the columns of the parity check matrix \(H\). (why?)
For nearest neighbor decoding, the column of the syndrome is the location of the error. (why?)