-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ4_c_m_10.m
44 lines (38 loc) · 1.4 KB
/
Q4_c_m_10.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
clear
N = 20000;
m = 10;
L_1 = N/m;
entropy_rate_string_track = [];
entropy_rate_enc_string_track = [];
range = 0.1:0.05:0.9;
for alpha = range
beta = alpha;
string = generateMarkov1String(N, alpha, beta);
enc_string = encodeArithmeticMarkov1Modi(string, alpha);
L_2 = floor(length(enc_string)/m);
entropy_rate_string_m_hist = [];
entropy_rate_enc_string_m_hist = [];
for i = 1:L_1
idx = (i-1)*m+1:i*m;
entropy_rate_string_m = estimateEntropyRate(string(idx));
entropy_rate_string_m_hist = [entropy_rate_string_m_hist entropy_rate_string_m];
end
for i = 1:L_2
idx = (i-1)*m+1:i*m;
entropy_rate_enc_string_m = estimateEntropyRate(enc_string(idx));
entropy_rate_enc_string_m_hist = [entropy_rate_enc_string_m_hist entropy_rate_enc_string_m];
end
entropy_rate_string = mean(entropy_rate_string_m_hist);
entropy_rate_enc_string = mean(entropy_rate_enc_string_m_hist);
entropy_rate_string_track = [entropy_rate_string_track entropy_rate_string];
entropy_rate_enc_string_track = [entropy_rate_enc_string_track entropy_rate_enc_string];
end
figure;
plot(range, entropy_rate_string_track, '-x', Color='r', LineWidth=1.5)
hold on
plot(range, entropy_rate_enc_string_track, '--*', Color='b', LineWidth=1.5)
ylim([0 1])
title('m = 10')
xlabel('\alpha')
ylabel('Entropy Rate H\{X_n\}')
legend('Markov-1 String', 'Arithmetic Code Stream')