SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
Module 4
                      Arithmetic Coding
                             Prof. Hung-Ta Pai




Module 4, Data Compression       LISA, NTPU      1
Reals in Binary
          Any real number x in the interval [0, 1) can be
          represented in binary as .b1b2... where bi is a bit




Module 4, Data Compression       LISA, NTPU                 2
First Conversion
                 L:=0; R:=1; i :=1;
                 while x > L *
                     if x < (L+R)/2 then bi := 0; R := (L+R)/2;
                     if x ≥ (L+R)/2 then bi := 1; L := (L+R)/2;
                     i := i + 1;
                 end{while}
                 bi := 0 for all j ≥ i;


                  * Invariant: x is always in the interval [L, R)

Module 4, Data Compression          LISA, NTPU                      3
Basic Ideas
          Represent each string x of length n by a unique
          interval [L, R) in [0, 1)
          The width of the interval [L, R) represents the
          probability of x occurring
          The interval [L, R) can itself be represented by
          any number, called a tag, within the half open
          interval
          The k significant bits of the tag .t1t2t3.... is the
          code of x
               That is, .t1t2t3...tk000... is in the interval [L, R)

Module 4, Data Compression            LISA, NTPU                       4
Example
                             1. Tag must be in the half open interval
                             2. Tag can be chosen to be (L+R)/2
                             3. Code is the significant bits of the tag




Module 4, Data Compression         LISA, NTPU                        5
Better Tag




Module 4, Data Compression     LISA, NTPU   6
Example of Codes
          P(a) = 1/3, P(b) = 2/3




Module 4, Data Compression        LISA, NTPU    7
Code Generation from Tag
        If binary tag is .t1t2t3... = (L+R)/2 in [L, R), then
        we want to choose k to form the code t1t2 ...tk
        Short code: choose k to be as small as possible
        so that L ≤ . t1t2 ...tk000... < R
        Guaranteed code:
           Choose k = ⎡log2(1/(R-L))⎤ + 1
           L ≤ . t1t2 ...tkb1b2b3... < R for any bits b1b2b3...
           For fixed length strings provides a good prefix code
           Example: [.000000000..., .000010010...), tag
           = .000001001...
                   Short code: 0
                   Guaranteed code: 000001
Module 4, Data Compression           LISA, NTPU                   8
Guaranteed Code Example
          P(a) = 1/3, P(b) = 2/3




                             Guaranteed code -> Prefix code
Module 4, Data Compression   LISA, NTPU                       9
Coding Algorithm
          P(a1), P(a2), ..., P(am)
          C(ai) = P(a1) + P(a2) + ... +P(ai-1)
          Encode x1x2...xn
                    Initialize L := 0; and R:=1;
                    For i = 1 to n do
                        W := R - L;
                        L := L + W * C(xi);
                        R := L + W * P(xi);
                    end;
                    t := (L+R)/2; choose code for the tag
Module 4, Data Compression          LISA, NTPU              10
Coding Example
          P(a) = 1/4, P(b) = 1/2, P(c) = 1/4
          C(a) = 0, C(b) =1/4, C(c) = 3/4
          abca




Module 4, Data Compression       LISA, NTPU    11
Coding Excercise
          P(a) = 1/4, P(b) = 1/2, P(c) = 1/4
          C(a) = 0, C(b) =1/4, C(c) = 3/4
          bbbb




Module 4, Data Compression        LISA, NTPU    12
Decoding (1/3)
          Assume the length is known to be 3
          0001 which converts to the tag .0001000




Module 4, Data Compression       LISA, NTPU         13
Decoding (2/3)
          Assume the length is known to be 3
          0001 which converts to the tag .0001000




Module 4, Data Compression       LISA, NTPU         14
Decoding (3/3)
          Assume the length is known to be 3
          0001 which converts to the tag .0001000




