Communications Toolbox | ![]() ![]() |
Arithmetic Coding
Arithmetic coding offers a way to compress data and can be useful for data sources having a small alphabet. The length of an arithmetic code, instead of being fixed relative to the number of symbols being encoded, depends on the statistical frequency with which the source produces each symbol from its alphabet.
The arithenco
and arithdeco
functions support arithmetic coding and decoding.
Note Arithmetic coding is different from Huffman coding. For long sequences from sources having skewed distributions and small alphabets, arithmetic coding compresses better than Huffman coding. |
Representing Arithmetic Coding Parameters
Arithmetic coding requires statistical information about the source of the data being encoded. In particular, the counts
input argument in the arithenco
and arithdeco
functions lists the frequency with which the source produces each symbol in its alphabet. You can determine the frequencies by studying a set of test data from the source. The set of test data can have any size you choose, as long as each symbol in the alphabet has a nonzero frequency.
For example, before encoding data from a source that produces 10 x's, 10 y's, and 80 z's in a typical 100-symbol set of test data, define
Alternatively, if a larger set of test data from the source contains 22 x's, 23 y's, and 185 z's, then define
Example: Creating and Decoding an Arithmetic Code
The example below performs arithmetic encoding and decoding, using a source whose alphabet has three symbols.
seq = repmat([3 3 1 3 3 3 3 3 2 3],1,50); counts = [10 10 80]; code = arithenco(seq,counts); dseq = arithdeco(code,counts,length(seq));
![]() | Companding a Signal | Selected Bibliography for Source Coding | ![]() |