0% found this document useful (0 votes)
45 views

Arithmetic Coding - Lecture Example

This document describes arithmetic coding and provides an example of encoding and decoding a sequence of symbols. It shows: 1) How to encode the sequence 1,3,2,1 using an alphabet of {1,2,3} by calculating interval ranges based on a cumulative distribution function and shifting bits out to a codeword. 2) How to decode the resulting codeword by tracking interval ranges, shifting bits between the codeword and calculation variables, and mapping interval ranges back to symbols. 3) The encoding and decoding produce the same original sequence, demonstrating arithmetic coding works to compress data.

Uploaded by

perhacker
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Arithmetic Coding - Lecture Example

This document describes arithmetic coding and provides an example of encoding and decoding a sequence of symbols. It shows: 1) How to encode the sequence 1,3,2,1 using an alphabet of {1,2,3} by calculating interval ranges based on a cumulative distribution function and shifting bits out to a codeword. 2) How to decode the resulting codeword by tracking interval ranges, shifting bits between the codeword and calculation variables, and mapping interval ranges back to symbols. 3) The encoding and decoding produce the same original sequence, demonstrating arithmetic coding works to compress data.

Uploaded by

perhacker
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Arithmetic coding, lecture example

Coding
Alphabet A = {1, 2, 3}. Let m = k = 6. Cumulative distribution function

F (0) = 0, F (1) = 38, F (2) = 58, F (3) = 64

Code the sequence 1,3,2,1

l(0) = 0 = (000000)2
u(0) = 63 = (111111)2

(63 − 0 + 1) · 0
l(1) = 0+b c = 0 = (000000)2
64
(63 − 0 + 1) · 38
u(1) = 0+b c − 1 = 37 = (100101)2
64
(37 − 0 + 1) · 58
l(2) = 0+b c = 34 = (100010)2
64
(37 − 0 + 1) · 64
u(2) = 0+b c − 1 = 37 = (100101)2
64
The first bit is the same in l and u. Shift out 1 to the codeword, shift a 0 into
l and a 1 into u. The codeword so far is 1.

l(2) = (000100)2 = 4
(2)
u = (001011)2 = 11

The first bit is the same in l and u. Shift out 0 to the codeword, shift a 0 into
l and a 1 into u. The codeword so far is 10.

l(2) = (001000)2 = 8
(2)
u = (010111)2 = 23

The first bit is the same in l and u. Shift out 0 to the codeword, shift a 0 into
l and a 1 into u. The codeword so far is 100.

l(2) = (010000)2 = 16
u(2) = (101111)2 = 47

Case 3. Shift both l and u, but don’t put any bits in the codeword yet. Shift a
0 into l and a 1 into u, and invert the new most significant bit in both l and u.

1
l(2) = (000000)2 = 0
(2)
u = (111111)2 = 63

(63 − 0 + 1) · 38
l(3) = 0+b c = 38 = (100110)2
64
(63 − 12 + 1) · 58
u(3) = 0+b c − 1 = 57 = (111001)2
64

The first bit is the same in l and u. Shift out 1 plus an extra 0 from the previous
case 3 shift to the codeword, shift a 0 into l and a 1 into u. The codeword so
far is 10010.

l(3) = (001100)2 = 12
u(3) = (110011)2 = 51

(51 − 12 + 1) · 0
l(4) = 12 + b c = 12 = (001100)2
64
(51 − 12 + 1) · 38
u(4) = 12 + b c − 1 = 34 = (100010)2
64
Since there are no more symbols we don’t need to do any more shift operations.
The codeword is the bits that have been shifted out before, plus all of l(4) , ie
10010001100.

Decoding
The decoder has to know the precision (m = k = 6), the number of symbols
coded (n = 4) and the cumulative distribution function:

F (0) = 0, F (1) = 38, F (2) = 58, F (3) = 64

Decode the first codeword in the bitstream starting 100100011001010 . . .


For the given F , the interval 0-37 belongs to symbol 1, the interval 38-57 to
symbol 2 and the interval 58-63 to symbol 3. Start the tag t as the first six bits
from the bitstream.

l(0) = (000000)2 = 0
(0)
u = (111111)2 = 63
t = (100100)2 = 36

(36 − 0 + 1) · 64 − 1
b c = 36 ⇒ the first symbol is 1
63 − 0 + 1

(63 − 0 + 1) · 0
l(1) = 0+b c = 0 = (000000)2
64
(63 − 0 + 1) · 38
u(1) = 0+b c − 1 = 37 = (100101)2
64

2
(36 − 0 + 1) · 64 − 1
b c = 62 ⇒ the second symbol is 3
37 − 0 + 1

(37 − 0 + 1) · 58
l(2) = 0+b c = 34 = (100010)2
64
(37 − 0 + 1) · 64
u(2) = 0+b c − 1 = 37 = (100101)2
64
The first three bits are the same in l and u. Shift them out, shift zeros into l,
ones into u and three new bits from the bitstream into t.

l(2) = (010000)2 = 16
(2)
u = (101111)2 = 47
t = (100011)2 = 35

Case 3. Shift l, u and t. 0 into l, 1 into u and a new bit from the bitstream into
t. Invert the new most signficant bit in each.

l(2) = (000000)2 = 0
u(2) = (111111)2 = 63
t = (100110)2 = 38

(38 − 0 + 1) · 64 − 1
b c = 38 ⇒ the third symbol is 2
63 − 0 + 1

(63 − 0 + 1) · 38
l(3) = 0+b c = 38 = (100110)2
64
(63 − 0 + 1) · 58
u(3) = 0+b c − 1 = 57 = (111001)2
64

The first bit is the same in l and u. Shift them out, shift 0 into l, 1 into u and
a new bit from the bitstream into t.

l(3) = (001100)2 = 12
u(3) = (110011)2 = 51
t = (001100)2 = 12

(12 − 12 + 1) · 64 − 1
b c = 1 ⇒ the fourth symbol is 1
51 − 12 + 1
Since we have now decoded four symbols we don’t have to do any more calcu-
lations. The decoded sequence is 1,3,2,1 which is exactly what we coded. The
rest of the bits in the stream belong the next codeword.

You might also like