Chapter 2 Source Coding
Chapter 2 Source Coding
Source coding
Prof. Abhishek Dixit
Dept. of Electrical Engineering
IIT Delhi
Binary Channel
Channel
Information Source Coder Modulator
Analog/Digital Bit Coder Bit Waveform
Waveform Stream Stream
Channel
Source Channel
Information Demodulator
Analog/Digital Decoder Bit Decoder Bit Waveform
Stream Stream
Waveform
Receiver
Prof. Abhishek Dixit
Source Coder/Decoder
r1 r2 …. rn d1 d2 …. dn 10 11 …. 01
Uniquely
decodable
Uniquely
decodable
Easy to construct
Optimum
All other codes Prefix
Instantaneous
Free
Codes
Uniquely
decodable
Easy to construct
Optimum
All other codes Prefix
Instantaneous
Free
Codes Not practical
1 1
b
1 1
b
1 1
b
1 1
b
1 1
b
1 1
b d
a ca
0 0
0 1 0 1
c
1 cc
1
b cb
2−𝑙(𝑥) ≤ 1
𝑥∈𝑋
2−𝑙(𝑥) ≤ 1
𝑥∈𝑋
• Converse is also true.
• Full prefix-free code satisfies the equation with equality.
• Nonfull prefix-free code satisfies this with strict inequality.
2−𝑙(𝑥) ≤ 1
𝑥∈𝑋
• Converse is also true.
• Full prefix-free code satisfies the equation with equality.
• Nonfull prefix-free code satisfies this with strict inequality.
• This equation is also true for uniquely decodable codes
• If a code satisfies this equation, it does not mean, it is prefix-free or uniquely
decodable.
𝑦1 𝑦2 𝑦𝑚
. 𝑦1 𝑦2 … 𝑦𝑚 = + + ⋯ + 𝑚
2 4 2
1
1
Interval [2 , 1)
1 → .1 1 1
Interval [4 , 2ቁ
01 → .01 1
Interval [0, 4ቁ
00 → .00
𝑦1 𝑦2 𝑦𝑚
. 𝑦1 𝑦2 … 𝑦𝑚 = + + ⋯ + 𝑚
2 4 2
1
1
Interval [2 , 1)
1 → .1 1 1
Interval [4 , 2ቁ
𝑙 𝑙
01 → .01 1
Interval [0, 4ቁ 𝑦𝑚 2−𝑚 , 𝑦𝑚 2−𝑚 + 2−l ቍ
00 → .00 𝑚=1 𝑚=1
1 1
1 1
Interval [2 , 1) Interval [2 , 1)
1 → .1 1 1 1 → .1 1 1
Interval [4 , 2ቁ Interval [4 , 2ቁ
01 → .01 1 01 → .01 3 1
Interval [0, 4ቁ Interval [8 , 2ቁ
00 → .00 011 → .011
A code 𝐶(𝑎𝑗 ) is prefix of 𝐶(𝑎𝑖 ) if and only if the expansion of 𝐶(𝑎𝑖 ) contains the
expansion of 𝐶(𝑎𝑖 ) in its approximate interval.
1 → .1 1 1 1 → .1 1 1
Interval [ 4 , 2ቁ Interval [4 , 2ቁ
01 → .01 1 01 → .01 3 1
Interval [0, 4ቁ Interval [8 , 2ቁ
00 → .00 011 → .011
A code 𝐶(𝑎𝑗 ) is prefix of 𝐶(𝑎𝑖 ) if and only if the expansion of 𝐶(𝑎𝑖 ) contains the
expansion of 𝐶(𝑎𝑖 ) in its approximate interval.
1 → .1 1 1 1 → .1 1 1
Interval [ 4 , 2ቁ Interval [4 , 2ቁ
01 → .01 1 01 → .01 3 1
Interval [0, 4ቁ Interval [8 , 2ቁ
00 → .00 011 → .011
A code 𝐶(𝑎𝑗 ) is prefix of 𝐶(𝑎𝑖 ) if and only if the expansion of 𝐶(𝑎𝑖 ) contains the
expansion of 𝐶(𝑎𝑖 ) in its approximate interval.
DMS IID
𝐿ത = 𝐸 𝐿 = 𝑙 𝑎𝑗 𝑝𝑋 (𝑎𝑗 )
𝑗
𝐿ത = 𝐸 𝐿 = 𝑙 𝑎𝑗 𝑝𝑋 (𝑎𝑗 )
𝑗
• Another notation
𝐿ത = 𝐸 𝐿 = 𝑙𝑗 𝑝𝑗
𝑗
𝐿ത = 𝐸 𝐿 = 𝑙 𝑎𝑗 𝑝𝑋 (𝑎𝑗 )
𝑗
• Another notation
𝐿ത = 𝐸 𝐿 = 𝑙𝑗 𝑝𝑗
𝑗
• Minimizing 𝐿ത
𝑀
𝐿ത 𝑚𝑖𝑛 = min −𝑙 𝑙𝑗 𝑝𝑗
𝑙1 …𝑙𝑚 :σ𝑗 2 𝑗 ≤1
𝑗
𝐿ത 𝑚𝑖𝑛 = min −𝑙 𝑙𝑗 𝑝𝑗
𝑙1 …𝑙𝑚 :σ𝑗 2 𝑗 ≤1
𝑗
• Hard problem as 𝑙1 … 𝑙𝑚 all have to be positive integers.
𝐿ത 𝑚𝑖𝑛 = min −𝑙 𝑙𝑗 𝑝𝑗
𝑙1 …𝑙𝑚 :σ𝑗 2 𝑗 ≤1
𝑗
• Hard problem as 𝑙1 … 𝑙𝑚 all have to be positive integers.
• Minimizing 𝐿ത
𝑀
𝐿ത 𝑚𝑖𝑛 = min −𝑙 𝑙𝑗 𝑝𝑗
𝑙1 …𝑙𝑚 :σ𝑗 2 𝑗 ≤1
𝑗
• Relax 𝑙1 … 𝑙𝑚 to be real numbers.
• Provides a lower bound.
𝐿ത 𝑚𝑖𝑛 = min −𝑙 𝑙𝑗 𝑝𝑗
𝑙1 …𝑙𝑚 :σ𝑗 2 𝑗 =1
𝑗
• Relax 𝑙1 … 𝑙𝑚 to be real numbers.
• Provides a lower bound.
𝐿ത 𝑚𝑖𝑛 = min −𝑙 𝑙𝑗 𝑝𝑗
𝑙1 …𝑙𝑚 :σ𝑗 2 𝑗 =1
𝑗
• Relax 𝑙1 … 𝑙𝑚 to be real numbers.
• Provides a lower bound.
• Langrage multipler:
𝑀
𝑙𝑗 𝑝𝑗 + λ 2−𝑙𝑗
𝑗 𝑗
𝐿ത 𝑚𝑖𝑛 = min −𝑙 𝑙𝑗 𝑝𝑗
𝑙1 …𝑙𝑚 :σ𝑗 2 𝑗 =1
𝑗
• Relax 𝑙1 … 𝑙𝑚 to be real numbers.
• Provides a lower bound.
• Langrage multipler:
𝑙𝑗 𝑝𝑗 + λ2−𝑙𝑗
𝐿ത 𝑚𝑖𝑛 = min −𝑙 𝑙𝑗 𝑝𝑗
𝑙1 …𝑙𝑚 :σ𝑗 2 𝑗 =1
𝑗
• Relax 𝑙1 … 𝑙𝑚 to be real numbers.
• Provides a lower bound.
• Langrage multipler:
𝑙𝑗 𝑝𝑗 + λ2−𝑙𝑗
𝑑
𝑙𝑗 𝑝𝑗 + λ2−𝑙𝑗 = 𝑝𝑗 + λ(− ln 2)2−𝑙𝑗
𝑑𝑙𝑗
𝐿ത 𝑚𝑖𝑛 = min −𝑙 𝑙𝑗 𝑝𝑗
𝑙1 …𝑙𝑚 :σ𝑗 2 𝑗 =1
𝑗
• Relax 𝑙1 … 𝑙𝑚 to be real numbers.
• Provides a lower bound.
• Langrage multipler:
𝑙𝑗 𝑝𝑗 + λ2−𝑙𝑗
𝑑
𝑙𝑗 𝑝𝑗 + λ2−𝑙𝑗 = 𝑝𝑗 + λ(− ln 2)2−𝑙𝑗
𝑑𝑙𝑗
𝑝𝑗 + λ(− ln 2)2−𝑙𝑗 = 0
𝑗
1 − λ ln 2 = 0 or λ = 1/ ln 2
𝐿ത 𝑚𝑖𝑛 = min −𝑙 𝑙𝑗 𝑝𝑗
𝑙1 …𝑙𝑚 :σ𝑗 2 𝑗 =1
𝑗
• Relax 𝑙1 … 𝑙𝑚 to be real numbers.
• Provides a lower bound.
• Langrage multipler:
𝑙𝑗 𝑝𝑗 + λ2−𝑙𝑗
𝑑
𝑙𝑗 𝑝𝑗 + λ2−𝑙𝑗 = 𝑝𝑗 + λ(− ln 2)2−𝑙𝑗
𝑑𝑙𝑗
𝑝𝑗 + λ(− ln 2)2−𝑙𝑗 = 0
𝑗
𝑝𝑗 = 2−𝑙𝑗 or 𝑙𝑗 = − l𝑜𝑔 𝑝𝑗
a a
0 0
0 1 0 c 0 1 0 c
1 1 1 1
b b
a
0
0 1 0 c
1 1
b d
a
0
0 1 0 c
1 1
b d
0
4
1
Prof. Abhishek Dixit 5
Huffman coding
𝒑𝒋 symbol
0.4 1
0.25 {4,5}
0.2 2
0.15 3
0 2
1
3
0
4
1
Prof. Abhishek Dixit 5
Huffman coding
𝒑𝒋 symbol
0.4 1
0.35 {2,3}
0.25 {4,5}
0 2
0
1
3
0
1 4
1
Prof. Abhishek Dixit 5
Huffman coding
𝒑𝒋 symbol
0.6 {{4,5}, {2,3}}
0.4 1
0 2
0
0 1
3
0
1 4
1
1 1
Prof. Abhishek Dixit 5
Huffman coding
𝒑𝒋 symbol Binary representation
0.4 1 1
0.2 2 000
0.15 3 001
0.15 4 010
0.1 5 011
𝐻 𝑋 = 2.15 bpss
𝐿ത = 2.2 bpss
0 2
0
0 1
3
0
1 4
1
1 1
5
Optimal code for the reduced set leads to the optimal code for the original set
Prof. Abhishek Dixit
Optimality of Huffman coding
𝒑𝒋 symbol
0.4 1
0.2 2
0.15 3
0
0.25 0.15 4
0.1 5
1
Properties of entropy
1) 𝐻(𝑋) ≥ 0
Proof: Because − log 𝑝𝑗 are all positives.
Equality is satisfied when 𝑋 is deterministic or 𝑝𝑗 is 1.
Properties of entropy
1) 𝐻 𝑋 ≥ 0
2) 𝐻(𝑋) ≤ log 𝑀
Properties of entropy
1) 𝐻 𝑋 ≥ 0
2) 𝐻(𝑋) ≤ log 𝑀
1
𝐻 𝑋 − log 𝑀 = 𝑝𝑗 log − log 𝑀
𝑝𝑗
1 1
= 𝑝𝑗 log ≤ log 𝑒 𝑝𝑗 −1 =0
𝑀𝑝𝑗 𝑀𝑝𝑗
𝑗
Properties of entropy
1) 𝐻 𝑋 ≥ 0
2) 𝐻 𝑋 ≤ log 𝑀
3) 𝐻 𝑋𝑌 = 𝐻 𝑋 + 𝐻(𝑌) If 𝑋 and 𝑌 are independent random variables
Properties of entropy
1) 𝐻 𝑋 ≥ 0
2) 𝐻 𝑋 ≤ log 𝑀
3) 𝐻 𝑋𝑌 = 𝐻 𝑋 + 𝐻 𝑌
4) 𝐻 𝑋 𝑛 = 𝑛𝐻(𝑋)
− log 𝑝𝑋 𝑛 (𝑥 𝑛 ) σ2𝑊
Pr −𝐻 𝑋 >ε ≤ 2
𝑛 𝑛ε
σ2𝑊
Pr 𝑋 𝑛 𝜖𝑇ε𝑛 ≥1− 2 As 𝑛 → ∞, typical set approaches probability 1
𝑛ε
Prof. Abhishek Dixit
Typical set
− log 𝑝𝑋𝑛 𝑥 𝑛
• 𝑇ε𝑛 = 𝑥 𝑛 : −𝐻 𝑋 <ε
𝑛
• 𝑇ε𝑛 = 𝑥 𝑛 : 𝑛 𝐻 𝑋 − ε < − log 𝑝𝑋 𝑛 𝑥 𝑛 < 𝑛 𝐻 𝑋 + ε
− log 𝑝𝑋𝑛 𝑥 𝑛
• 𝑇ε𝑛 = 𝑥 𝑛 : 2𝑛 𝐻 𝑋 −ε <2 < 2𝑛 𝐻 𝑋 +ε
log 𝑝𝑋𝑛 𝑥 𝑛
• 𝑇ε𝑛 = 𝑥 𝑛 : 2−𝑛 𝐻 𝑋 −ε >2 > 2−𝑛 𝐻 𝑋 +ε
𝑥 𝑛 ∈𝑇ε𝑛
𝑇ε𝑛 < 2𝑛 𝐻 𝑋 +ε
• Lower bound
𝑥 𝑛 ∈𝑇ε𝑛
𝑇ε𝑛 > 1 − δ 2𝑛 𝐻 𝑋 −ε
• 𝑇ε 𝑛 : 𝑥 𝑛 : 𝑝𝑋 𝑛 (𝑥 𝑛 ) ≈ 𝑝𝑛𝑝 1 − 𝑝 𝑛 1−𝑝
• Typical set is one where out of 𝑛 bits, 𝑛𝑝 bits are 1 and 𝑛(1 − 𝑝) bits are zeros.
00 01
10 11
{o,n} {o,n}
10 11
{o,n} {o,n}
10 11
{o,n} {o,n}
10 11
{o,n} {o,n}
10 11 1
1
0 1
0
{o,n} {o,n}
10 11 1
0
1
0 1
0
{o,n} {o,n}
10 11 1
0
1
0 1
0
{o,n} {o,n}
10 11 1
0
1; 0.5
0; 0.5 1; 0.5
0; 0.5
{o,n} {o,n}
10 11 1; 0.9
0; 0.1
• Interpretation
• Interpretation
• Probability of transition depends only upon the previous state.
• The transition probabilities do not change with time.
1
0 1
0
10 11 1
0
1
0 1
0
10 11 1
0
1
0 1
0
10 11 1
0
Number of transitions = 1
1
0 1
0
10 11 1
0
Number of transitions = 1
Number of transitions = 3
1
0 1
0
10 11 1
0
Number of transitions = 1
Number of transitions = 3
Number of transitions = 4
1
0 1
0
10 11 1
0
Number of transitions = 1
Number of transitions = 4
1
0 1
0
10 11 1
0
Number of transitions = 1
1
0 1
0
10 11 1
0
Ergodic Markov chain is the one where all states are aperiodic and are accessible
from one another.
1
0 1
0
10 11 1
0
1
0 1
0
10 11 1
0
lim 𝑃𝑟 𝑆𝑘 = 𝑠 𝑆0 = 𝑠 ′ = 𝑞(𝑠)
𝑘→∞
• Let us define
• 𝐿ത 𝑚𝑖𝑛 ≝ σ𝑠 𝑞(𝑠) 𝐿ത 𝑚𝑖𝑛 𝑠
• 𝐻 𝑋|𝑆 ≝ σ𝑠 𝑞(𝑠) 𝐻 𝑋|𝑠
• Let us define
• 𝐿ത 𝑚𝑖𝑛 ≝ σ𝑠 𝑞(𝑠) 𝐿ത 𝑚𝑖𝑛 𝑠
• 𝐻 𝑋|𝑆 ≝ σ𝑠 𝑞(𝑠) 𝐻 𝑋|𝑠
𝑤 = 𝑤𝑖𝑛𝑑𝑜𝑤 P 𝑛=4
match
𝑎𝑐 𝑑 𝑏 𝑐 𝑑 𝑎𝑐 𝑏 𝑎𝑏𝑎𝑐 𝑑 𝑎𝑏𝑎𝑏 𝑎𝑏𝑑 𝑐 𝑎…
𝑢=2
1 𝒖𝒏𝒄𝒐𝒎𝒑𝒓𝒆𝒔𝒔𝒆𝒅 ( 𝒍𝒐𝒈 𝑴 )
𝑝𝑋 𝑥 𝑝𝑌 𝑦
𝐻 𝑋𝑌 − 𝐻 𝑋 − 𝐻 𝑌 ≤ 𝑝𝑋,𝑌 𝑥, 𝑦 − 1 log 𝑒 = 0
𝑝𝑋,𝑌 𝑥, 𝑦
𝑥,𝑦
𝐻 𝑋𝑌 ≤ 𝐻 𝑋 + 𝐻 𝑌