SP19HW3
SP19HW3
Recommended: Solve HW# 4, 5 from spring 2017 for practice (appended at the end)
Programming assignment: You can use any programming language you prefer (MATLAB,
Python, C/C++, or Julia, for example). Write down your code as clearly as possible and
add suitable comments. You should write your program from scratch. However, it is okay to
use some common functions such as sort or random generators in your code. Submit your
code and the output plots to AFAZELIC@UCSD.EDU or turn in the hard copies during the office
hours on Friday afternoon.
0 0 0 1 1 1 1
In this case, recall that the parity check matrix H is obtained easily by H = [AT |In−k ].
(a) Recall that the minimum distance decoding is maximum likelihood decoding for
BSC(p), where p < 1/2. Write a minimum distance decoder function
mindistdec(y,C). This function takes a received bits y and a codebook C as
inputs. (To implement this, you may need to write a function for generating the
codebook for a given generator matrix G.)
(b) Write a syndrome decoder function syndromedec(y,H), which takes a received
bits y and a parity check matrix H as inputs.
(c) For the (7, 4) Hamming code, verify that any one bit error in code bits can be
corrected by both mindistdec and syndromedec. Hence, for simplicity, we now
use mindistdec as our decoder for the rest of this problem.
(d) (NOT a programming) For the (7, 4) Hamming code, find the formula of the
probability of decoding to a wrong codeword when the code is used for BSC(p).
(e) We want to run a simulation that verifies the result found in Problem (c). For
p = 0.05 : 0.05 : 0.5, do the following steps 1,000 times to get a good estimate of
the decoded word error rate (WER).
1
i. Generate 4 random binary digits.
ii. Encode them by calculating the 3 check digits, or using generator matrix G.
iii. Put the codeword through BSC(p).
iv. Decode the received 7-bit vector to a 4-bit word.
v. Compare the decoded word with the transmitted word and count word errors
to find word error rate (WER). Also count the errors in the information
positions of the code words to obtain an estimate of the decoded bit error
probability (BER).
Plot your simulation results p vs. BER(p) and p vs. WER(p), along with the
analytical expression found in part (d). Is the bit error probability larger or
smaller than the word error probability?
(f) (10% bonus) Now we consider another systematic generator matrix
1 0 0 0 1 0 0
0 1 0 0 0 1 0
G= 0 0 1 0 0 0
.
1
0 0 0 1 1 1 1
Repeat the same experiment as in (e), and compare the results with BER and
WER of the (7,4) Hamming code.
(g) (10% bonus) Finally we examine the performance of a randomly generated (7, 4)
systematic generator matrices. Generate a random 4 × 3 binary matrix A and use
G = [I4 , A] as our generator matrix. For each G, repeat the same experiment in
(e), and take averages of BERs and WERs over the random matrices. Compare
the results with BER and WER of the (7,4) Hamming code. Is there any p where a
randomly generated G performs better than the Hamming (7,4) code on average?
(Note: you do not have to compute the theoretical expression of WER for parts (f)
and (g).)
2
UCSD ECE154C Handout #14
Prof. Young-Han Kim Thursday, May 11, 2017
Homework Set #4
(Due: Thursday, May 18, 2017)
1. Suppose that a pair of dice are thrown, each independently taking on the values
{1, 2, 3, 4, 5, 6} with equal probabilities. Let X denote the output of the first die and
Y denote the output of the second die. Let Z = X + Y and Q = Z mod 2. Compute
the following entropies.
1−a 1−c
1 1 1 1
a c
X1 Y 1 = X2 Y2
b d
0 0 0 0
1−b 1−d
(a) Draw a single channel with binary input and binary output that is equivalent to
this cascade.
(b) Repeat part (a) when the order of the two channels is reversed.
(c) Show that a cascade of two binary symmetric channels is also a binary symmetric
channel.
1
UCSD ECE154C Handout #15
Prof. Young-Han Kim Thursday, May 18, 2017
1. Suppose that a pair of dice are thrown, each independently taking on the values
{1, 2, 3, 4, 5, 6} with equal probabilities. Let X denote the output of the first die and
Y denote the output of the second die. Let Z = X + Y and Q = Z mod 2. Compute
the following entropies.
Solution:
(a) We have H(X) = H(Y ) = log 6 = 2.585. By considering all the combinations of
X and Y , we have
6 1 2 3 4 5 36
H(Z) = log 6+2 log 36+ log 18+ log 12+ log 9+ log = 3.27.
36 36 36 36 36 36 5
(b) We have
Hence
H(X, Z) = H(X|Z) + H(Z) = 5.17
and
H(Z|X) = H(X, Z) − H(X) = 2.585.
1
(c) Since given X is even, the binary random variable Q = 0 if Y is even and Q = 1
if Y is odd. Similarly for the case when X is odd. Thus H(Q|X) = 1. Note that
since H(Q) = 1, X and Q are independent of each other. Thus
and
H(X|Q) = H(Q, X) − H(Q) = 2.585.
(d) Since Q is a function of Z, we have H(Q|Z) = 0. Thus
and
H(Z|Q) = H(Z, Q) − H(Q) = 2.274.
(e) Since Z = X + Y , we have H(Z|X, Y ) = 0 and H(Y |X, Z) = 0. Note that
H(X, Y ) = H(X) + H(Y ) since X and Y are independent, hence
and
H(X, Y |Z) = H(Y |X, Z) + H(X|Z) = H(X|Z) = 1.896.
(f) Since H(Q|X, Y, Z) = 0, we have
Thus
H(X, Y, Z|Q) = H(X, Y, Z, Q) − H(Q) = 5.17 − 1 = 4.17.
1−a 1−c
1 1 1 1
a c
X1 Y 1 = X2 Y2
b d
0 0 0 0
1−b 1−d
(a) Draw a single channel with binary input and binary output that is equivalent to
this cascade.
(b) Repeat part (a) when the order of the two channels is reversed.
(c) Show that a cascade of two binary symmetric channels is also a binary symmetric
channel.
2
Solution:
3
UCSD ECE154C Handout #16
Prof. Young-Han Kim Thursday, May 18, 2017
Homework Set #5
(Due: Tuesday, May 30, 2017)
3. For the (23, 12) Golay code given in the notes, calculate the probability of decoding to
the wrong codeword if the code is used to correct errors caused by a binary symmetric
channel with bit error probability p.
4. Consider the (15, 7) parity check code with parity check matrix given below:
1 0 0 0 1 0 0 1 1 0 1 0 1 1 1
0 1 0 0 1 1 0 1 0 1 1 1 1 0 0
0 0 1 0 0 1 1 0 1 0 1 1 1 1 0
0 0 0 1 0 0 1 1 0 1 0 1 1 1 1
H = 1 0 0 0 1
1 0 0 0 1 1 0 0 0 1
0 0 0 1 1 0 0 0 1 1 0 0 0 1 1
0 0 1 0 1 0 0 1 0 1 0 0 1 0 1
0 1 1 1 1 0 1 1 1 1 0 1 1 1 1
(a) Without changing the order of the digits put the parity check matrix in a form
with a 8-by-8 identity matrix on the right.
(b) Give the generator matrix of the code with a 7 by 7 unit matrix on the left.
(c) What is the minimum Hamming distance of the code?
(d) Show the form of an encoder using a table look-up. What is the size of the table?
(e) Show a decoder for the code using two tables. What are the size of the tables?
1
UCSD ECE154C Handout #17
Prof. Young-Han Kim Tuesday, May 30, 2017
1
For 4, 5, 6, and 7 erasures, there are 74 = 35, 75 = 21, 76 = 7, and 77 = 1 patterns
respectively. Hence the analytic expression for the probability of uncorrectable erasures
is
X 7
P(uncorrectable erasures) = ei pi (1 − p)7−i
i=3
where ei is the number of patterns with i erasures that cannot be corrected calculated
above, i.e., e3 = 7, e4 = 35, e5 = 21, e6 = 7, e7 = 1.
3. For the (23, 12) Golay code given in the notes, calculate the probability of decoding to
the wrong codeword if the code is used to correct errors caused by a binary symmetric
channel with bit error probability p.
Solution: From the lecture, we know that the Hamming (23, 12) Golay code has
dmin = 7. Hence it can correct all error patterns of ⌊ dmin2 −1 ⌋ errors or less. The
probability of decoding to a correct codeword Pc can be given as
3
X 23
Pc = pi (1 − p)23−i
i=0
i
Pw = 1 − Pc .
4. Consider the (15, 7) parity check code with parity check matrix given below:
1 0 0 0 1 0 0 1 1 0 1 0 1 1 1
0 1 0 0 1 1 0 1 0 1 1 1 1 0 0
0 0 1 0 0 1 1 0 1 0 1 1 1 1 0
0 0 0 1 0 0 1 1 0 1 0 1 1 1 1
H = 1 0 0 0 1
1 0 0 0 1 1 0 0 0 1
0 0 0 1 1 0 0 0 1 1 0 0 0 1 1
0 0 1 0 1 0 0 1 0 1 0 0 1 0 1
0 1 1 1 1 0 1 1 1 1 0 1 1 1 1
(a) Without changing the order of the digits put the parity check matrix in a form
with a 8-by-8 identity matrix on the right.
(b) Give the generator matrix of the code with a 7 by 7 unit matrix on the left.
(c) What is the minimum Hamming distance of the code?
(d) Show the form of an encoder using a table look-up. What is the size of the table?
(e) Show a decoder for the code using two tables. What are the size of the tables?
2
Solution: Let H = [A|B] where A is a 8 × 7 matrix and B is a 8 × 8 matrix. Then
H ′ = B −1 [A|B] = [B −1 A|I8×8 ],