Top Banner
Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr. Yao Xie, ECE587, Information Theory, Duke University
21

Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Apr 06, 2018

Download

Documents

vannhan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Lecture 7: Source Coding and Kraft Inequality

• Codes

• Kraft inequality and consequences

Dr. Yao Xie, ECE587, Information Theory, Duke University

Page 2: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Horse Racing

!"#$"%"&'()%*&+,%

Dr. Yao Xie, ECE587, Information Theory, Duke University 1

Page 3: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

pi Code 1 Code 21/2 000 01/4 001 101/8 010 1101/16 011 11101/64 100 1111001/64 101 1111011/64 110 1111101/64 111 111111Eli 3 2

H(X) = −∑

pi log pi = 2bits

How to find the best code?

Dr. Yao Xie, ECE587, Information Theory, Duke University 2

Page 4: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

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}

Dr. Yao Xie, ECE587, Information Theory, Duke University 3

Page 5: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Morse’s code (1836)

• A code for English alphabet of four symbols

• Developed for electric telegraph system

• D = {dot, dash, letter space, word space}

• Short sequences represent frequent letters

• Long sequences represent infrequent letter

Dr. Yao Xie, ECE587, Information Theory, Duke University 4

Page 6: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Dr. Yao Xie, ECE587, Information Theory, Duke University 5

Page 7: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Source coding applications

• Magnetic recording: cassette, hardrive, USB...

• Speech compression

• Compact disk (CD)

• Image compression: JPEG

Still an active area of research:

• Solid state hard drive

• Sensor network: distributed source coding

Dr. Yao Xie, ECE587, Information Theory, Duke University 6

Page 8: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

What defines a good code

• Non-singular:x ̸= x′ ⇒ C(x) ̸= C(x′)

• non-singular enough to describe a single RV X

• When we send sequences of value of X, without “comma” can we stilluniquely decode

• Uniquely decodable if extension of the code is nonsingular

C(x1)C(x2) · · ·C(xn)

Dr. Yao Xie, ECE587, Information Theory, Duke University 7

Page 9: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

X Singular Nonsingularnotuniquelydecodable

Uniquelydecoable

Prefix

1 0 0 10 02 0 010 00 103 0 01 11 1104 0 10 110 111

• Uniquely decodable if only one possible source string producing it

• However, we have to look at entire string to determine

• Prefix code (instantaneous code): no codeword is a prefix of any othercode

Dr. Yao Xie, ECE587, Information Theory, Duke University 8

Page 10: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Allcodes

Nonsingularcodes

Uniquelydecodable

codes

Instantaneouscodes

FIGURE 5.1. Classes of codes.

Dr. Yao Xie, ECE587, Information Theory, Duke University 9

Page 11: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Expected code length

• Expected length L(C) of a source code C(x) for X with pdf p(x)

L(C) =∑x∈X

p(x)l(x)

• We wish to construct instantaneous codes of minimum expected length

Dr. Yao Xie, ECE587, Information Theory, Duke University 10

Page 12: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

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∑i=1

D−li ≤ 1

• Given l1, . . . , lm satisfy Kraft, can construct instantaneous code

• Can be extended to uniquely decodable code (McMillan inequality)

Dr. Yao Xie, ECE587, Information Theory, Duke University 11

Page 13: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Proof of Kraft inequality

• Consider D-ary tree

• Each codeword is represented by a leaf node

• Path from the root traces out the symbol

• Prefix code: no codeword is an ancestor of any other codeword on thetree

• Each code eliminates its descendants as codewords

Dr. Yao Xie, ECE587, Information Theory, Duke University 12

Page 14: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Root

0

10

110

111

Dr. Yao Xie, ECE587, Information Theory, Duke University 13

Page 15: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

• lmax be the length of longest codeword

• A codeword at level li has Dlmax−li descendants

• Descendant sets must be disjoint:∑Dlmax−li ≤ Dlmax

⇒∑

D−li ≤ 1

• Converse: if l1, . . . , lmax satisfy Kraft inequality, can label first node atdepth l1, remove its descendants...

• Can extend to infinite prefix code lmax → ∞

Dr. Yao Xie, ECE587, Information Theory, Duke University 14

Page 16: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Optimal expected code length

• One application of Kraft inequality

• Expected code length of D-ary is lower bounded by entropy:

L ≥ HD(X)

Proof:

L−HD(X) =∑

pili −∑

pi logD1

pi

= D(p||r) + logD1

c≥ 0

ri = D−li/∑j

D−lj, c =∑

D−li ≤ 1

Dr. Yao Xie, ECE587, Information Theory, Duke University 15

Page 17: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

• Achieve minimum code length if

– c = 1: Kraft inequality is equality– ri = pi: approximated pdf using D-ary alphabet is exact

• How to construct such an optimal code?

• Finding the D-adic distribution that is closet to distribution of X

• Construct the code by converse of Kraft inequality

Dr. Yao Xie, ECE587, Information Theory, Duke University 16

Page 18: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Construction of optimal codes

• Finding the D-adic distribution that is closet to distribution of X isimpractical because finding the closest D-adic distribution is not obvious

• Good suboptimal procedure

– Shannon-Fano coding– Arithmetic coding

• Optimal procedure: Huffman coding

Dr. Yao Xie, ECE587, Information Theory, Duke University 17

Page 19: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

First step: finding optimal code length

• Solving optimization problem

minimizeli

m∑i=1

pili

subject tom∑i=1

D−li ≤ 1.

• Solve using Lagrangian multiplier

J =

m∑i=1

pili + λ(

m∑i=1

D−li − 1)

Dr. Yao Xie, ECE587, Information Theory, Duke University 18

Page 20: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

• Solution:l∗i = − logD pi.

• Achieves the lower bound:

L∗ =∑

pil∗i = −

∑pi logD pi = HD(X).

• Problem: − logD pi may not be an integer!

• Rounding upli = ⌈− logD pi⌉.

may not be optimal.

• Usable code constructions?

Dr. Yao Xie, ECE587, Information Theory, Duke University 19

Page 21: Lecture 7: Source Coding and Kraft Inequality - Atlanta, GAyxie77/ece587/Lecture7.pdf · Lecture 7: Source Coding and Kraft Inequality Codes Kraft inequality and consequences Dr.

Summary

• Nonsingular > Uniquely decodable > Instantaneous codes

• Kraft inequality for Instantaneous code

• Entropy is lower bound on expected code length

Dr. Yao Xie, ECE587, Information Theory, Duke University 20