Golomb coding
From Free net encyclopedia
Golomb coding is a form of entropy coding invented by Solomon W. Golomb that is optimal for alphabets following geometric distributions, that is, when small values are vastly more common than large values.
It uses a tunable parameter b to divide an input value into two parts: <math>q</math>, the result of a division by b, and <math>r</math>, the remainder. The quotient is sent in unary coding, followed by the remainder in truncated binary encoding. When <math>b=1</math> Golomb coding is equivalent to unary coding.
Formally, the two parts are given by the following expression, where <math>x</math> is the number being encoded:
<math>q = \left \lfloor \frac{\left (x-1 \right )}{b} \right \rfloor</math>
and
<math>r = x-qb-1</math>
The final result looks like:
<math>\left (q+1 \right ) r</math>
Note that <math>r</math> can be of a varying number of bits.
The parameter b is a function of the corresponding Bernoulli process, which is parameterized by <math>p=P(X=0)</math> the probability of success in a given Bernoulli Trial. <math>b</math> and <math>p</math> are related by these inequalities:
<math>(1-p)^b + (1-p)^{b+1} \leq 1 < (1-p)^{b-1} + (1-p)^b</math>
The Golomb code for this distribution is equivalent to the Huffman code for the same probabilities, if it were possible to compute the Huffman code.
Rice coding is a special case of Golomb coding first described by Robert Rice. It is equivalent to Golomb coding where the tunable parameter is a power of two. This makes it extremely efficient for use on computers, since the division operation becomes a bitshift operation and the remainder operation becomes a bitmask operation.
Applications
The FLAC audio codec uses Rice coding to represent linear prediction residues.
Apple's ALAC audio codec uses modfied Rice coding after its Adaptive FIR filter.
References
- Golomb, S.W. (1966). Run-length encodings. IEEE Transactions on Information Theory, IT--12(3):399--401 [1]
- R. F. Rice, "Some Practical Universal Noiseless Coding Techniques, " Jet Propulsion Laboratory, Pasadena, California, JPL Publication 79--22, Mar. 1979.
- Witten, Ian Moffat, Alistair Bell, Timothy. "Managing Gigabytes: Compressing and Indexing Documents and Images." Second Edition. Morgan Kaufmann Publishers, San Francisco CA. 1999 ISBN 1-55860-570-3de:Golomb Code