Encode sequence of symbols by arithmetic encoding
Using a source with a two-symbol alphabet, produce a test data set in which 99% of the symbols are 1s. Encode 1000 symbols from this source to produce a code vector with less than 1000 elements. The actual number of elements in the encoded sequence varies depending on the particular random sequence.
Specify for symbol 1 from the source alphabet to occur 99 times in the test data set.
counts = [99 1]
counts = 1×2 99 1
Generate a random sequence of length 1000.
len = 1000; seq = randsrc(1,len,[1 2; .99 .01]);
Encode the random sequence and display the encoded length.
code = arithenco(seq,counts); s = size(code)
s = 1×2 1 57
seq— Sequence of symbols
Sequence of symbols, specified as a positive numeric row vector. This input specifies the random sequence for the function to encode.
counts— Statistics of symbols
Statistics of symbols, specified as a positive numeric row vector. This input specifies the number of times each symbol of the source alphabet occurs in a test data set.
code— Generated binary arithmetic code
Generated binary arithmetic code corresponding to the sequence of source symbols, returned as a nonnegative binary row vector.
arithenco function uses the algorithm described in .
 Sayood, Khalid. Introduction to Data Compression. 2nd ed. San Francisco: Morgan Kaufmann Publishers, 2000.