This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Encode sequence of symbols using arithmetic coding


code = arithenco(seq,counts)


code = arithenco(seq,counts) generates the binary arithmetic code corresponding to the sequence of symbols specified in the vector seq. The vector counts represents the source's statistics by listing the number of times each symbol of the source's alphabet occurs in a test data set.


collapse all

This example illustrates the compression that arithmetic coding can accomplish in some situations. A source has a two-symbol alphabet and produces a test data set in which 99% of the symbols are 1s. Encoding 1000 symbols from this source produces a code vector having fewer than 1000 elements. The actual number of elements in encoded sequence varies depending on the particular random sequence.

Set counts so that a one occurs 99% of the time.

counts = [99 1];

Generate a random data sequence of length 1000.

len = 1000;
seq = randsrc(1,len,[1 2; .99 .01]);

Encode the sequence and display the encoded length.

code = arithenco(seq,counts);
s = size(code)
s = 1×2

     1    57

The length of the encoded sequence is only 5.7% of the length of the original sequence.


This function uses the algorithm described in [1].


[1] Sayood, Khalid, Introduction to Data Compression, San Francisco, Morgan Kaufmann, 2000.

Introduced before R2006a