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
the source's statistics by listing the number of times each symbol
of the source's alphabet occurs in a test data set.
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.
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 57
The length of the encoded sequence is only 5.7% of the length of the original sequence.
 Sayood, Khalid, Introduction to Data Compression, San Francisco, Morgan Kaufmann, 2000.