Created
May 8, 2016 22:02
-
-
Save agaikwad123/ae5d7073b1e2fb525d02a92e2da083da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear all; | |
clc; | |
n=5; % no. of inputs | |
disp(Probabilities of messages:); | |
p=[0.4 0.2 0.1 0.2 0.1];disp(p); | |
s=1:n; | |
[dict,avglen]=huffmandict(s,p); | |
disp('Huffman Dicitionary :');disp(dict); | |
disp('Huffman bit length :');disp(avglen); | |
temp = dict; | |
for i=1:length(temp) | |
temp{i,2}=num2str(temp{i,2}); | |
end | |
disp(temp); | |
sig=[1 3 4 2]; | |
disp('String of message:');disp(sig); | |
disp('Huffman codes for given messages:'); | |
sc=huffmanenco(sig,dict);disp(sc); | |
disp('Received bit string:'); | |
mr=[1 0 0 1 1 0 1 0 0 0]; | |
mo=huffmandeco(mr,dict); | |
disp(mo); | |
err=isequal(sig,mo); | |
if err==1 | |
disp(Message recovered correctly); | |
else | |
disp(Error in decoding); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment