Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Tutorial

Classical Linear Codes

Abstract

The mathematical formulation of a broad class of classical error correcting codes.

Keywords:bitsbit-flipsrepetition code

In this section, we will give a mathematical description of a broad class of binary classical error correcting codes called linear codes, which includes the repetition code and parity check codes introduced in the previous section.

Three methods of representing a classical linear code will be given. For each, the parity error detection and correction examples will be detailed.

Finally, in this section we will denoted an nn bit-strings as an nn dimensional vectors in the vector space F2n\mathbb{F}^n_2, i.e,

a1a2…an→a=[a1a2⋮an]   where  ai∈F21.a_1a_2 \ldots a_n \rightarrow \bm{a} = \begin{bmatrix} a_{1} \\ a_{2} \\ \vdots \\ a_{n} \end{bmatrix} ~ ~ ~{\rm where} ~ ~a_i \in \mathbb{F}^1_2.

Definition

A classical linear code is a subspace C⊆F2n\mathcal{C} \subseteq \mathbb{F}^n_2. All of elements of C\mathcal{C} are the code words of the error correction code.

As C\mathcal{C} is a subspace, it holds that for any a,b∈C\bm{a}, \bm{b} \in \mathcal{C} that

a+b∈C,\bm{a} + \bm{b} \in \mathcal{C},

where all addition is modulo 2. Hence, the sum of any two code words is another code word.

If kk logical bits are encoded, then dim(C)=k{\rm dim}(\mathcal{C})=k.

Code Representation

List Code Words

The most obvious — but expensive — method for representing a code is to list all of its code words.

Examples

Error Detection With Parity

Logical bit-string →\rightarrow Code Word:

000→[0000]t001→[0011]t010→[0101]t011→[0110]t100→[1001]t101→[1010]t110→[1100]t111→[1111]t\begin{align*} &000 \rightarrow [0000]^t \\ &001 \rightarrow [0011]^t \\ &010 \rightarrow [0101]^t \\ &011 \rightarrow [0110]^t \\ &100 \rightarrow [1001]^t \\ &101 \rightarrow [1010]^t \\ &110 \rightarrow [1100]^t \\ &111 \rightarrow [1111]^t \\ \end{align*}
Error Correction With Parity

Logical bit-string →\rightarrow Code Word:

000→[000,000]t001→[001,011]t010→[010,101]t011→[011,110]t100→[100,110]t101→[101,101]t110→[110,011]t111→[111,000]t\begin{align*} &000 \rightarrow [000,000]^t \\ &001 \rightarrow [001,011]^t \\ &010 \rightarrow [010,101]^t \\ &011 \rightarrow [011,110]^t \\ &100 \rightarrow [100,110]^t \\ &101 \rightarrow [101,101]^t \\ &110 \rightarrow [110,011]^t \\ &111 \rightarrow [111,000]^t \\ \end{align*}

Generators

A set of vectors u1,u2,…,um∈C\bm{u}_1, \bm{u}_2, \ldots, \bm{u}_m \in \mathcal{C} is said generate the code C\mathcal{C} if

C={α1u1+α2u2+…+αmum:αi∈F21 ∀i}\mathcal{C} = \big\{ \alpha_1 \bm{u}_1 + \alpha_2 \bm{u}_2 + \ldots + \alpha_m \bm{u}_m : \alpha_i \in \mathbb{F}^1_2~\forall i \big\}

If all u1,u2,…,um∈C\bm{u}_1, \bm{u}_2, \ldots, \bm{u}_m \in \mathcal{C} are linearly independent then the set is called a minimal generating set.

From this definition, it can be see that a minimal generating set of a code is a basis for the subspace C\mathcal{C}, meaning m=km=k.

Consider now a code encoding kk logical bits into nn physical bits, such that p=n−kp=n-k parity bits are used for the error correction. Then, from a minimal generating set of a code (they are not unique), a generating matrix GG can be created as follows

G=[Ik×kAp×k],G = \left[ \begin{array}{cc} \mathbb{I}_{k \times k} \\ \hline A_{p \times k} \end{array} \right],

such that Ik×k\mathbb{I}_{k \times k} is the k×kk \times k identity matrix and Ap×kA_{p \times k} is an p×kp \times k matrix that encodes which parity checks occur.

If x∈F2k\bm{x} \in \mathbb{F}^k_2 is an unencoded bit-string, then its encoded bit-string y∈C⊆F2n\bm{y} \in \mathcal{C} \subseteq \mathbb{F}^n_2, which includes its parity bits, is given by

y=Gx,\bm{y} = G \bm{x},

hence the term generating matrix for GG.

Examples

Error Detection With Parity

A minimum generating set for this code is given by the code-words

001→[0011]t010→[0101]t100→[1001]t\begin{align*} &001 \rightarrow [0011]^t \\ &010 \rightarrow [0101]^t \\ &100 \rightarrow [1001]^t \\ \end{align*}

