+ All Categories
Home > Documents > Adaptive Huffman Code

Adaptive Huffman Code

Date post: 15-Jan-2016
Category:
Upload: mukesh-israni
View: 75 times
Download: 2 times
Share this document with a friend
Description:
Adaptive Huffman Code Explained
Popular Tags:
46
ADAPTIVE HUFFMAN CODE The contents on this presentation have been Compiled for academic use by Mukesh T Israni Contents of these slides developed from: Khalid Sayood – Introduction to Data Compression (Third Edition) Slides are private property of MI, Do not reproduce the contents without permission
Transcript
Page 1: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODE

The contents on this presentation have been

Compiled for academic use by Mukesh T

Israni

Contents of these slides developed from:

Khalid Sayood – Introduction to Data

Compression (Third Edition)

Slides are private property of MI, Do not reproduce the contents without permission

Page 2: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODE

• Huffman coding requires knowledge of the probabilities of the source sequence.

• If this knowledge is not available, Huffman coding becomes a two-pass procedure.

• The statistics are collected in the first pass, and the source is encoded in the second pass.

Slides are private property of MI, Do not reproduce the contents without permission

Page 3: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODE

• In order to convert this algorithm into a one-pass procedure, Faller and Gallagher independently developed adaptive algorithms to construct the Huffman code based on the statistics of the symbols already encountered. These were later improved by Knuth and Vitter.

Slides are private property of MI, Do not reproduce the contents without permission

Page 4: Adaptive Huffman Code

Coding Techniques

• If a1,a2,………am are alphabets of size m then choose e and r such that m=2e + r where 0 ≤ r ≤ 2ealso the Node will start at 2m-1

• If 1 ≤ k ≤ 2r then the symbol ak is encoded as (e + 1) bit of k-1 else ak is encoded as e bit binary representation of k-r -1 (where k is current alphabet)

Slides are private property of MI, Do not reproduce the contents without permission

Page 5: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODE

• Example:

For English Alphabets A to Z

m = 26

Then e = 4 and r =10

So alphabets A to T will be represented as 5

bit of k-1 and U to Z will be represented as 4

bit of k-r-1Slides are private property of MI, Do not reproduce the contents without permission

Page 6: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEENCODING FLOWCHART

Slides are private property of MI, Do not reproduce the contents without permission

Page 7: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDECODING FLOWCHART

Slides are private property of MI, Do not reproduce the contents without permission

Page 8: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

• Example:

Encode and Decode the symbols: aardvark

Step 1:

Start at the NYT (no. of node will be 51)

51

Slides are private property of MI, Do not reproduce the contents without permission

0 - NYT

Page 9: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

Step 2: First letter is A(1) which is a new symbol and is between 1 and 2r so its code will be e+1 (5) bit of k-1(0) so it will be 00000 which is transmitted

Transmission: 00000

Step 3:The Tree structure is updated by splitting the NYT as shown below:

Slides are private property of MI, Do not reproduce the contents without permission

Page 10: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

51

0 1

49 50

Step 3: Next Symbol is AIt is not a new symbol and its code from the

tree will be (1) and 1 is transmitted and tree is

updatedSlides are private property of MI, Do not reproduce the contents without permission

0 - NYT

1

A- 1

Page 11: Adaptive Huffman Code

Coding Techniques

51

0 1

49 50

Transmission: 000001

Slides are private property of MI, Do not reproduce the contents without permission

0 - NYT

2

A- 2

Page 12: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

Step 4: Next symbol is R, it’s a new symbol

so first code for NYT is transmitted (0) and

Since R(18) is between 1 and 2r its code will

be (18 – 1= 17) in binary 10001 and tree

will be updated

Transmission: 000001010001

Slides are private property of MI, Do not reproduce the contents without permission

Page 13: Adaptive Huffman Code

Coding Techniques

51

0 1

49 50

0 1

47 48Slides are private property of MI, Do not reproduce the contents without permission

0 - NYT

3

A- 2

1 - R

1

Page 14: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

Step 5: Next symbol is D, it’s a new symbol

so first code for NYT is transmitted (00) and

Since D(4) is between 1 and 2r its code will

be (4 – 1= 3) in binary 00011 and tree will be

updated

Transmission: 0000010100010000011

Slides are private property of MI, Do not reproduce the contents without permission

Page 15: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

Slides are private property of MI, Do not reproduce the contents without permission

4

2

1 1 - R

1 - D

2 - A

0 - NYT

Page 16: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

Step 6: Next symbol is V, it’s a new symbol

so first code for NYT is transmitted (000) and

Since V(22) is greater than2r its code will

be in 4 bits and represented as (22-10-1= 11)

in binary 1011 and tree will be updated

Transmission: 00000101000100000110001011

Slides are private property of MI, Do not reproduce the contents without permission

Page 17: Adaptive Huffman Code

Coding Techniques

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

Slides are private property of MI, Do not reproduce the contents without permission

5

3

2 1 - R

1 - D

2 - A

0 - NYT

1

1- V

Page 18: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

• It should be noted that weight of node 49 is greater than weight of node 50 and weight of node 47 is greater than node 48

• So nodes 49 and 50 will be swapped and nodes 47 and 48 will be swapped and the tree is redrawn

Slides are private property of MI, Do not reproduce the contents without permission

Page 19: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

Slides are private property of MI, Do not reproduce the contents without permission

5

3

1

2

1 - V

1 - R

1 - D

2 - A

0- NYT

Page 20: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

Step 7: Next symbol is A, and is not a new

symbol code for A will be (0) and tree

will be updated

Transmission: 000001010001000001100010110

