Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

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