comp = huffmanenco(sig,dict)
comp = huffmanenco(sig,dict) encodes
sig using the Huffman codes described
by the code dictionary
dict. The argument
have the form of a numeric vector, numeric cell array, or alphanumeric
cell array. If
sig is a cell array, it must be
either a row or a column.
dict is an N-by-2 cell
array, where N is the number of distinct possible symbols to be encoded.
The first column of
dict represents the distinct
symbols and the second column represents the corresponding codewords.
Each codeword is represented as a numeric row vector, and no codeword
dict can be the prefix of any other codeword
dict. You can generate
The example below encodes a vector of random data that has a prescribed probability distribution.
symbols = [1:6]; % Distinct symbols that data source can produce p = [.5 .125 .125 .125 .0625 .0625]; % Probability distribution [dict,avglen] = huffmandict(symbols,p); % Create dictionary. actualsig = randsrc(100,1,[symbols; p]); % Create data using p. comp = huffmanenco(actualsig,dict); % Encode the data.
 Sayood, Khalid, Introduction to Data Compression, San Francisco, Morgan Kaufmann, 2000.