Infomation Theory
Infomation Theory
for i = 1:length(symbols)
code = dictionary{i,2};
fprintf('%d : [%s]\n', symbols(i), num2str(code));
end
0 : [0]
1 : [1 1 1]
2 : [1 1 0]
3 : [1 0 0 1]
4 : [1 0 0 0]
5 : [1 0 1 1]
6 : [1 0 1 0]
% (b) PMF of compressed file and expected length for 1000 symbols
expected_len = avglen * 1000;
% Compute probability of 0 and 1 in compressed bits
total0 = sum(p .* cellfun(@(c) sum(c==0), dictionary(:,2)));
total1 = sum(p .* cellfun(@(c) sum(c==1), dictionary(:,2)));
prob0 = total0 / avglen;
prob1 = total1 / avglen;
fprintf('Probability of 0: %.4f, Probability of 1: %.4f\n', prob0, prob1);
1
t = 10000;
seq = randsample(symbols, t, true, p);
Symbol 0: 50.54%
Symbol 1: 12.35%
Symbol 2: 12.41%
Symbol 3: 6.18%
Symbol 4: 6.01%
Symbol 5: 6.31%
Symbol 6: 6.20%
% (i) Explanation:
2
% The Huffman code reduces average code length below the fixed-length of 3
bits,
% resulting in fewer total bits and a change in bit probability due to
% variable-length assignments favoring more likely symbols.
3
Bottles to mix in first test: [1 3 5]
Symbol 1: 0 (length = 1)
Symbol 2: 10 (length = 2)
Symbol 3: 110 (length = 3)
Symbol 4: 111 (length = 3)