%ELG5126 %Huffman coding example from Lecture 4 clear all, close all; %probability vector p = [.25 .2 .2 .18 .09 .05 .02 .01]; %first order entropy H_1 = sum(-p .* log2(p)); %define the symbols to be the integers from 1 to 8 sym = 1:8; % %Use the huffmandict routine from the communications toolbox to get both a %Huffman code and the average codeword length. %If you double-click DICT in the workspace, you can see the codewords in %the Variable Editor. % [DICT, AVGLEN] = huffmandict(sym,p); % %Shannon codeword lengths and average codeword length ell_i_shann = ceil(-log2(p)); ell_shann = sum(p.*ell_i_shann);