-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4_d.m
More file actions
54 lines (45 loc) · 1.67 KB
/
Q4_d.m
File metadata and controls
54 lines (45 loc) · 1.67 KB
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
46
47
48
49
50
51
52
53
54
clear
N = 20000;
ratios_golomb_rl = [];
ratios_arith = [];
ratios_ideal = [];
range = 0.05:0.05:0.95;
for alpha = range
beta = alpha;
string = generateMarkov1String(N, alpha, beta);
[~, string_rl] = binaryToRunLength(string);
string_rl = string_rl - 1;
string_rl_golomb = encodeGolomb(string_rl, mean(string_rl), 20);
% estimateEntropy(string_rl_golomb)
% estimateEntropyRate(string_rl_golomb)
ratio_golomb_rl = N / (length(string_rl_golomb) + 1);
ratios_golomb_rl = [ratios_golomb_rl, ratio_golomb_rl];
[length_rl_encoded, ~, ~] = computeOptLength(string_rl);
ratio_ideal = N / (length_rl_encoded+1);
ratios_ideal = [ratios_ideal, ratio_ideal];
string_arith = encodeArithmeticMarkov1Modi(string, alpha);
% estimateEntropyRate(string_arith)
% estimateEntropy(string_arith)
ratio_arith = N / length(string_arith);
ratios_arith = [ratios_arith ratio_arith];
end
figure;
plot(range, ratios_ideal, '-.', LineWidth=1.5)
hold on
plot(range, ratios_golomb_rl, LineWidth=1.5)
hold on
plot(range, ratios_arith, '-*', LineWidth=1.5, Color='cyan')
line([0 1], [1 1], 'Color','magenta','LineStyle','--')
ylim([0 4])
title('Compress Ratio as a Function of \alpha')
xlabel('\alpha')
ylabel('Ratio (length source / length encoded)')
legend('Ideal RunLength Encoder', 'RunLength+Golomb','Arithmetic Code','Compression Threshold, Ratio=1')
figure;
plot(range, ratios_arith, '-*', LineWidth=1.5,Color='cyan')
line([0 1], [1 1], 'Color','magenta','LineStyle','--')
ylim([0 4])
title('Compress Ratio as a Function of \alpha')
xlabel('\alpha')
ylabel('Ratio (length source / length encoded)')
legend('Arithmetic Code','Compression Threshold, Ratio=1')