-
Notifications
You must be signed in to change notification settings - Fork 0
/
channelcapacity.m
45 lines (37 loc) · 906 Bytes
/
channelcapacity.m
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
39
40
41
42
43
44
45
close all;
clear all;
clc;
r=input('Enter the number of inputs\n>> '); % input alphabet size is entered
s=input('Enter the number of outputs\n>> '); % output alphabet size is entered
T=zeros(r,s);
disp('Enter the valid channel transition matrix row wise.');
for i=1:r
for j=1:s
T(i,j)=input('>> ');
end
end
% Channel Transition Matrix is obtained in T;
Px=1/r; % probability of inputs is uniform
Hx=log2(r); % Entropy of input alphabet
Py=zeros(1,s); % probability values of output
for j=1:s
for i=1:r
Py(1,j)=Py(1,j)+T(i,j)*Px;
end
end
% conditional entropy of x given y is computed using basic formula
Hxy=0;
for i=1:r
for j=1:s
if (T(i,j)~=0)
Hxy=Hxy+Px*T(i,j)*log2(T(i,j)*Px/Py(1,j));
end
end
end
Hxy=-Hxy;
% Capacity = Max(H(x) - H(x/y))
C=Hx-Hxy;
disp('The transition matrix:');
disp(T);
disp('Capacity:');
disp(C);