File Exchange

image thumbnail


version 1.0 (9.58 KB) by

A set of MATLAB m-files (version 5.2) which do complete Huffman Coding.



No License

A set of MATLAB m-files (version 5.2) which do complete Huffman Coding.

The files are:

hufflen: Based on probability (or number of occurences) of each symbol the length for the Huffman codewords are calculated.

ex: HL = hufflen(S);

huffcode: Based on the codeword lengths this function find the Huffman codewords

ex: HK = huffcode(HL);

hufftree: Make the Huffman-tree from the length of Huffman codes

ex: Htree = hufftree(HL);

huff03: Huffman encoder/decoder, one or two vectors of non-negative integers are huffman coded.

ex: y = huff03(x1, x2); % encoding
ex: [x1, x2] = huff03(y); % decoding

Comments and Ratings (9)

Authors remark:
A newer zip-file is now available from

milind tandel

Faisal Alhajri

It`s not bad. However, I think you can make it more simple and efficient. It`s too long and it needs three other function beside the orginal one, you can combine them in one function and much less lines. it's going to be then more faster in execution and less error. I have made one but still in progress. anyway, mine is much less lines than this one. You are like trying to execute 1+1 in this manner y = 1, x = 1, and z = y, s = x, then g = z + s.
Good luck man.

mickey mickey


bala sundaram

its really nice


the coding process is not running correctly it fails in encoding itself help for it

George Castle

I tried using a square wave with a long period and the compression was no different than for a random sequence. There appears to be a bug that needs fixing first.

Afshin David

Doesn't seem to work, e.g., for a constant sequence it gives irrelevant codewords.

akam paul

I try it

MATLAB Release
MATLAB 5.2 (R10)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video