<< Chapter < Page Chapter >> Page >

Since the entropy defines the smallest number of bits that can be used to encode a source, it can be used to definethe efficiency of a code

e f f i c i e n c y = e n t r o p y a v e r a g e # o f b i t s p e r s y m b o l .

Thus the efficiency of the naive code [link] is 1 . 75 / 2 = 0 . 875 while the efficiency of the variable rate code [link] is 1. Shannon's source coding theorem says that ifan independent source has entropy H , then there exists a prefix code in which the averagenumber of bits per symbol is between H and H + 1 . Moreover, there is no uniquely decodable codethat has smaller average length. Thus, if N symbols (each with entropy H ) are compressed into less than N H bits, information is lost, while information need not be lost if N ( H + 1 ) bits are used. Shannon has defined the goal towardswhich all codes aspire, but provides no way of finding good codes for any particular case.

Fortunately, D. A. Huffman proposed an organized procedure to build variable-length codes that are as efficient as possible.Given a set of symbols and their probabilities, the procedure is as follows:

  1. List the symbols in order of decreasing probability. These are the original “nodes.”
  2. Find the two nodes with the smallest probabilities, and combine them into one new node, with probability equalto the sum of the two. Connect the new nodes to the old ones with “branches” (lines).
  3. Continue combining the pairs of nodes with the smallest probabilities. (If there are ties, pick anyof the tied symbols).
  4. Place a 0 or a 1 along each branch. The path from the rightmost node to the original symbol defines a binary list,which is the code word for that symbol.

This procedure is probably easiest to understand by working through an example. Consider again the N = 4 code from Example [link] (a) in which the symbols have probabilities p ( x 1 ) = 0 . 5 , p ( x 2 ) = 0 . 25 , and p ( x 3 ) = p ( x 4 ) = 0 . 125 . Following the foregoing procedure leads to the chart shown in [link] . In the first step, x 3 and x 4 are combined to form a new node with probability equal to 0 . 25 (the sum p ( x 3 ) + p ( x 4 ) ). Then this new node is combined with x 2 to form a new node with probability 0 . 5 . Finally, this is combined with x 1 to form the rightmost node. Each branch is now labelled. The convention used in [link] is to place a 1 on the top and a 0 on the bottom (assigning the binary digits in another order justrelabels the code). The Huffman code for this source can be read from the chart. Reading from the right-hand side, x 1 corresponds to 1, x 2 corresponds 01, x 3 to 001 and x 4 to 000. This is the same code as in [link] .

The Huffman code for the source defined in Example 14-4(a) can be read directly from this chart, which is constructed using the procedure (1) to (4) in the text.
The Huffman code for the source defined in Example  [link] (a) can be read directly from this chart, which is constructed using the procedure (1) to (4) in thetext.

The Huffman procedure with a consistent branch labelling convention always leads to a prefix code because all the symbols end the same (except for the maximal length symbol x 4 ). More importantly, it always leads to a code that has average lengthvery near the optimal.

Consider the source with N = 5 symbols with probabilities p ( x 1 ) = 1 / 16 , p ( x 2 ) = 1 / 8 , p ( x 3 ) = 1 / 4 , p ( x 4 ) = 1 / 16 , and p ( x 5 ) = 1 / 2 .

  1. What is the entropy of this source?
  2. Build the Huffman chart.
  3. Show that the Huffman code is
    x 1 0001 , x 2 001 , x 3 01 , x 4 0000 , and x 5 1 .
  4. What is the efficiency of this code?
  5. If this source were encoded naively, how many bits per symbol are needed? What is the efficiency?

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Software receiver design. OpenStax CNX. Aug 13, 2013 Download for free at http://cnx.org/content/col11510/1.3
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Software receiver design' conversation and receive update notifications?

Ask