Arithmetic Coding
Arithmetic Coding
Arithmetic Coding
Generating code words for groups or sequences of
symbols
A unique identifier or tag is generated for the
sequence to be encoded
This tag is a fraction and it is binary encoded
The set of tags for representing symbols are the
numbers in the unit interval [0,1)
Number of numbers in the unit interval is infinite.
Unique tag can be generated for each sequence.
Arithmetic Coding
Cumulative distribution function of the random
variables associated with the source is used for
mapping the sequence to a tag.
Generating the tag:
Example:
Consider a three-letter alphabet A = {a1, a2, a3} with
P(a1) = 0.7,P(a2) = 0.1, and P(a3) = 0.2.
Fx(1) = 0.7, Fx (2) = 0.8, and Fx(3) = 1.
This partitions the unit interval as shown in Figure.
Arithmetic Coding
0.0 0.0 0.49 0.546
a1 a1 a1 a1
Subtract the value of l(2) from both the limits and the tag.
Find the value of x3 for which the interval [0.144 x Fx (x3 -1),
0.144 x Fx (x3)) contains 0.772352 - 0.656 (Residual tag)
Divide the residual tag value by 0.144 to get 0.808.
Find the value of x3 for which 0.808 falls in the interval [Fx(x3-
1), Fx(x3) ). It is possible if x3 =2.
Then update the intervals.
Decoding
Let the fourth element is x4.
Subtract the value of l(3) from both the limits and the tag. (0.772352 - 0.7712
=0.001152)
Find the value of x4 for which the interval [0. 00288 x Fx (x4 -1), 0.00288 x
Fx (x4)) contains 0.001152 (Residual tag)
Divide the residual tag value by 0. 00288 to get 0.4.
Find the value of x4 for which 0.4 falls in the interval [Fx(x4-1), Fx(x4) ). It is
possible if x4 =1.
Data is decoded as 1321 i.e., a1 a3 a2 a1
Generating a binary code
To make the code efficient, the binary representation has
to be truncated. Tag is a number in the interval [0,1).
A binary code for the tag can be obtained by taking the
binary representation of this number and truncating it to
l(x) bits.
l ( x) log(1 / p ( x)) 1
Generating a binary code
Example A ={a1, a2, a3,a4}
P(a1) = 1/2, P(a2) =1/4, P(a3) =1/8 , P(a4)=1/8
1 2
H(X) l A H(X)
m m