Professional Documents
Culture Documents
Communications Lab: The Preparatory Exercises Must Be Solved Prior To The Date of The Experiment
Communications Lab: The Preparatory Exercises Must Be Solved Prior To The Date of The Experiment
Name: Matr.-Nr.:
Supervisor: Date:
N T S
The preparatory exercises must be solved prior to the date of the experiment.
CONTENTS i
Contents
1 Introduction 1
2 Theoretical background 1
2.1 Linear block codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.1.1 Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.1.2 Decoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Reed-Solomon codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.1 Galois-Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.2 DFT-based coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.3 Algebraic decoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 Preparatory Exercises 11
3.1 Linear block codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Reed-Solomon codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4 Experimental Tasks 13
4.1 Hamming codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.1.1 Generation of Hamming codes . . . . . . . . . . . . . . . . . . . . . . 13
4.1.2 Encoding using generator matrix . . . . . . . . . . . . . . . . . . . . . 13
4.1.3 Channel modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.1.4 Decoding using parity check matrix . . . . . . . . . . . . . . . . . . . 14
4.1.5 Error Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2 Reed-Solomon codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.2.1 Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.2.2 Channel modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2.3 Decoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.3 Comparison between Hamming and Reed-Solomon codes . . . . . . . . . . . . 18
1
1 Introduction
When transmitting information data via a noisy channel, channel coding is used in order to
reduce the bit-error ratio (BER) at the receiver. Channel coding techniques add redundancy to
the transmitted data that is also known to the receiver. The receiver has therefore additional
information which it exploit to detect and correct errors that occured during the transmission.
In this seminar, the class of linear block codes is investigated. Reed-Solomon codes as spe-
cial linear block codes are powerful symbol-oriented codes applied in modern communication
standards Digital Audio Broadcasting (DAB), Digital Video Broadcasting (DVB) as well as in
audio compact discs (CD).
2 Theoretical background
In the following, some facts (repeated from the exercises) about linear block codes and, subse-
quently, Reed-Solomon codes will be summarized that are intended to assist the preparationary
exercises.
c = u·G (1)
(2)
where u is the uncoded information word with k bits, c is the corresponding code word for the
information word u with n bits and G is the n × k generator matrix of the block code.
With the information word u = (u0 u1 u2 , the matrix multiplication equals (here an example
generator matrix is taken):
c = u·G (3)
1 1 0 1 0 0 1
c = u0 u 1 u2 · 1 0 1 0 0 1 1 (4)
1 1 1 0 1 0 0
= u0 · 1 1 0 1 0 0 1 + (5)
| {z }
1st row of G
u1 · 1 0 1 0 0 1 1 + (6)
| {z }
2 row of G
nd
u2 · 1 1 1 0 1 0 0 . (7)
| {z }
3 row of G
rd
2 2 THEORETICAL BACKGROUND
The minimum distance dmin of the code is the minimum number of digits in which two code
words are different. It is shown in the lecture that the minimum distance equals the minimum
weight of the code words:
The number of errors in the code words that can be detected at the decoder side is
te = dmin − 1 = 3 .
G −→ G′ G′ = k × n − matrix
c −→ c′ .
The code words of a systematic code is composed of the information words and parity bits. The
generator matrix of the systematic code G′ has the following structure:
.
G′ = Ik .. P Ik : Identity matrix (k × k)
P : Parity bit matrix (k × (n − k)) .
2.1 Linear block codes 3
The rows of G′ are generated by combinations of the rows of G such that the first part of the
G′ is the identity matrix Ik :
..
(1 + 2 + 3 ) row of G −→ 1 0 0 . 1 1 1 0
st nd rd
The code words of the systematic code are obtained by the matrix equation:
c′ = u · G′
With
..
1 0 0 . 1 1 1 0
′
..
G =
0 1 0 . 0 1 1 1
(8)
.
0 0 1 .. 1 1 0 1
an example code word for this systematic code is given by:
.
ua = (1 0 1) ( 1 0 1 .. 0 0 1 1 ) = c′a .
| {z } | {z }
=ua parity check bits
2.1.2 Decoding
The parity check matrix H′ is used to detect and correct errors. An important property of every
parity check matrix H is:
Now, the way how to generate H′ is described when the generator matrix of the systematic
code is given. The structures of generator and parity check matrix are
.
G′ = ( Ik .. P ) (generator matrix)
.
H′ = ( PT .. In−k ) (parity check matrix).
4 2 THEORETICAL BACKGROUND
Example: With the above determined parity bit matrix P, the parity check matrix is
1 0 1
1 1 1 0 1 1 1
P = 0 1 1 1 −→ PT = 1 1 0
1 1 0 1
0 1 1
..
1 0 1 .. 1 0 0 0
1 1 1 .. 0 1 0 0
=⇒ H′ = .
1 1 0 ... 0 0 1 0
..
0 1 1 . 0 0 0 1
Note that H′ is the parity check matrix for both code c and code c′ since they are equivalent
codes (codes with the same set of code words)!
Let us consider the following transmission model:
u G′ x y H′ x (errorfree)
channel
If only single errors are considered, the syndrome table consists of all possible resulting vectors
when e contains only one “1”:
Error at bit no. 2 e.g. e = ( 0 0 1 0 0 0 0 )
T
=⇒ s = e · H′
= ( 1 1 0 1 )
ˆ third column of H′ .
=
2.1 Linear block codes 5
if s 6= 0 =⇒ search in table
a) s included in the table =⇒ determine error vector e
b) s not included in the table =⇒ more than t = 1 errors
=⇒ not correctable
Some properties of the elements of the Galois-field (direct or extended) are summarized:
• The results of the addition and multiplication of two elements will be elements of the
Galois-field:
ai ⊕ ak = al ∈ GF ⊕ =Modulo
ˆ p addition
ai ⊗ ak = am ∈ GF ⊗ =Modulo
ˆ p multiplication.
dmin = n − k + 1
as a rule to design the code. E.g. if the code shall be able to correct t = 1 error, then
with dmin = 2t + 1 = 3 for the code length n and the information wordlength k holds
n − k = 2. n depends on the type of Galois-field and is n = pm − 1. If p and m are
given, then k can be calculated.
2.2 Reed-Solomon codes 7
1 1 1 1 1 1 1 1 4 4 4 4
1 z 3 z 2 z 1 z=2,mod5 1 3 4 2 4 2 1 3
= − inv.elem.
1 z2 z0 z2 = − =
MDFT .
1 4 1 4 4 1 4 1
1 z1 z2 z3 1 2 4 3 4 3 1 2
The inverse transform is equivalent:
a = MIDFT · AT
1 1 1 1 1 1 1 1 1 1 1 1
1 z1 z2 z3 1 z1 z2 z3 1 2 4 3
MIDFT 1 z2 z4 z6 = 1 z2 z0 z2 = 1 4
= .
1 4
1 z3 z6 z9 1 z3 z2 z1 1 3 4 2
An important property of the matrices is
MDFT · MIDFT = MIDFT · MDFT = 1 .
and transformed into the time domain. The time-domain codewords are then transmitted
via the channel. When transforming back into the frequency domain, errors can be de-
tected on the last n − k digits which are zero in case of an errorfree transmission. If not,
an error occured during the transmission.
8 2 THEORETICAL BACKGROUND
• Transmission model:
Again, the transmission model is given by the sum of coded word and error vector: r =
a + e. Note that r is the received vector in the time domain.
• Error check:
By transforming r into the frequency domain (DFT), errors can be detected on the digits
where zeros have been set. Without error, the received vector in the frequency domain
must be:
.
R = ( A0 A1 .. 0 0 ) .
| {z } | {z }
information “parity frequencies”
word length
length k n−k
• Error correction:
If there are errors, the last digits can be regarded as syndromes. E.g.:
.
R = (4 1 .. 2|{z}3 )
S = ( S0 S1 ) = ( 2 3 ).
| {z }
n−k=2
R=A+E
holds. A consists of ’0’s on the last (n − k) digits by design rules. Therefore the (n − k)
last digits of S are directly the last (n − k) digits of the error vector in the frequency
domain.
One way to detect and correct errors for RS-Codes is based on the error position polyno-
mial. The decoding steps are summarized:
must be less than the maximum number of error t that can be corrected, thus it
holds: e ≤ t.
The matrix representation for the set of equation is
S e · · · S 0 C0
0
.. ... .. . ! .
2t−e . . · .. e+1 = .. . (10)
S
2t−1 · · · S2t−e−1
Ce
0
| {z }
e+1
The equation is fulfilled for the correct value of e, which is unknown a priori. There-
fore, one should start with the most probable case e = 1:
C
0
=⇒ S1 S0 · = 0
C1
⇐⇒ S1 · C0 + S0 · C1 = 0
⇐⇒ 3 · C0 + 2 · C1 = 0 .
Since there are more variables than equations, C(x) is normalized to e.g. C1 = 1.
C(x) can be always normalized, as only zeros are important. The solution for C(x)
is found by:
=⇒ 3 · C0 + 2 = 0 |−2 = ˆ + 3 ( inverse element )
⇐⇒ 3 · C0 = 3 | · 3−1 =ˆ · 2 ( inverse element)
⇐⇒ C0 = 6 mod 5 = 1
=⇒ C(x) = 1 + 1 · x .
Note that if the matrix equation is not solvable for e = 1, try e = 2, 3, 4, . . . , t. If
the matrix equation is not solvable at all, a correction is not possible.
– Find the position of the error (optional):
Once the error polynomial is found, the next step is to look for the position of the
errors which can be determined by the following relation:
C(x = z i ) = 0 ⇐⇒ Error on position i (i = 0 · · · n − 1, z = 2) .
In this example, all values of i are tested:
C(z 0 = 1) = 2 6= 0
C(z 1 = 2) = 3 6= 0
C(z 2 = 4)[= 5] = 0 =⇒ Error on position i = 2
C(z 3 = 3) = 4 6= 0 (clear, since only a single error was assumed, e = 1) .
Now the position of the error has been found. The value of the error is calculated
in the next step.
– Find the error vector in the frequency domain:
The last (n − k) digits of E correspond to S which can be seen from:
..
E = ( E0 E1 . E E )
| 2 {z }3
n−k=2
.. ..
= ( E0 E1 . S0 S1 ) = ( E0 E1 . 2 3)
| {z }
k=2
10 2 THEORETICAL BACKGROUND
 = R “ − ” E = ( 4 1 2 3)−(2 3 2 3)=(2 3 0 0 ).
