Source Coding
Source Coding
2
DIGITAL COMMUNICATION
Baseband signal
Signal Source Source Channel Modulator
& Transducer Encoder Encoder
4
CLASSIFICATION OF INFORMATION SOURCES
5
CODE LENGTH DEFINITION
6
OTHER DEFINITIONS
8
CLASSIFICATION OF CODES
9
CLASSIFICATION OF CODES
10
CLASSIFICATION OF CODES
11
CLASSIFICATION OF CODES
4. Prefix-free Codes
Codes in which no codeword can be formed
by adding code symbols to another codeword
12
CLASSIFICATION OF CODES
13
CLASSIFICATION OF CODES
6. Instantaneous Codes
1. A code which has the end of any codeword is
recognizable without examining subsequent code
symbols.
2. Instantaneous Codes have the property that no
codeword is a prefix of another codeword.
14
CLASSIFICATION OF CODES
7. Optimal Codes:
A code is said to be optimal if it is
instantaneous and has a minimum average
Length, 𝐿𝑚𝑖𝑛
15
WORKED EXAMPLE - 1
16
SOLUTION
Entropy is:
Code efficiency is
17
EXAMPLE 2
20
SHANNON-FANO CODING
21
SHANNON-FANO CODING
x2 0.30 0
Assign 0
x4 0.25 0
x5 0.20 1
x6 0.12 1
x3 0.08 1
Assign 1
x1 0.05 1
23
SHANNON-FANO CODING
5. Partition the remaining into 2 sets above and below the middle points
x(i) P(x(i)) Step 1 Step 2 Step 3
x2 0.30 0 0
x4 0.25 0 1
x5 0.20 1 0
x6 0.12 1 1 0
x3 0.08 1 1 1
x1 0.05 1 1 1 Remaining
5. Partition the remaining into 2 sets above and below the middle points
x(i) P(x(i)) Step 1 Step 2 Step 3 Step 4 Code
x2 0.30 0 0 00
x4 0.25 0 1 01
x5 0.20 1 0 10
x6 0.12 1 1 0 110
x3 0.08 1 1 1 0 1110
24
x1 0.05 1 1 1 1 1111
SHANNON-FANO CODING EXAMPLE 1
25
SHANNON-FANO CODE-EXAMPLE 1 - SOLUTION
1. Shannon-Fano Code
x(i) P(x(i)) Step 1 Step 2 Step 3 Code
x1 0.500 0 0
x2 0.250 1 0 10
x3 0.125 1 1 0 110
x4 0.125 1 1 1 111
𝐼 𝑥1 = 𝑙𝑜𝑔2 2 = 1 = n1
𝐼 𝑥2 = 𝑙𝑜𝑔2 4 = 2 = n2
𝐼 𝑥3 = 𝑙𝑜𝑔2 8 = 3 = n3
𝐼 𝑥4 = 𝑙𝑜𝑔2 8 = 3 = n4
4
1 1 1 1
𝐻 𝑋 = 𝑃 𝑥𝑖 𝐼 𝑥𝑖 = 1 + 2 + 3 + 3 = 1.75
2 4 8 8
𝑖=1
4
1 1 1 1
𝐿 = 𝑃 𝑥𝑖 𝑛𝑖 = 1 + 2 + 3 + 3 = 1.75
2 4 8 8
𝑖=1
1. Efficiency
𝐻(𝑋)
𝑛= = 1 𝑜𝑟 100% 26
𝐿
HUFFMAN CODE
27
HUFFMAN CODE
28
STEPS IN HUFFMAN CODING
30
USING THE HUFFMAN CODE IN PRACTICE
• Assume that you a character file that you would like to compress. By parsing
through the list, a computer stablishes that there are 100,000 characters with a
frequency of occurrence as shown below.
Character Frequency
A 45,000
B 13,000
C 12,000
D 16,000
E 9,000
F 5,000
Total 100,000
• Determine a code that encodes the file using as few bits as possible.
G 0.1 D 0.05
33
FIRST, CREATE THE TREE
G 0.1 D 0.05
34
USE ONLINE CALCULATOR TO CROSS-CHECK
35