Builds a Huffman code, given a probability list. The Huffman codes per symbol are output as a list of strings-per-source symbol. A zero probability symbol is NOT assigned any codeword as this symbol doesn’t occur in practice anyway.
toggle is an optional argument with values 1 or 0, that starts
building a code based on 1s or 0s, defaulting to 0. Also minvar
is a boolean value that is useful in choosing if you want to optimize
buffer for transmission in the applications of Huffman coding, however
it doesn’t affect the type or average codeword length of the generated
code. An example of the use of huffmandict
is
huffmandict (symbols, [0.5 0.25 0.15 0.1], 1) ⇒ {[0], [1 0], [1 1 1], [1 1 0]} huffmandict (symbols, 0.25 * ones (1,4), 1) ⇒ {[1 1], [1 0], [0 1], [0 0]} prob = [0.5 0 0.25 0.15 0.1]; dict = huffmandict (1:5, prob, 1); entropy (prob) ⇒ 2.3219 laverage (dict, prob) ⇒ 1.8500 x = [0.2 0.4 0.2 0.1 0.1]; huffmandict (1, x, 0, true) ⇒ {[1 0], [0 0], [1 1], [0 1 0], [0 1 1]} huffmandict (1, x) ⇒ {[0 1], [1], [0 0 1], [0 0 0 0], [0 0 0 1]}
Reference: Dr.Rao’s course EE5351 Digital Video Coding, at UT-Arlington.
See also: huffmandeco, huffmanenco.
Package: communications