Module 4, Data Compression       LISA, NTPU         15
Decoding Algorithm
          P(a1), P(a2), ..., P(am)
          C(ai) = P(a1) + P(a2) + ... +P(ai-1)
          Decode b1b2...bm, number of symbols is n
     Initialize L := 0; and R:=1;
     t := b1b2...bm000...
     for i = 1 to n do
         W := R - L;
         find j such that L + W * C(aj) ≤ t < L + W * (C(aj)+P(aj));
         output aj;
         L := L + W * C(aj); R = L + W * P(aj);
Module 4, Data Compression         LISA, NTPU                      16
Decoding Example
          P(a) = 1/4, P(b) = 1/2, P(c) = 1/4
          C(a) = 0, C(b) =1/4, C(c) = 3/4
          00101




Module 4, Data Compression        LISA, NTPU    17
Decoding Issues
          There are two ways for the decoder to know
          when to stop decoding
               Transmit the length of the string
               Transmit a unique end of string symbol




Module 4, Data Compression       LISA, NTPU             18
Practical Arithmetic Coding
          Scaling:
               By scaling we can keep L and R in a reasonable
               range of values so that W = R–L does not underflow
               The code can be produced progressively, not at the
               end
               Complicates decoding some
          Integer arithmetic coding avoids floating point
          altogether



Module 4, Data Compression       LISA, NTPU                    19
Adaptation
          Simple solution – Equally Probable Model
               Initially all symbols have frequency 1
               After symbol x is coded, increment its frequency by 1
               Use the new model for coding the next symbol
               Example in alphabet a, b, c, d




Module 4, Data Compression        LISA, NTPU                      20
Zero Frequency Problem
          How do we weight symbols that have not
          occurred yet?
               Equal weight? Not so good with many symbols
               Escape symbol, but what should its weight be?
               When a new symbol is encountered send the <esc>,
               followed by the symbol in the equally probable model
               (both encoded arithmetically)




Module 4, Data Compression        LISA, NTPU                     21
End of File Problem
          Similar to Zero Frequency Problem
          Reasonable solution:
               Add EOF to the post-ESC equally-probable model
          When done compressing:
               First send ESC
               Then send EOF
          What’s the cost of this approach?




Module 4, Data Compression         LISA, NTPU                   22
Arithmetic vs. Huffman
          Both compress very well
          For m symbol grouping
               Huffman is within 1/m of entropy
               Arithmetic is within 2/m of entropy
          Context
               Huffman needs a tree for every context
               Arithmetic needs a small table of frequencies for
               every context
          Adaptation
               Huffman has an elaborate adaptive algorithm
               Arithmetic has a simple adaptive mechanism

Module 4, Data Compression         LISA, NTPU                      23

Weitere ähnliche Inhalte

Was ist angesagt?

Data compression huffman coding algoritham
Data compression huffman coding algorithamData compression huffman coding algoritham
Data compression huffman coding algoritham
Rahul Khanwani
 
Convolution codes and turbo codes
Convolution codes and turbo codesConvolution codes and turbo codes
Convolution codes and turbo codes
Manish Srivastava
 
Channel Equalisation
Channel EqualisationChannel Equalisation
Channel Equalisation
Poonan Sahoo
 

Was ist angesagt? (20)

Turbo Code
Turbo Code Turbo Code
Turbo Code
 
Adaptive linear equalizer
Adaptive linear equalizerAdaptive linear equalizer
Adaptive linear equalizer
 
Bit plane coding
Bit plane codingBit plane coding
Bit plane coding
 
Data compression huffman coding algoritham
Data compression huffman coding algorithamData compression huffman coding algoritham
Data compression huffman coding algoritham
 
image compression ppt
image compression pptimage compression ppt
image compression ppt
 
Compression: Video Compression (MPEG and others)
Compression: Video Compression (MPEG and others)Compression: Video Compression (MPEG and others)
Compression: Video Compression (MPEG and others)
 
