-
Notifications
You must be signed in to change notification settings - Fork 20
/
ICompare.m
77 lines (73 loc) · 1.49 KB
/
ICompare.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
70
71
72
73
74
75
76
77
clear; close all; clc;
K=20;
M=400;
N=2000;
MI=zeros(2,7);
m=1;
t=10; %公式10求均值的循环次数
method=4;
s=1;
for SNR=-20:5:10
temp=0;
for h=1:t
I=0;
jj=0;
pxk=zeros(1,4);
[p,px]=GenP(SNR,K,M,N,method);
for k=1:4
for kk=1:4
pxk(k)=pxk(k)+p(4*(kk-1)+k)*px(kk);
end
end
for j=1:16
if(p(j)>0)
I=I+p(j)*px(fix(j/4.1)+1)*log(p(j)/pxk(j-4*jj))/log(2);
end
if(mod(j,4)==0)
jj=jj+1;
end
end
temp=temp+I;
end
MI(m,s)=temp/t;
s=s+1;
end
m=m+1;
s=1;
for SNR=-20:5:10
temp=0;
for h=1:t
I=0;
jj=0;
pxk=zeros(1,4);
[p,px]=Analytical(SNR,K,M,N,method);
for k=1:4
for kk=1:4
pxk(k)=pxk(k)+p(4*(kk-1)+k)*px(kk);
end
end
for j=1:16
if(p(j)>0)
I=I+p(j)*px(fix(j/4.1)+1)*log(p(j)/pxk(j-4*jj))/log(2);
end
if(mod(j,4)==0)
jj=jj+1;
end
end
temp=temp+I;
end
MI(m,s)=temp/t;
s=s+1;
end
%画图程序
hf = figure;
set( hf, 'color', 'white');
SNR=-20:5:10;
plot( SNR, MI(1,:), '-rs','LineWidth',1.5);
hold on;
plot( SNR, MI(2,:), '-bo','LineWidth',1.5);
set(hf,'position',[0,0,760,468])
grid on;
legend('numerical','analytical')
xlabel('\fontsize{14}SNR(dB)');
ylabel('\fontsize{14}Mutual information per user (bit/channel use)');