Tutorial Basic Information and Coding 2 With Answers
Tutorial Basic Information and Coding 2 With Answers
1) Consider a source that emits a sequence of symbols that are i.i.d. (independently and identically
distributed) according to the probability mass function:
P(symbol = a) = 0.7 P(symbol = b) = 0.15 P(symbol = c) = 0.15
Propose a coding scheme that codes each symbol as bits, and uses a) fixed length coding, b) variable length
coding using as few bits per symbol as possible in each case. Compare each code with the Entropy and
decide which is best.
b)
A B C D SYMBOLS
000 101 010 110 CODEWORDS
c) A B C SYMBOLS
0 1 10 CODEWORDS
d) A B C SYMBOLS
0 10 11 CODEWORDS
3) Using the Fano technique we have studied, design a prefix code for:
a) Symbol A B C D E
Probabilities 0.385 0.179 0.154 0.154 0.128
b) Symbol A B C D E
Probabilities 0.4 0.25 0.125 0.125 0.1
c) Symbol A B C D E
Probabilities 0.3 0.2 0.2 0.2 0.1
d) Symbol A B C D E
Probabilities 0.6 0.1 0.1 0.1 0.1
In each case, determine the mean number of bits per symbol that your coding scheme requires, and
compare with Entropy.
Using this to determine the probabilities associated with each of the hexadecimal symbols, and then
calculate the Entropy.
If each hexadecimal symbol has probability 1/16, what then is the number of bits that would be needed to
encode each symbol?
6) Webpage
https://pi.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html
b) Variable length per symbol coding, using a few bits per symbol, might be: 0 is a, 10 is b, 11 is c
Mean codeword length for fixed length coding = 2 bits per symbol
Mean codeword length for variable length coding = 0.7*(1) + 0.15*(2) + 0.15*(2) = 1.3 bits per
symbol.
So the variable length code is better in this case, as it uses fewer bits per symbol.
b)
A B C D SYMBOLS
000 101 010 110 CODEWORDS
Yes, no codeword is a prefix of any other
c) A B C SYMBOLS
0 1 10 CODEWORDS
No, codeword “1” is a prefix of codeword “10”
d) A B C SYMBOLS
0 10 11 CODEWORDS
Yes, no codeword is a prefix of any other
3) Using the Fano technique we have studied, design a prefix code for:
a) Symbol A B C D E
Probabilities 0.385 0.179 0.154 0.154 0.128
1 1 1 1
𝐻2 = 0.385. log 2 (0.385) + 0.179. log 2 (0.179) + 0.154. log 2 (0.154) + 0.154. log 2 (0.154) +
1
0.128. log 2 (0.128) = 0.53 + 0.4443 + 0.4156 + 0.4156 + 0.3796 = 2.185bits per symbol
b) Symbol A B C D E
Probabilities 0.4 0.25 0.125 0.125 0.1
1 1 1 1
𝐻2 = 0.4. log 2 (0.4) + 0.25. log 2 (0.25) + 0.125. log 2 (0.125) + 0.125. log 2 (0.125) +
1
0.1. log 2 (0.1) = 0.5288 + 0.5 + 0.375 + 0.375 + 0.3322 = 2.111bits per symbol
1 1 1 1 1
𝐻2 = 0.3. log 2 ( ) + 0.2. log 2 ( ) + 0.2. log 2 ( ) + 0.2. log 2 ( ) + 0.1. log 2 ( ) = 0.5211 + 0.4644 +
0.3 0.2 0.2 0.2 0.1
0.4644 + 0.4644 + 0.3322 = 2.246 bits per symbol
d) d) Symbol A B C D E
Probabilities 0.6 0.1 0.1 0.1 0.1
1 1 1 1 1
𝐻2 = 0.6. log 2 (0.6) + 0.1. log 2 (0.1) + 0.1. log 2 (0.1) + 0.1. log 2 (0.1) + 0.1. log 2 (0.1) = 0.4422 + 0.3322 +
0.3322 + 0.3322 + 0.3322 = 1.771 bits per symbol
Symbol X Y Z A
Probability 0.5 0.2 0.2 0.1
They are to be encoded and transmitted down a communications channel. If the symbol generation rate is
1 symbol per millisec, what bitrate is needed in the channel a) as an absolute minimum, b) as a practical
minimum if a prefix code is used (using Fano’s method), c) if fixed length encoding is used.
1 1 1 1
𝐻2 = 0.5. log 2 ( ) + 0.2. log 2 ( ) + 0.2. log 2 ( ) + 0.1. log 2 ( ) = 0.5 + 0.4644 + 0.4644 + 0.3322 =
0.5 0.2 0.2 0.1
1.761 bits per symbol
Therefore the bitrate using prefix coding = 1000 * 1.9 = 1900 bps
Therefore the bitrate using fixed length coding = 1000 * 2 = 2000 bps
• P(0) = 124/192
• P(1) = 11/192
• P(2) = 7/192
• P(3) = 1/192
• P(4) = 9/192
• P(6) = 4/192
• P(7) = 2/192
• P(8) = 14/192
• P(9) = 6/192
• P(a) = 4/192
• P(c) = 4/192
• P(d) = 1/192
• P(e) = 3/192
• P(f) = 2/192
If each hexadecimal symbol has probability 1/16, what then is the number of bits that would be needed to
encode each symbol?
https://pi.math.cornell.edu/~mec/2003-2004/cryptography/subs/frequencies.html