
%% Exercises Ch1, Sec. Mean Rate

%% Comma Code Rate
clear all
P=[2/5 3/10 1/5 1/10];
P=[1/6,1/3,1/3,1/6];
P=[1/4,1/4,1/4,1/4]; 
%P=[1 1 1 1]/4;
%2*log(4)/5/log(2)
tau=[1 2 3 4]; % for comma code
T=P*tau'; % Average symbol time
H=P*(log(1./P))'/log(2) % Entropy
R=H/T

% as part of the binary code
p=P*[((tau-1)./tau)',([1 1 1 1]./tau)']; %signal distribution
h=p*(log(1./p))'/log(2)
t=p*[1 1]';
r=h/t
%% Comma Code Rate