MATLAB Examples

Create and Decode an Arithmetic Code

Encode and decode a sequence from a source having three symbols.

Create a sequence vector containing symbols from the set of {1,2,3}.

seq = [3 3 1 3 3 3 3 3 2 3];

Set the counts vector to define an encoder that produces 10 ones, 20 twos, and 70 threes from a typical 100-symbol set of test data.

counts = [10 20 70];

Apply the arithmetic encoder and decoder functions.

code = arithenco(seq,counts);
dseq = arithdeco(code,counts,length(seq));

Verify that the decoder output matches the original input sequence.

isequal(seq,dseq)
ans =

  logical

   1