Slides are private property of MI, Do not reproduce the contents without permission

Page 21: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

Slides are private property of MI, Do not reproduce the contents without permission

6

3

1

2

1 - V

1 - R

1 - D

3 - A

0- NYT

Page 22: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

Step 8: Next symbol is R, and is not a new

symbol code for R will be (10) and tree will

be updated

Transmission: 00000101000100000110001011010

Slides are private property of MI, Do not reproduce the contents without permission

Page 23: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

Slides are private property of MI, Do not reproduce the contents without permission

6

4

1

2

1 - V

2- R

1 - D

3 - A

0- NYT

Page 24: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

Step 9: Next symbol is K(11), it’s a new

symbol so first NYT(1100) is transmitted and

code for will be (01010) and tree will be

updated

Transmission: 00000101000100000110001011010110001010

Slides are private property of MI, Do not reproduce the contents without permission

Page 25: Adaptive Huffman Code

Coding Techniques

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

0 1

41 42

Slides are private property of MI, Do not reproduce the contents without permission

8

5

2

3

1 1 - V

2 - R

1 - D

3 - A

1 - K0- NYT

Page 26: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

0 1

41 42

Slides are private property of MI, Do not reproduce the contents without permission

8

5

2

3

1 1 - V

2 - R

1 - D

3 - A

1 - K0- NYT

Page 27: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODECoding Technique

This completes the encoding procedure and

the final transmitted sequence is listed below

we will now use this and decode

Transmission:

00000101000100000110001011010110001010

Slides are private property of MI, Do not reproduce the contents without permission

Page 28: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

Received bits: 00000101000100000110001011010110001010

Step 1:

Start at the NYT (no. of node will be 51)

51

Slides are private property of MI, Do not reproduce the contents without permission

0 - NYT

Page 29: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

Step 2:Read 4 bits (0000), decimal value is 0

which is less than 10(r) so read 5 bits 00000,

add 1 to it 00000+1 = 00001 = 1=A, so first

symbol is A and update tree

Slides are private property of MI, Do not reproduce the contents without permission

Page 30: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

51

0 1

49 50

Step 3: Read next bit(1) which traces to A so

next symbol is A and update tree

Slides are private property of MI, Do not reproduce the contents without permission

0 - NYT

1

A- 1

Page 31: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

51

0 1

49 50Step 4: Read next bit(0) traces path to NYT so next

symbol is new. Now read 4 bits (1000) which is less

than (10)r so read 5 bits (10001) and add 1 to get 18

which is R which is the next symbol & update tree. Slides are private property of MI, Do not reproduce the contents without permission

0 - NYT

2

A- 2

Page 32: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

51

0 1

49 50

0 1

47 48Slides are private property of MI, Do not reproduce the contents without permission

0 - NYT

3

A- 2

1 - R

1

Page 33: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

Step 5: Read next 2 bits (00) traces path to

NYT so next symbol is new. Now read 4 bits

(0001) which is less than (10)r so read 5 bits

(00011) and add 1 to get 4 which is D which

is the next symbol & update tree.

Slides are private property of MI, Do not reproduce the contents without permission

Page 34: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

Slides are private property of MI, Do not reproduce the contents without permission

4

2

1 1 - R

1 - D

2 - A

0 - NYT

Page 35: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

Step 6: Read next 3 bits (000) traces path to

NYT so next symbol is new. Now read 4 bits

(1011) which is greater than (10)r so

(11+ 10+ 1 =22) which is V which

is the next symbol & update tree.

Slides are private property of MI, Do not reproduce the contents without permission

Page 36: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

Slides are private property of MI, Do not reproduce the contents without permission

5

3

2 1 - R

1 - D

2 - A

0 - NYT

1

1- V

Page 37: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

Slides are private property of MI, Do not reproduce the contents without permission

5

3

1

2

1 - V

1 - R

1 - D

2 - A

0- NYT

Page 38: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

Step 7: Read next bit (0) traces path to

A so next symbol is A & update tree.

Slides are private property of MI, Do not reproduce the contents without permission

Page 39: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

Slides are private property of MI, Do not reproduce the contents without permission

6

3

1

2

1 - V

1 - R

1 - D

3 - A

0- NYT

Page 40: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

Step 8: Read next bit (10) traces path to

R so next symbol is R & update tree.

Slides are private property of MI, Do not reproduce the contents without permission

Page 41: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

Slides are private property of MI, Do not reproduce the contents without permission

6

3

1

2

1 - V

2- R

1 - D

3 - A

0- NYT

Page 42: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

Step 9: Read next 4 bits (1100) traces path to

NYT so next symbol is new. Now read 4 bits

(0101) which is less than (10)r so read 5 bits

(01010) And add 1 to get 11 which is K so

next symbol is K & update tree.

Slides are private property of MI, Do not reproduce the contents without permission

Page 43: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

0 1

41 42

Slides are private property of MI, Do not reproduce the contents without permission

8

5

2

3

1 1 - V

2 - R

1 - D

3 - A

1 - K0- NYT

Page 44: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

51

0 1

49 50

0 1

47 48

0 1

45 46

0 1

43 44

0 1

41 42

Slides are private property of MI, Do not reproduce the contents without permission

8

5

2

3

1 1 - V

2 - R

1 - D

3 - A

1 - K0- NYT

Page 45: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODEDecoding Technique

This was the last bit so the decoding is: AARDVARK

Slides are private property of MI, Do not reproduce the contents without permission

Page 46: Adaptive Huffman Code

ADAPTIVE HUFFMAN CODE

Slides are private property of MI, Do not reproduce the contents without permission


Recommended