JPEG Image Compression
JPEG Image CompressionJPEG Image Compression
JPEG Image Compression
 
7 convolutional codes
7 convolutional codes7 convolutional codes
7 convolutional codes
 
Convolution codes and turbo codes
Convolution codes and turbo codesConvolution codes and turbo codes
Convolution codes and turbo codes
 
Convolution codes - Coding/Decoding Tree codes and Trellis codes for multiple...
Convolution codes - Coding/Decoding Tree codes and Trellis codes for multiple...Convolution codes - Coding/Decoding Tree codes and Trellis codes for multiple...
Convolution codes - Coding/Decoding Tree codes and Trellis codes for multiple...
 
Pulse modulation
Pulse modulationPulse modulation
Pulse modulation
 
Adaptive Huffman Coding
Adaptive Huffman CodingAdaptive Huffman Coding
Adaptive Huffman Coding
 
Data Communication & Computer network: Shanon fano coding
Data Communication & Computer network: Shanon fano codingData Communication & Computer network: Shanon fano coding
Data Communication & Computer network: Shanon fano coding
 
Convolutional codes
Convolutional codesConvolutional codes
Convolutional codes
 
Channel Coding (Digital communication)
Channel Coding (Digital communication)Channel Coding (Digital communication)
Channel Coding (Digital communication)
 
Pcm
PcmPcm
Pcm
 
Unit 2 processor&amp;memory-organisation
Unit 2 processor&amp;memory-organisationUnit 2 processor&amp;memory-organisation
Unit 2 processor&amp;memory-organisation
 
Channel Equalisation
Channel EqualisationChannel Equalisation
Channel Equalisation
 
Vector Quantization Vs Scalar Quantization
Vector Quantization Vs Scalar Quantization Vector Quantization Vs Scalar Quantization
Vector Quantization Vs Scalar Quantization
 
Predictive coding
Predictive codingPredictive coding
Predictive coding
 

Ähnlich wie Module 4 Arithmetic Coding

basicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptxbasicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptx
upendrabhatt13
 
The performance of turbo codes for wireless communication systems
The performance of turbo codes for wireless communication systemsThe performance of turbo codes for wireless communication systems
The performance of turbo codes for wireless communication systems
chakravarthy Gopi
 
Matlab 3
Matlab 3Matlab 3
Matlab 3
asguna
 
SURF 2012 Final Report(1)
SURF 2012 Final Report(1)SURF 2012 Final Report(1)
SURF 2012 Final Report(1)
Eric Zhang
 

Ähnlich wie Module 4 Arithmetic Coding (20)

High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
 
Er24902905
Er24902905Er24902905
Er24902905
 
basicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptxbasicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptx
 
The performance of turbo codes for wireless communication systems
The performance of turbo codes for wireless communication systemsThe performance of turbo codes for wireless communication systems
The performance of turbo codes for wireless communication systems
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysis
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
system software 16 marks
system software 16 markssystem software 16 marks
system software 16 marks
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptx
 
Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法
 
Matlab 3
Matlab 3Matlab 3
Matlab 3
 
Lec5 Compression
Lec5 CompressionLec5 Compression
Lec5 Compression
 
internal assement 3
internal assement 3internal assement 3
internal assement 3
 
Ch9b
Ch9bCh9b
Ch9b
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Modulation techniques matlab_code
Modulation techniques matlab_codeModulation techniques matlab_code
Modulation techniques matlab_code
 
CHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐ
CHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐCHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐ
CHƯƠNG 2 KỸ THUẬT TRUYỀN DẪN SỐ - THONG TIN SỐ
 
Arithmetic Coding
Arithmetic CodingArithmetic Coding
Arithmetic Coding
 
SURF 2012 Final Report(1)
SURF 2012 Final Report(1)SURF 2012 Final Report(1)
SURF 2012 Final Report(1)
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
 
Fast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka StreamsFast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka Streams
 

