Code covered by the BSD License  

Highlights from
Huffman Encoder

Huffman Encoder

by

 

Input-number of occurrences or probabilities in a row matrix form Output-avelength,codewords,probab

huffmancode.m
clear
format long
op=fopen('C:\Users\mariska\Desktop\FF7.txt');
rd=fread(op);
%translate data to its ascii equivalent
un=unique(rd); 
%find used characters
for n=1:length(un)
    occ(n,1)=length(find(rd==un(n))); 
    %count the occurence of a character
end
e=char(un); 
%character equivalent of ascii codes
z=input('Input "1" for normal huffman or "2" for 2nd extension: ');
%prompts the user to choose between huffman or its 2nd extension
%Entropy
if z==1
    extension=transpose(occ);
    %count per char
elseif z==2
    %%Huffman 2nd extension
    u=1;
    for o=1:length(occ)
        for ii=1:length(occ)
            extension(u)=occ(o,1)*occ(ii,1);
            %computes for the huffman second extension probabilities
            u=u+1;
        end
    end
   
else
    error('Error input!')
end
[codex tau]=huffmankasan(extension)

Contact us