In Experiment-1, we provided a brief introduction to block codes and also defined a class of block codes, linear block codes. For rest of the experiments in this virtual lab we shall now focus on linear block codes. In Experiment-1, we also introduced two simple classes of linear block codes, repetition and single parity check codes. In this experiment, we shall focus on the theory general linear block codes. We shall study two important matrices associated with the given linear block code, generator matrix (denoted by G) and parity check matrix (denoted by H).
The theory associated with Experiment-2 is divided into two parts:
Generator Matrix
Parity Check Matrix
1. Generator matrix
Recall that a linear block code C(n,k) is a k-dimensional subspace of the vector space F2n (see Experiment-1, Part-2 Theory).
For any linear block code, there exists a matrix G∈F2k×n such that the codeword v∈F2n corresponding to the message m∈F2k is given by
mG=v, i.e.,
This matrix G is called as a generator matrix of
the given linear block code. Note that the given code is completely
described by the generator matrix since by considering all possible message
vectors in F2k, one can obtain the entire codebook.
Let us consider some examples.
Example-1: For REP-3 code, the codewords corresponding to messages
0 and 1 can be obtained as
[000][111]=[0][111]=[1][111],
where it can be seen that the matrix
G=[111] is a generator matrix.
Example-2: For (3,2) SPC code, the messages and the corresponding codewords are given below:
Table 1: Messages and codewords for the (3,2) single parity check (SPC) code.
These codewords can be written as
[000]=[00][100111]
[011]=[01][100111]
[101]=[10][100111]
[110]=[11][100111],
where the matrix
G=[100111]
is a generator matrix of (3,2) SPC code.
Example-3: Consider the following generator matrix.
G=[10010111]
One can obtain the linear block code generated by this generator matrix by obtaining all possible codewords corresponding to all possible messages in F22 as follows.
[00][10010111]=[0000]
[01][10010111]=[0111]
[10][10010111]=[1001]
[11][10010111]=[1110]
Thus the linear block code C(4,2) generated by this generator matrix will be
Example-4: Consider the following generator matrix.
G=100010100111011
It can be verified that the linear block code C(5,3) generated by this generator matrix will be
C(5,3)={[00000],[10110],[01011],[00011],[11101],[10101],[01000],[11110]}.
1.1 Encoding Examples using Generator Matrix
Let us now look at detailed step-by-step encoding examples for different messages.
Example 1.1: Consider a (5,3) linear block code with generator matrix
1.2 Obtaining a generator matrix from the given codebook
In Examples-3 and 4, we illustrated how to obtain linear block code corresponding to the given generator matrix. Let us now discuss how to obtain a generator matrix from the given linear block code C(n,k). Recall that a linear block code C(n,k) is a k-dimensional subspace of the vector space F2n. Let g1,g2,…,gk be a basis of this subspace (preliminaries about basis of a vector space are discussed in Experiment-1, Part-1 Theory).
Obtain a matrix G∈F2k×n corresponding to this basis as follows
G=←←←g1g2⋮gk→→→.
Note that the given code C(n,k)=span{g1,g2,…,gk}, i.e., the rows of the matrix G defined in Eq. (1) generate (span) the linear block code C(n,k). Hence this matrix G is termed as a generator matrix. Note that different bases of the vector space C(n,k) will correspond to a different generator matrix and hence a generator matrix for the given code is not unique. For Examples-3 and 4 it can be verified that the rows corresponding to the respective generator matrices does form a basis for the respective linear block codes.
1.3 Systematic generator matrix
A linear block code C(n,k) is said to be systematic if every codeword v∈C(n,k) can be written as
v=[mp],
where m∈F2k is the message corresponding to the codeword v and p∈F2n−k is the vector corresponding to parity bits. It can be seen that Examples-1, 2, and 3 are systematic codes whereas Example-4 is not a systematic code.
For a systematic code, it is possible to obtain a generator matrix that can be written as
G=[IkP],
where P is some matrix in F2k×(n−k) and Ik∈F2k×k is
an identity matrix given by
Ik=10⋮001⋮0…………00⋮1.
Note that an identity matrix Ik is a diagonal matrix with 1 as diagonal entries.
It can be verified that the generator matrices corresponding to Examples-1, 2, and 3 can be written as G=[IkP]. For example, generator matrix of Example-2 can be written as
A linear block code can also be defined using a parity check matrix H∈F2(n−k)×n as follows.
Definition 1 (Linear block code C(n,k)): For the given parity check matrix H∈F2(n−k)×n, the linear block code corresponding to it is defined as the collection of all possible vectors v∈F2n that satisfy the condition vHT=0, i.e.,
C(n,k)={v∈F2nsuchthatvHT=0}.
It can be seen from Definition 1 that, one can verify whether the given vector is a codeword or not using a parity check matrix.
Similar to generator matrix, a parity check matrix also need not be unique. We shall next define the dual code
C⊥(n,n−k) of the linear block code C(n,k).
Definition 2 (Dual code): Consider a linear block code C(n,k) with parity check matrix H. Let C⊥(n,n−k) be the linear block obtained by choosing H as its generator matrix. Then C⊥(n,n−k) is said to be the dual code of C(n,k), i.e., for any v∈C(n,k) and w∈C⊥(n,n−k) we have vwT=0.
For the systematic code with generator matrix G=[IkP], parity check matrix H can be obtained as
H=[PTIn−k],
where In−k denotes an identity matrix with n−k rows and columns. For Example-2, parity check matrix can be obtained as (see Eq. (2))
H=[PTIn−k]=[111],
where P is defined in Eq. (2). For Example-3, parity check matrix can be obtained as (see Eq. (3))
H=[P′TIn−k]=[01111001],
where P′ is defined in Eq. (3).
2.1 Verification Examples using Parity Check Matrix
Let us now look at detailed examples of verifying whether vectors are codewords using the parity check matrix.
Example 2.1: Consider the (3,2) SPC code from Example-2 with parity check matrix
H=[111].
(a) Verify if v=[101] is a codeword:
vHT=[101]111=0.
Since vHT=0, vis a codeword.
(b) Verify if v=[111] is a codeword:
vHT=[111]111=1.
Since vHT=1=0, vis not a codeword.
Example 2.2: Consider the (4,2) code from Example-3 with parity check matrix
H=[01111001].
(a) Verify if v=[1001] is a codeword:
vHT=[1001]01101101=[00].
Since vHT=0, vis a codeword.
(b) Verify if v=[1111] is a codeword:
vHT=[1111]01101101=[01].
Since vHT=0, vis not a codeword.
(c) Verify if v=[1110] is a codeword:
vHT=[1110]01101101=[00].
Since vHT=0, vis a codeword.
Example 2.3: Consider a (5,3) code with parity check matrix
H=[1110011001].
(a) Verify if v=[11100] is a codeword:
vHT=[11100]1101010101=[00].
Since vHT=0, vis a codeword.
(b) Verify if v=[01010] is a codeword:
vHT=[01010]1101010101=[00].
Since vHT=0, vis a codeword.
2.2 Combined Encoding and Verification Example
Example 2.4: Consider a (6,4) systematic linear block code with generator matrix
(b) Verify that the encoded codeword satisfies vHT=0:
vHT=[101101]110110101101=[00].✓
This confirms that the encoding is correct!
2.3 Properties of Parity Check Matrices
We shall now summarize some properties of parity check matrices.
A generator matrix G∈F2k×n and parity check matrix H∈F2(n−k)×n associated with the given linear block code satisfy the following condition
GHT=0.
Example: For the (3,2) SPC code, we have G=[100111] and H=[111]. Let's verify:
GHT=[100111]111=[00].✓
Consider a linear block code C(n,k) with parity check matrix H. Then a vector v∈F2n is a codeword in C(n,k) if and only if vHT=0.
Consider a linear block code C(n,k) with parity check matrix H. Then the minimum distance dmin (see Experiment-1 Theory, Definition 13) of C(n,k) is equal to the smallest number of columns of H that sum to 0.
Example: For Example-3 with H=[01111001], we can verify that columns 1 and 4 sum to zero:
[01]+[01]=[00].
Similarly, columns 2 and 3 sum to zero:
[11]+[10]=[01]+[10]=[00].
Since we need minimum 2 columns to sum to 0, the minimum distance dmin=2.