Mehr von anithabalaprabhu (20)

Shannon Fano
Shannon FanoShannon Fano
Shannon Fano
 
Ch 04 Arithmetic Coding ( P P T)
Ch 04  Arithmetic  Coding ( P P T)Ch 04  Arithmetic  Coding ( P P T)
Ch 04 Arithmetic Coding ( P P T)
 
Compression
CompressionCompression
Compression
 
Datacompression1
Datacompression1Datacompression1
Datacompression1
 
Speech Compression
Speech CompressionSpeech Compression
Speech Compression
 
Z24 4 Speech Compression
Z24   4   Speech CompressionZ24   4   Speech Compression
Z24 4 Speech Compression
 
Dictor
DictorDictor
Dictor
 
Compression Ii
Compression IiCompression Ii
Compression Ii
 
06 Arithmetic 1
06 Arithmetic 106 Arithmetic 1
06 Arithmetic 1
 
Lassy
LassyLassy
Lassy
 
Compression Ii
Compression IiCompression Ii
Compression Ii
 
Lossy
LossyLossy
Lossy
 
Planning
PlanningPlanning
Planning
 
Lossless
LosslessLossless
Lossless
 
Losseless
LosselessLosseless
Losseless
 
Lec32
Lec32Lec32
Lec32
 
Huffman Student
Huffman StudentHuffman Student
Huffman Student
 
Huffman Encoding Pr
Huffman Encoding PrHuffman Encoding Pr
Huffman Encoding Pr
 
Huffman Coding
Huffman CodingHuffman Coding
Huffman Coding
 
