22-Elec-B3 Digital Communications Systems · December 2014
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)
Paper format: Professional Engineers of Ontario, Annual Examinations — December 2014, 07-Elec-B3 Digital Communication Systems. Three hours, closed book, a PEO-approved non-programmable calculator permitted. Five questions are printed at 25 marks each; any four constitute a complete paper worth 100 marks, and only the first four appearing in the answer book are marked. Marks are shown in the left margin. All five questions are solved below, because the set as a whole is the study resource.
Reference texts.
Check — the parity-check matrix of Question 5(c) did not print on the paper. Page 3 reads “Consider a binary Hamming code with the following parity check matrix:” followed by a blank gap of roughly two lines, and then “Give the corresponding generator matrix.” The gap is genuinely empty: the matrix is missing from the printed paper itself. Parts (c) and (d) are therefore solved for the standard systematic binary (7,4) Hamming code, which is the only binary Hamming code that fits a matrix of the size the gap allows and is the canonical textbook example. The assumption is stated explicitly in the answer, exactly as Note 1 on the cover page instructs (“the candidate is urged to submit with the answer paper a clear statement of any assumptions made”). The method of parts (c) and (d) is independent of which particular Hamming matrix is intended.
Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.
Given.
| Letter | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| Probability | 0.11 | 0.05 | 0.28 | 0.17 | 0.25 | 0.14 |
The probabilities sum to $0.11 + 0.05 + 0.28 + 0.17 + 0.25 + 0.14 = 1.00$, so the description is complete and the source is memoryless.
Find. A Huffman code for the six letters and its average codeword length; the entropy of the source; a definition of a prefix code with a justification of whether Huffman codes qualify; and one genuine advantage and one genuine disadvantage of Huffman coding.
Approach. Repeatedly merge the two least probable symbols into a composite node until one node of probability 1 remains, then read the codewords off the resulting binary tree by labelling each branch 0 or 1.
| Letter | Probability $p_i$ | Codeword | Length $\ell_i$ | $p_i \ell_i$ |
|---|---|---|---|---|
| D | 0.17 | 00 | 2 | 0.34 |
| E | 0.25 | 01 | 2 | 0.50 |
| C | 0.28 | 10 | 2 | 0.56 |
| F | 0.14 | 110 | 3 | 0.42 |
| A | 0.11 | 1110 | 4 | 0.44 |
| B | 0.05 | 1111 | 4 | 0.20 |
Approach. Evaluate $H = -\sum p_i \log_2 p_i$ term by term and compare with the average codeword length found in part (a).
| $p_i$ | $-\log_2 p_i$ | $-p_i\log_2 p_i$ |
|---|---|---|
| 0.28 | 1.8365 | 0.5142 |
| 0.25 | 2.0000 | 0.5000 |
| 0.17 | 2.5564 | 0.4346 |
| 0.14 | 2.8365 | 0.3971 |
| 0.11 | 3.1844 | 0.3503 |
| 0.05 | 4.3219 | 0.2161 |
A code is a prefix code (also called prefix-free, or an instantaneous code) when no codeword is a prefix of any other codeword — that is, no codeword can be obtained by truncating a different, longer codeword. In the code of part (a), for example, 110 is a codeword while 11 is not, and although 1110 and 1111 share the leading three bits neither is a prefix of the other because they have equal length and differ in the last bit. A quick check confirms the property holds for all thirty ordered pairs of codewords.
The practical importance of the property is that it makes the code uniquely and instantaneously decodable. A receiver reading a concatenated bit stream such as 10 01 1111 00 110 can accumulate bits until the accumulated string matches a codeword and emit that letter immediately, with no need to look ahead, no need for inter-symbol markers, and no ambiguity about where one codeword ends and the next begins. A non-prefix code can be uniquely decodable but may require unbounded look-ahead, and a code in which one codeword prefixes another may be ambiguous outright.
A Huffman code is always a prefix code. The reason is structural rather than coincidental: the construction places every source letter at a leaf of a binary tree, and a codeword is the sequence of branch labels on the path from the root to that leaf. For one codeword to prefix another, the first letter’s node would have to lie on the path to the second, meaning it would be an internal node with descendants — which no leaf is. Since merging always creates a new internal node above two existing nodes and never places a symbol above another symbol, the prefix-free property is guaranteed by construction. Equivalently, the Kraft equality $\sum 2^{-\ell_i} = 1$ verified in part (a) confirms that the codeword lengths correspond to a full binary tree with all symbols at leaves.
Advantage — it is provably optimal, and instantaneously decodable. For a given set of symbol probabilities, no other uniquely decodable symbol-by-symbol code achieves a smaller average codeword length than Huffman’s: the greedy bottom-up merge is not a heuristic but an exact solution to the minimum-average-length problem over prefix codes. Here that optimum is 2.46 bits per letter, within 0.05 bit of the 2.412-bit entropy floor and 0.54 bit better than the 3-bit fixed-length alternative — a lossless reduction of roughly 18 per cent in stored or transmitted volume, obtained with a small lookup table and no arithmetic at run time. The prefix property further means decoding needs no synchronisation markers and adds no latency beyond one codeword.
Disadvantage — it needs the statistics in advance, and integer codeword lengths cost efficiency. The encoder and decoder must agree on the probability model before any data flows, so either the source statistics are known a priori or the table has to be measured and transmitted as overhead, and performance degrades whenever the real source drifts away from the assumed distribution. Because codeword lengths are whole numbers of bits, a Huffman code can only approach the entropy in steps: the residual redundancy here is 0.048 bit per letter, and in the pathological case of a highly skewed binary source the overhead approaches a full bit per symbol, which arithmetic coding avoids by allowing fractional-bit effective lengths. Two further practical weaknesses are worth stating: because the code is variable-length, a single channel bit error can shift the decoder’s codeword boundaries and corrupt an indefinite run of following letters until it accidentally resynchronises; and because the code treats letters independently it captures none of the correlation in a source with memory, where modelling the dependence — by coding blocks of letters, or by predictive or dictionary methods such as Lempel–Ziv — recovers far more than optimising the symbol code ever can.
| Quantity | Result |
|---|---|
| (a) Huffman code | D = 00, E = 01, C = 10, F = 110, A = 1110, B = 1111 |
| (a) Average codeword length | 2.46 bits/letter (Kraft sum = 1.00, so the tree is complete) |
| (b) Source entropy | 2.412 bits/letter |
| (b) Coding efficiency / redundancy | 98.06 % / 0.048 bit per letter |
| (c) Prefix code | No codeword is a prefix of another; Huffman codes always qualify because all letters sit at tree leaves |
| (d) Advantage / disadvantage | Provably minimum average length and instantaneous decoding / requires known statistics, integer-bit granularity, error propagation, ignores source memory |