It can easily be see that for any arbitrary unencoded bit-string a1a2a3a_1a_2a_3 it follows that

[a1a2a3p(a)]=a1[1001]+a2[0101]+a3[0011]\begin{bmatrix} a_{1} \\ a_{2} \\ a_3 \\ p(\bm{a}) \end{bmatrix} = a_1 \begin{bmatrix} 1 \\ 0 \\ 0 \\ 1 \end{bmatrix} + a_2 \begin{bmatrix} 0 \\ 1 \\ 0 \\ 1 \end{bmatrix} + a_3 \begin{bmatrix} 0 \\ 0 \\ 1 \\ 1 \end{bmatrix}

The generating matrix is then

G=[100010001111].G = \left[ \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \hline 1 & 1 & 1 \end{array} \right].
Error Correction With Parity

A minimum generating set for this code is given by the code-words

001→[001,011]t010→[010,101]t100→[100,110]t\begin{align*} &001 \rightarrow [001,011]^t \\ &010 \rightarrow [010,101]^t \\ &100 \rightarrow [100,110]^t \\ \end{align*}

such that for any arbitrary unencoded bit-string a1a2a3a_1a_2a_3 it follows that

[a1a2a3a1⊕a2a1⊕a3a2⊕a3]=a1[100110]+a2[010101]+a3[001011]\begin{bmatrix} a_{1} \\ a_{2} \\ a_3 \\ a_1 \oplus a_2 \\ a_1 \oplus a_3 \\ a_2 \oplus a_3 \end{bmatrix} = a_1 \begin{bmatrix} 1 \\ 0 \\ 0 \\ 1 \\ 1 \\ 0 \end{bmatrix} + a_2 \begin{bmatrix} 0 \\ 1 \\ 0 \\ 1 \\ 0 \\ 1 \end{bmatrix} + a_3 \begin{bmatrix} 0 \\ 0 \\ 1 \\ 0 \\ 1 \\ 1 \end{bmatrix}

The generating matrix is then

G=[100010001110101011].G = \left[ \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \hline 1 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 1 \end{array} \right].

Parity Checks

Let v1,v2,…,vm∈F2n\bm{v}_1, \bm{v}_2, \ldots, \bm{v}_m \in \mathbb{F}^n_2 represented a set of parity checks. A codespace C\mathcal{C} can then be defined as

C={a∈F2n:a⋅vi=0 ∀ i}.\mathcal{C} = \big\{ \bm{a} \in \mathbb{F}^n_2 : \bm{a} \cdot \bm{v}_i = 0 ~\forall~i \big\}.

In words, the code space is defined to be the set of vectors in F2n\mathbb{F}^n_2 whose dot product with the set of vector v1,v2,…,vm∈F2n\bm{v}_1, \bm{v}_2, \ldots, \bm{v}_m \in \mathbb{F}^n_2 is zero.

Dot Product as a Parity Check

Consider a 3 bit string encoded as 4 physical bits,

a=[a1a2a3a1⊕a3],\bm{a} = \begin{bmatrix} a_1 \\ a_2 \\ a_3 \\ a_1 \oplus a_3 \end{bmatrix},

where the 4th physical bit stores the parity check bit a1⊕a3a_1 \oplus a_3.

If this is valid code word, and one wants to check to see if it remains a valid codeword, this can be done through the vector

v=[1011],\bm{v} = \begin{bmatrix} 1 \\ 0 \\ 1 \\ 1 \end{bmatrix},

as

a⋅v=[a1a2a3a1⊕a3]⋅[1011]=a1⊕a3⊕(a1⊕a3).\bm{a} \cdot \bm{v} = \begin{bmatrix} a_1 \\ a_2 \\ a_3 \\ a_1 \oplus a_3 \end{bmatrix} \cdot \begin{bmatrix} 1 \\ 0 \\ 1 \\ 1 \end{bmatrix} = a_1 \oplus a_3 \oplus (a_1 \oplus a_3).

Hence, if there has been a bit-flip on either the 1st, 3rd or 4th bit (the parity bit), then a⋅v≠0\bm{a} \cdot \bm{v} \neq 0.

As above, consider a code encoding kk logical bits into nn physical bits, such that p=n−kp=n-k parity bits are used for the error correction. Then, the parity checks can be formulated in terms of a parity matrix HH as

H=[Ap×k ∣ Ip×p],H = \left[ \begin{array}{c} A_{p \times k} ~ \vert ~ \mathbb{I}_{p \times p} \\ \end{array} \right],

such that Ip×p\mathbb{I}_{p \times p} is the k×kk \times k identity matrix and Ap×kA_{p \times k} is an p×kp \times k matrix that encodes which parity checks occur. Note, Ap×kA_{p \times k} is the same as in the generating matrix.

If y∈F2n\bm{y} \in \mathbb{F}^n_2 is an encoded bit-string, then its a code word if and only if

Hy=0.H \bm{y} = 0.

