-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp4.m
71 lines (59 loc) · 1.1 KB
/
p4.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
clc;
clear all;
clc;
L=20000;
a=0.1;
x=markov(a,L);
arcode=arithcode(x,a);
a2=0.1:0.05:0.9;
ho=[];
h=[];
hor=[];
hr=[];
ratio=zeros(1,length(a2));
ratio1=zeros(1,length(a2));
ratio2=zeros(1,length(a2));
for j=1:length(a2)
x=markov(a2(j),L);
rv=runlength(x);
counts=optimal(rv);
leng = 0;
for i=1:length(rv)
leng = leng + counts(rv(i));
end
ratio(j) = L/leng;
gc= golomb(rv);
ratio1(j) = L/length(gc);
arcode=arithcode(x,a2(j));
ratio2(j)=L/length(arcode);
h=[h,entropy(arcode,0)];
ho=[ho,entropy(x,0)];
hr=[hr,entropy(arcode,1)];
hor=[hor,entropy(x,1)];
end
figure;
plot(a2,h);
hold on
plot(a2,ho);
hold on
legend('entropy after code','origin entropy');
xlabel('value of alpha');
ylabel('entropy');
figure;
plot(a2,hr);
hold on
plot(a2,hor);
hold on
legend('entropy rate after code','origin entropy rate');
xlabel('value of alpha');
ylabel('entropy rate');
figure;
plot(a2,ratio);
hold on
plot(a2,ratio1);
hold on
plot(a2,ratio2);
hold on
legend('ideal run length','golomb','arithmetic');
xlabel('value of alpha');
ylabel('compression ratio');