summaryrefslogtreecommitdiff
path: root/1895/CH11/EX11.46/EXAMPLE11_46.sce
blob: 2d9394e8fdbf63f58b97eb396f544dccf39fcfd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//ANALOG AND DIGITAL COMMUNICATION
//BY Dr.SANJAY SHARMA
//CHAPTER 11
//Information Theory
clear all;
clc;
printf("EXAMPLE 11.46(PAGENO 532)");

//given
P_x1 = .4//probability of first signal
P_x2 = .19//probability of second signal
P_x3 = .16//probability of third signal
P_x4 = .15//probability of fourth signal
P_x5 = .1//probability of fifth signal
n1 = 1//number of bits in code obtained from table givenn textbook
n2 = 2//number of bits in code obtained from table givenn textbook
n3 = 2//number of bits in code obtained from table givenn textbook
n4 = 3//number of bits in code obtained from table givenn textbook
n5 = 3//number of bits in code obtained from table givenn textbook

//calculations
I_x1 = -log2(P_x1);
I_x2 = -log2(P_x2);
I_x3 = -log2(P_x3);
I_x4 = -log2(P_x4);
I_x5 = -log2(P_x5);
H_x = P_x1*I_x1 +  P_x2*I_x2 +  P_x3*I_x3 +  P_x4*I_x4 +  P_x5*I_x5;//entropy
L1 = P_x1*n1 + P_x2*n2 + P_x3*n3 + P_x4*n4 + P_x5*n5;
neta1 = H_x/L1;
P_neta1 = neta1*100//efficiency in percentage using Shannon Fano code
L2 = P_x1*1 + (P_x2 + P_x3 +P_x4 +P_x5 )*3
neta2 = H_x/L2;
P_neta2 = neta2*100//efficiency in percentage using huffman code

//results
printf("\n\nEfficiency in percentage using Shannon Fano code = %2f percent",P_neta1)
printf("\n\nEfficiency in percentage using huffman code   = %2f percent",P_neta2)
printf("\n\nNote: There is mistake in the textbook in calculation of L using SHannon Fano code")