Vous êtes sur la page 1sur 12

Arithmetic Coding

Unlike the variable-length codes

described
previously,
arithmetic
coding, generates non-block codes. In
arithmetic
coding,
a
one-to-one
correspondence
between
source
symbols and code words does not
exist. Instead, an entire sequence of
source symbols (or message) is
assigned a single arithmetic code
word.

Arithmetic coding assigns a sequence of bits to a

message, a string of symbols.
Arithmetic coding can treat the whole symbols in
a list or in a message as one unit.
The main idea behind Arithmetic coding is to
assign each symbol an interval. Starting with the
interval [0...1), each interval is divided in several
subinterval, which its sizes are proportional to the
current probability of the corresponding symbols .
The subinterval from the coded symbol is then
taken as the interval for the next symbol. The
output is the interval of the last symbol.

Arithmetic coding

a1a2a3a3a4

Arithmetic coding algorithm is shown in

the following.
ncoding
lowerboundStrings
=0
upperbound = 1
while there are still symbols to encode
currentrange = upperbound - lowerbound
upperbound = lowerbound + (currentrange
upperboundofnewsymbol)
lowerbound = lowerbound + (currentrange
lowerboundofnewsymbol)
end while

Any value between the computed lower and upper probability

bounds now encodes the input string.
Example:
Encode the string "ace" using the probability ranges from Table 1.
Encode 'a'
current range = 1 - 0 = 1
upper bound = 0 + (1 0.3) = 0.3
lower bound = 0 + (1 0.0) = 0.0
lowerbound = 0
upperbound = 1

Encode 'c'
while there are still symbols to encode
currentrange = upperbound - lowerbound
current range = 0.3 - 0.0 = 0.3
upperbound = lowerbound + (currentrange
upper bound = 0.0 + (0.3 0.70) = 0.210upperboundofnewsymbol)
lowerbound = lowerbound + (currentrange
lowerboundofnewsymbol)
lower bound = 0.0 + (0.3 0.45) = 0.135
end while

Encode 'e'
current range = 0.210 - 0.135 = 0.075
upper bound = 0.135 + (0.075 1.00) = 0.210
lower bound = 0.135 + (0.075 0.80) = 0.195
The string "ace" may be encoded by any value within the probability
range [0.195, 0.210).

Decoding Strings

edvalue = encodedinput

move effects of symbol from encoded value

entrange = upperboundofnewsymbol - lowerboundofnewsymbol
edvalue = (encodedvalue - lowerboundofnewsymbol) current rang

hile

Example:
Using the probability ranges from Table 1 decode the three character
string encoded as 0.20.
encodedvalue = encodedinput
Decode first symbol
while string is not fully decoded
0.20 is within [0.00, 0.30)
identify the symbol containing encoded value within its range
0.20 encodes 'a'

//remove effects of symbol from encoded value

currentrange = upperboundofnewsymbol - lowerboundofnewsymbol
encodedvalue = (encodedvalue - lowerboundofnewsymbol) current rang

Remove effects of 'a' from encode value end while

current range = 0.30 - 0.00 = 0.30
encoded value = (0.20 - 0.0) 0.30 = 0.67 (rounded)
Decode second symbol
0.67 is within [0.45, 0.70)
0.67 encodes 'c'
Remove effects of 'c' from encode value
current range = 0.70 - 0.45 = 0.35
encoded value = (0.67 - 0.45) 0.35 = 0.88
Decode third symbol
0.88 is within [0.80, 1.00)
0.88 encodes 'e'
The encoded string is "ace".

Stopping The Decoding Process

One of the methods for knowing when to stop the decoding process
is to include a symbol count somewhere in the encoded file. The
file header is an ideal place to store the symbol count.

2.Encode the message

M = [a, b, a, a, a, e, a, a, b, a]
Given:
Alphabet : {a,b,c,d,e,f}
P=[0.67,0.11,0.07,0.06,0.05,0.04].

Comparison Huffman/Arithmetic
coding
From implementation point of view,
Huffman coding is easier than arithmetic
coding.

Arithmetic algorithm yields much more

compression ratio than Huffman algorithm
while Huffman coding needs less
execution time than the arithmetic
coding.
This means that in some applications that
time is not so important we can use
arithmetic algorithm to achieve high