Huffman1
Huffman1Huffman1
Huffman1
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Module 4 Arithmetic Coding

  • 1. Module 4 Arithmetic Coding Prof. Hung-Ta Pai Module 4, Data Compression LISA, NTPU 1
  • 2. Reals in Binary Any real number x in the interval [0, 1) can be represented in binary as .b1b2... where bi is a bit Module 4, Data Compression LISA, NTPU 2
  • 3. First Conversion L:=0; R:=1; i :=1; while x > L * if x < (L+R)/2 then bi := 0; R := (L+R)/2; if x ≥ (L+R)/2 then bi := 1; L := (L+R)/2; i := i + 1; end{while} bi := 0 for all j ≥ i; * Invariant: x is always in the interval [L, R) Module 4, Data Compression LISA, NTPU 3
  • 4. Basic Ideas Represent each string x of length n by a unique interval [L, R) in [0, 1) The width of the interval [L, R) represents the probability of x occurring The interval [L, R) can itself be represented by any number, called a tag, within the half open interval The k significant bits of the tag .t1t2t3.... is the code of x That is, .t1t2t3...tk000... is in the interval [L, R) Module 4, Data Compression LISA, NTPU 4
  • 5. Example 1. Tag must be in the half open interval 2. Tag can be chosen to be (L+R)/2 3. Code is the significant bits of the tag Module 4, Data Compression LISA, NTPU 5
  • 6. Better Tag Module 4, Data Compression LISA, NTPU 6
  • 7. Example of Codes P(a) = 1/3, P(b) = 2/3 Module 4, Data Compression LISA, NTPU 7
  • 8. Code Generation from Tag If binary tag is .t1t2t3... = (L+R)/2 in [L, R), then we want to choose k to form the code t1t2 ...tk Short code: choose k to be as small as possible so that L ≤ . t1t2 ...tk000... < R Guaranteed code: Choose k = ⎡log2(1/(R-L))⎤ + 1 L ≤ . t1t2 ...tkb1b2b3... < R for any bits b1b2b3... For fixed length strings provides a good prefix code Example: [.000000000..., .000010010...), tag = .000001001... Short code: 0 Guaranteed code: 000001 Module 4, Data Compression LISA, NTPU 8
  • 9. Guaranteed Code Example P(a) = 1/3, P(b) = 2/3 Guaranteed code -> Prefix code Module 4, Data Compression LISA, NTPU 9
  • 10. Coding Algorithm P(a1), P(a2), ..., P(am) C(ai) = P(a1) + P(a2) + ... +P(ai-1) Encode x1x2...xn Initialize L := 0; and R:=1; For i = 1 to n do W := R - L; L := L + W * C(xi); R := L + W * P(xi); end; t := (L+R)/2; choose code for the tag Module 4, Data Compression LISA, NTPU 10
  • 11. Coding Example P(a) = 1/4, P(b) = 1/2, P(c) = 1/4 C(a) = 0, C(b) =1/4, C(c) = 3/4 abca Module 4, Data Compression LISA, NTPU 11
  • 12. Coding Excercise P(a) = 1/4, P(b) = 1/2, P(c) = 1/4 C(a) = 0, C(b) =1/4, C(c) = 3/4 bbbb Module 4, Data Compression LISA, NTPU 12
  • 13. Decoding (1/3) Assume the length is known to be 3 0001 which converts to the tag .0001000 Module 4, Data Compression LISA, NTPU 13
  • 14. Decoding (2/3) Assume the length is known to be 3 0001 which converts to the tag .0001000 Module 4, Data Compression LISA, NTPU 14
  • 15. Decoding (3/3) Assume the length is known to be 3 0001 which converts to the tag .0001000 Module 4, Data Compression LISA, NTPU 15
  • 16. Decoding Algorithm P(a1), P(a2), ..., P(am) C(ai) = P(a1) + P(a2) + ... +P(ai-1) Decode b1b2...bm, number of symbols is n Initialize L := 0; and R:=1; t := b1b2...bm000... for i = 1 to n do W := R - L; find j such that L + W * C(aj) ≤ t < L + W * (C(aj)+P(aj)); output aj; L := L + W * C(aj); R = L + W * P(aj); Module 4, Data Compression LISA, NTPU 16
  • 17. Decoding Example P(a) = 1/4, P(b) = 1/2, P(c) = 1/4 C(a) = 0, C(b) =1/4, C(c) = 3/4 00101 Module 4, Data Compression LISA, NTPU 17
  • 18. Decoding Issues There are two ways for the decoder to know when to stop decoding Transmit the length of the string Transmit a unique end of string symbol Module 4, Data Compression LISA, NTPU 18
  • 19. Practical Arithmetic Coding Scaling: By scaling we can keep L and R in a reasonable range of values so that W = R–L does not underflow The code can be produced progressively, not at the end Complicates decoding some Integer arithmetic coding avoids floating point altogether Module 4, Data Compression LISA, NTPU 19
  • 20. Adaptation Simple solution – Equally Probable Model Initially all symbols have frequency 1 After symbol x is coded, increment its frequency by 1 Use the new model for coding the next symbol Example in alphabet a, b, c, d Module 4, Data Compression LISA, NTPU 20
  • 21. Zero Frequency Problem How do we weight symbols that have not occurred yet? Equal weight? Not so good with many symbols Escape symbol, but what should its weight be? When a new symbol is encountered send the <esc>, followed by the symbol in the equally probable model (both encoded arithmetically) Module 4, Data Compression LISA, NTPU 21
  • 22. End of File Problem Similar to Zero Frequency Problem Reasonable solution: Add EOF to the post-ESC equally-probable model When done compressing: First send ESC Then send EOF What’s the cost of this approach? Module 4, Data Compression LISA, NTPU 22
  • 23. Arithmetic vs. Huffman Both compress very well For m symbol grouping Huffman is within 1/m of entropy Arithmetic is within 2/m of entropy Context Huffman needs a tree for every context Arithmetic needs a small table of frequencies for every context Adaptation Huffman has an elaborate adaptive algorithm Arithmetic has a simple adaptive mechanism Module 4, Data Compression LISA, NTPU 23