The codespace can therefore be defined more formally as the kernel of the parity check matrix.

Examples

Error Detection With Parity

The parity matrix of this code is

H=[111 ∣ 1].H = \left[ \begin{array}{cccc} 1 & 1 & 1 ~\vert ~ 1 \end{array} \right].

Now, consider an arbitrary code work

a=[a1a2a3a1⊕a2⊕a3].\bm{a} = \begin{bmatrix} a_1 \\ a_2 \\ a_3 \\ a_1 \oplus a_2 \oplus a_3 \end{bmatrix}.

It can then be seen that

Ha=[111 ∣ 1][a1a2a3a1⊕a2⊕a3]=a1⊕a2⊕a3⊕(a1⊕a2⊕a3)=0.\begin{align*} H \bm{a} &= \left[ \begin{array}{cccc} 1 & 1 & 1 ~\vert ~ 1 \end{array} \right] \begin{bmatrix} a_1 \\ a_2 \\ a_3 \\ a_1 \oplus a_2 \oplus a_3 \end{bmatrix} \\ &= a_1 \oplus a_2 \oplus a_3 \oplus (a_1 \oplus a_2 \oplus a_3) \\ &= 0. \end{align*}
Error Correction With Parity

The parity matrix of this code is

H=[110 ∣ 100101 ∣ 010011 ∣ 001].H = \left[ \begin{array}{cccccc} 1 & 1 & 0 ~ \vert ~ 1 & 0 & 0 \\ 1 & 0 & 1 ~ \vert ~ 0 & 1 & 0 \\ 0 & 1 & 1 ~ \vert ~ 0 & 0 & 1 \end{array} \right].

Now, consider an arbitrary code work

a=[a1a2a3a1⊕a2a1⊕a3a2⊕a3].\bm{a} = \begin{bmatrix} a_1 \\ a_2 \\ a_3 \\ a_1 \oplus a_2 \\ a_1 \oplus a_3 \\ a_2 \oplus a_3 \\ \end{bmatrix}.

It can then be seen that

Ha=[a1⊕a2⊕(a1⊕a2)a1⊕a3⊕(a1⊕a3)a2⊕a3⊕(a2⊕a3)]=0.\begin{align*} H \bm{a} &= \begin{bmatrix} a_1 \oplus a_2 \oplus (a_1 \oplus a_2) \\ a_1 \oplus a_3 \oplus (a_1 \oplus a_3) \\ a_2 \oplus a_3 \oplus (a_2 \oplus a_3) \\ \end{bmatrix} \\ &= \bm{0}. \end{align*}

Error Syndromes

Given an unknown encoded bit-string y′∈F2n\bm{y}' \in \mathbb{F}^n_2, the syndrome of the code s∈F2p\bm{s} \in \mathbb{F}^p_2 is given by

s=Hy′.\bm{s} = H \bm{y}'.

The aim is then for the syndrome s∈F2p\bm{s} \in \mathbb{F}^p_2 to determine where an error occurred.

Examples

Error Correction With Parity

The parity matrix of this code is

H=[110 ∣ 100101 ∣ 010011 ∣ 001].H = \left[ \begin{array}{cccccc} 1 & 1 & 0 ~ \vert ~ 1 & 0 & 0 \\ 1 & 0 & 1 ~ \vert ~ 0 & 1 & 0 \\ 0 & 1 & 1 ~ \vert ~ 0 & 0 & 1 \end{array} \right].

Now, consider an arbitrary code word y\bm{y} where an error occurs on the 2 logical bit

y=[y1y2y3y1⊕y2y1⊕y3y2⊕y3]→y′=[y1y2⊕1y3y1⊕y2y1⊕y3y2⊕y3].\bm{y} = \begin{bmatrix} y_1 \\ y_2 \\ y_3 \\ y_1 \oplus y_2 \\ y_1 \oplus y_3 \\ y_2 \oplus y_3 \\ \end{bmatrix} \rightarrow \bm{y}' = \begin{bmatrix} y_1 \\ y_2 \oplus 1 \\ y_3 \\ y_1 \oplus y_2 \\ y_1 \oplus y_3 \\ y_2 \oplus y_3 \\ \end{bmatrix}.

It can then be seen that the syndrome will be

Hy′=[y1⊕(y2⊕1)⊕(y1⊕y2)y1⊕y3⊕(y1⊕y3)(y2⊕1)⊕y3⊕(y2⊕y3)]=[101],\begin{align*} H \bm{y}' &= \begin{bmatrix} y_1 \oplus (y_2 \oplus 1) \oplus (y_1 \oplus y_2) \\ y_1 \oplus y_3 \oplus (y_1 \oplus y_3) \\ (y_2 \oplus 1) \oplus y_3 \oplus (y_2 \oplus y_3) \\ \end{bmatrix} \\ &= \begin{bmatrix} 1 \\ 0 \\ 1 \end{bmatrix}, \end{align*}

as expected from the error syndromes of the code detailed here.