0% found this document useful (0 votes)
12 views2 pages

MATLAB Huffman Source Encoding Guide

This document describes a MATLAB program for source encoding using Huffman coding. The program takes in a list of symbol probabilities, combines the two lowest probabilities into a new symbol, and repeats this process until only two symbols remain which are assigned 0 and 1 codes. It then works backwards to determine the code for each original symbol by tracking the sequence of 0s and 1s assigned during the combining process.

Uploaded by

ev
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

MATLAB Huffman Source Encoding Guide

This document describes a MATLAB program for source encoding using Huffman coding. The program takes in a list of symbol probabilities, combines the two lowest probabilities into a new symbol, and repeats this process until only two symbols remain which are assigned 0 and 1 codes. It then works backwards to determine the code for each original symbol by tracking the sequence of 0s and 1s assigned during the combining process.

Uploaded by

ev
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Source Coding

Aim:
To write MATLAB program for source encoding.
Software required:
1) MATLAB software system
2) keyboard
3) mouse
Program:
function code=huffman(p);
global code;
p=[0.4 0.19 0.16 0.15 0.1]
code=cell(length(p),1);
if length(p)1
!="educ1(p);
ma#ecode(!,[]);
el!e
code=$%1%&;
end;
function !="educ1(p);
!=cell(length(p),1);
fo" i=1'1'length(p)
!$i&=i;
end;
(hile numel(!));
[p,i]=!o"t(p);
p())=p(1)*p());
p(1)=[];
!=!(i);
!$)&=$!$1&,!$)&&;
!(1)=[];
end;
function ma#ecode(!c,code(o"d);
global code;
if i!a (!c,%cell%);
ma#ecode(!c$1&,[code(o"d 0]);
ma#ecode(!c$)&,[code(o"d 1]);
el!e
code$!c&=cha"(%0%*code(o"d);
end;
001
Agorit!m"
#tep 1"
T!e source symbos are isted in order to increase probabiity .T!e 2 source symbos of owest
probabiities are assigned as 0 and 1 . T!e part of t!e step is referred to as spitting range.
#tep 2"
T!e two source symbos are regarded as being combined into a new source symbo wit!
probabiity e$ua to t!e sum of 2 origina probabiities. T!e probabiity of new symbos is paced
in t!e ist accordance wit! its %aue.
#tep 3"
T!e procedure is repeated unti we are eft wit! a fina ist of source c!aracteristics of ony two
for w!ic! 0 and 1 are assigned.
T!e code for eac! source symbo is found by working backward and tracking t!e
se$uence of 0 and 1 assigned to t!e symbo as we its success.
&iagram"
#ymbo 'robabiity
#1 0.( 0.( 0.( 0.)
#2 0.1* 0.2+ 0.3+ 0.(
#3 0.1) 0.1* 000 0.2+
#( 0.1+ 0.1)
#+ 0.1
0
1
00
01

You might also like