101
lower bound. Shannon proposed a procedure for performing this encoding that
nearly achieves this bound, as follows.
1.
List the source symbols 5
i
in order
of
decreasing probability
Pi'
2.
Calculate for each 5
i
the number of bits Ii to represent it, using the
inequalities
3.
Calculate
Fi
= L
Pj
j~O.(i-])
and represent
Fi
as a binary fraction.
4.
Then
5
i
is
represented
by
the first ( bits of F
i
.
Thus, for an example, consider eight source symbols,
51
to 58' with probabilities as
listed in the first column of Table
AI.
Then
Ii'
F
i
, and the binary representation
of
5
i
can be read from the second, third, and fourth columns, respectively.
It
can be seen that this encoding produces an immediate code because the
length
is
such that for each new 5
i
the last bit
is
changed.
It
is
also clear that
is
bounded
by
So
H(5)
~L
< 1
+H(5)
In the above example
H(5)
= 2.73, while L = 2.78.
Table A.I
Pi
Ii
Fi
Bit String Representation
SI
1/4
2 0.00000
00
S2
1/4
2 0.01000
01
S3
1/8
3
0.10000
100
S4
1/8
3 0.10100
101
S5
3/32
4 0.11000 1100
S6
1/16
4 0.11011
1101
S7
1/16
4
0.11101 1110
S8
1/32
5 0.11111 11111