11
3 Preparatory Exercises
3.1 Linear block codes
Given is a linear block code with the generator matrix
1 1 0 0 1 0 1
G= 0 1 1 1 1 0 0 .
1 1 1 0 0 1 1
1. Calculate the number of valid codewords N and the coderate RC . Specify the complete
Code C .
2. Determine the generator matrix G′ of the appropriate systematic (separable) code C′ .
What are the codewords of the systematic code for the information words ua = 0 1 0 .
5. How is a received word y checked for errors and corrected? What are the valid codewords
that belong to the received words
ya = 1 0 0 1 0 0 1
yb = 1 1 1 0 0 1 1 .
1. Insert in the table the missing inverse elements with respect to addition and multiplication
for a ∈ GF(5).
a 0 1 2 3 4
−a
a−1
2. Determine the codewordlength n, the number of information digits k and the minimum
distance dmin .
3. Determine the matrix MDFT , that describes the discrete fourier transform (DFT) of the
codeword-vectors a and A:
AT = MDFT · aT
The matrix MDFT should only consist of elements of GF(5).
12 3 PREPARATORY EXERCISES
4. Determine the corresponding matrix MIDFT , that describes the inverse discrete fourier
transform (IDFT) of the codeword-vectors a and A:
aT = MIDFT · AT
The codeword a is transmitted via a channel. An error occurs during the transmission, such
that an error vector e = (0 2 0 0) is added to the codeword.
6. Find the received vector r and calculate the syndrome S using the DFT.
7. Determine the error position polynomial C(x) in the frequency domain and the error
positions of the received vector.
4 Experimental Tasks
4.1 Hamming codes
4.1.1 Generation of Hamming codes
The purpose of this assignment is to build a hamming code to reduce errors in a noisy binary
symmetric channel with error rate p_err. We will construct functions that are capable of en-
coding and decoding any single-error-correction (n, k) Hamming code, where n is the number
of code bits and k is the number of information bits. What are possible (n, k) combinations?
Initialize the variables:
p_err = 0.01; % bit error probability
n = ???; % codeword length
k = ???; % information word length
m = n-k; % number of parity bits
The formation of the generator matrix is simply a matter of arranging binary coded decimal
(BCD) vectors of m bits in numerical order, where m=n-k is the number of parity bits. The
vectors that correspond to integer powers of 2 (1,2,4,8,16, etc) are not included:
% generate matrix P (parity matrix)
P=[]; % initialize P
for iC=1:n
if (log2(iC)-floor(log2(iC)))>0 % check if position is not 1,2,4,8
P=[P bcd(iC,m)’]; % form P
end
end
G = [eye(k),P’]; % add identity matrix
Display the generator matrix for a (7,4) and (31,26) Hammming code.
if ( floor(length(vInfo)/k)< length(vInfo)/k )
a = mod(length(vInfo),k);
vInfo = [vInfo; zeros(k-a,1)];
end
U = reshape(vInfo,prod(size(vInfo))/k,k);
[ur,uc] = size(U); % U has dimension: num infowords x k
The product of U and G yields an xr × n matrix C of coded bits.
% Encoding all info words
C = mod(U*G,2); % C has dimension: num infowords x n
Now, C contains the code words for all information words in U.
Look at different information words and their corresponding codewords to see that it is a sys-
tematic code, e.g.: U(18454,:) and C(18454,:).
The channel is modeled as a binary symmetric channel with error probability p_err. A matlab
function channel.m has been prepared to model the channel. The function creates a vector of
length b of which e position are randomly set to 1 (the other positions are 0). Thus, p_err=e/b
and b is made equal to the total number of bits in C. The error vector is reshaped into matrix N
with the same dimensions as C. Then the received codes CN are generated by XORing the error
matrix with the code matrix.
% produce error vector with error probability p_err
N = errorv(prod(size(C)),round(prod(size(C))*p_err));
N = reshape(N,prod(size(C))/n,n); % same dimension as C
CN = xor(C,N); % add errors
Find the number of errors in N using the Matlab command find and compare it with the length
of N to verify the error probability.
Remember the structure of the parity check matrix of a systematic code. The parity check
matrix is readily computed from the matrix P above.
H = [P,eye(m)]; % parity matrix of systematic Hamming code
Display the parity check matrix H.
The binary syndromes S are calculated by multiplying the code matrix by the parity check
matrix. This results in an xr × m matrix:
% calculate syndrom vectors for all infowords
S = mod(CN*H’,2);
The decimal syndromes S_de are calculated from a simple binary to decimal conversion:
% get decimal value of syndroms
S_de = sum(((ones(ur,1)*(2.^((m-1):-1:0) )).*S)’);
These syndromes must then be related to the positions in the parity check matrix. A position
matrix Pm is generated by finding the decimal equivalent of the columns of H:
4.1 Hamming codes 15
Test the simulation program with different parameters values for p_err and different codes.
Determine the BER and fill in the following table: Plot the BERs versus the channel error rate
p_err for the different codes. What conclusions can you draw from the results?
4.2.1 Encoding
We want to transmit the same image as in 4.1. Since Matlab offers the possibility to calculate
within Galois fields and even to encode using a Reed-Solomon coder, we only need to adapt the
format of the message data. For the extended Galois field GF(2m ), m bits must be combined
such that one codeword contains m · n bits.
Start a new m-file and enter:
p_err = 0.01; % bit error probability
n = 7; % codeword length
k = 3; % information word length
m = 3; % extension field
% Note that one codeword consists of m*n bits!!!
% read data
% =========
[I,map] = imread(’image.jpg’);
level = graythresh(I);
X = im2bw(I,level);
X = double(X);
[xr,xc] = size(X);
% convert data to convenient format that it can be encoded
u = X(:);
if ( floor(length(u)/(k*m))< length(u)/(k*m) )
rest = mod(length(u),k*m);
% if there is rest, pad with zeros
4.2 Reed-Solomon codes 17
u = [u;zeros(m*k-rest,1)];
end
Then, convert m bits to decimal values. Note that Reed-Solomon codes are not binary codes:
U = reshape(u,m,length(u)/m);
U = U’;
U = bi2de(U); % convert bits to decimal values
U = reshape(U,length(U)/k,k);
Display ten rows of U by typing disp(U(1:10,:)) and disp(U(10001:10010,:)).
After reshaping the vector U into a matrix with the number of information words as number
of rows, the Matlab encoding routine requires to have the input message as a variable of type
Galois (Matlab specific).
U_gf = gf(U,m);
Now we can pass the message to the encoder:
C = rsenc(U_gf,n,k);
4.2.3 Decoding
The resulting matrix CN can be passed to the decoding routine
% Reed-Solomon decoding using Matlab toolbox function
[U_dec,cnumerr] = rsdec(CN,n,k);
The number of rows of U_dec is again equivalent to the number of information words. We
convert the matrix of decoded symbols back into a long vector and reverse all operations with
respect to the transmitter.
% convert matrix of decoded symbols to vector back
U_dec = U_dec(:);
% reverse operation with respect to transmitter
18 4 EXPERIMENTAL TASKS