Lecture 7: Source Coding and Kraft Inequality
Lecture 7: Source Coding and Kraft Inequality
Lecture 7: Source Coding and Kraft Inequality
Codes
Kraft inequality and consequences
Horse Racing
!"#$"%"&'()%*&+,%
pi
1/2
1/4
1/8
1/16
1/64
1/64
1/64
1/64
Eli
Code 1
000
001
010
011
100
101
110
111
3
H(X) =
Code 2
0
10
110
1110
111100
111101
111110
111111
2
pi log pi = 2bits
Codes
Source code C for a random variable X is
C(x) : X D
D: set of finite-length strings of symbol from D-ary alphabet D
Code length: l(x)
Example: C(red) = 00, C(blue) = 11, X = {red, blue}, D = {0, 1}
x = x C(x) = C(x)
Singular
1
2
3
4
0
0
0
0
Nonsingular
not
uniquely
decodable
0
010
01
10
Uniquely
decoable
Prefix
10
00
11
110
0
10
110
111
All
codes
Nonsingular
codes
Uniquely
decodable
codes
Instantaneous
codes
p(x)l(x)
xX
10
Kraft inequality
By Kraft in 1949
Coded over alphabet size D
m codes with length l1, . . . , lm
The code length of all instantaneous code must satisfy Kraft inequality
m
Dli 1
i=1
11
12
Root
10
110
111
13
Dlmaxli Dlmax
Dli 1
Converse: if l1, . . . , lmax satisfy Kraft inequality, can label first node at
depth l1, remove its descendants...
Can extend to infinite prefix code lmax
Dr. Yao Xie, ECE587, Information Theory, Duke University
14
pili
pi logD
1
pi
1
= D(p||r) + logD 0
c
ri = Dli /
Dlj , c =
Dli 1
j
15
16
17
i=1
m
pi li
Dli 1.
i=1
pili + (
i=1
Dr. Yao Xie, ECE587, Information Theory, Duke University
Dli 1)
i=1
18
Solution:
li = logD pi.
L =
pili
pi logD pi = HD (X).
li = logD pi.
19
Summary
Nonsingular > Uniquely decodable > Instantaneous codes
Kraft inequality for Instantaneous code
Entropy is lower bound on expected code length
20