-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.m
137 lines (115 loc) · 4.43 KB
/
main.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
sample_num = 1000000;
% Preallocation for Bit error rate
Pe_sc = zeros(5, 4, 2); % selective combining
Pe_mrc = zeros(5,4, 2); % maximal ratio combining
Pe_egc = zeros(5,4, 2); % equal gain combining
Pe_dc = zeros(5,4, 2); % direct combining
tic
for R = 0:1 % Rayleigh:0 ; Ricean:1
% Different fading channel has different variance
if R == 0
sigma = 1/sqrt(2);
else
sigma = 1/2;
end
for enr_index = 1:5
enr_dB = (enr_index-1)*2+1; % energy-to-noise ratio:1, 3, 5, 7, 9 dB
enr = 10^(enr_dB/10);
% generate QPSK data (2 bits)
data = rand(2,sample_num); % 2*sample_num matrix
data = 2*(data > 0.5)-1; % map to -1, 1
Edata = sqrt(2); % symbol energy
En = Edata/enr; % noise energy
for L = 1:4
% generate noise
n = normrnd(0,sqrt(En/2),2,sample_num,L) + 1i*normrnd(0,sqrt(En/2),2,sample_num,L);
% generate fading gain (R=0: Rayleigh; R=1: Riciean)
g = normrnd(R/2,sigma,1,sample_num,L) + 1i*normrnd(R/sqrt(2),1/2,1,sample_num,L);
g_tmp = repmat(g,2,1,1); % replicate for 2 bits (QPSK)
tx_data = repmat(data,1,1,L); % replicate for L branches
% received signal
r = g_tmp.*tx_data + n;
%%% Selective combining %%%
[Pe_sc(enr_index, L, R+1), result_sc] = selective_combining(g, g_tmp, r, sample_num, data);
%%% Maximal Ratio Combining %%%
[Pe_mrc(enr_index, L, R+1), result_mrc] = maximal_ratio_combining(g_tmp, r, sample_num, data);
%%% Equal Gain Combining %%%
[Pe_egc(enr_index, L, R+1), result_egc] = equal_gain_combining(g_tmp, r, sample_num, data);
%%% Direct Combining %%%
[Pe_dc(enr_index, L, R+1), result_dc] = direct_combining(r, sample_num, data);
end
end
end
toc
% Plot Rayleigh
figure,plot([1 3 5 7 9], Pe_sc(:,:,1),'-*')
set(gca, 'YScale', 'log')
title('BER of Selective Combining (Rayleigh)');
legend('L=1','L=2','L=3','L=4');
xlabel('SNR (dB)');
ylabel('Bit error rate');
figure,plot([1 3 5 7 9], Pe_mrc(:,:,1),'-*')
set(gca, 'YScale', 'log')
title('BER of Maximal Ratio Combining (Rayleigh)');
legend('L=1','L=2','L=3','L=4');
xlabel('SNR (dB)');
ylabel('Bit error rate');
figure,plot([1 3 5 7 9], Pe_egc(:,:,1),'-*')
set(gca, 'YScale', 'log')
title('BER of Equal Gain Combining (Rayleigh)');
legend('L=1','L=2','L=3','L=4');
xlabel('SNR (dB)');
ylabel('Bit error rate');
figure,plot([1 3 5 7 9], Pe_dc(:,:,1),'-*')
set(gca, 'YScale', 'log')
title('BER of Direct Combining (Rayleigh)');
legend('L=1','L=2','L=3','L=4');
xlabel('SNR (dB)');
ylabel('Bit error rate');
% Plot Riciean
figure,plot([1 3 5 7 9], Pe_sc(:,:,2),'-*')
set(gca, 'YScale', 'log')
title('BER of Selective Combining (Ricean)');
legend('L=1','L=2','L=3','L=4');
xlabel('SNR (dB)');
ylabel('Bit error rate');
figure,plot([1 3 5 7 9], Pe_mrc(:,:,2),'-*')
set(gca, 'YScale', 'log')
title('BER of Maximal Ratio Combining (Ricean)');
legend('L=1','L=2','L=3','L=4');
xlabel('SNR (dB)');
ylabel('Bit error rate');
figure,plot([1 3 5 7 9], Pe_egc(:,:,2),'-*')
set(gca, 'YScale', 'log')
title('BER of Equal Gain Combining (Ricean)');
legend('L=1','L=2','L=3','L=4');
xlabel('SNR (dB)');
ylabel('Bit error rate');
figure,plot([1 3 5 7 9], Pe_dc(:,:,2),'-*')
set(gca, 'YScale', 'log')
title('BER of Direct Combining (Ricean)');
legend('L=1','L=2','L=3','L=4');
xlabel('SNR (dB)');
ylabel('Bit error rate');
% Comparison among all combining strategies
% Rayleigh
figure,plot([1 3 5 7 9], Pe_dc(:,4,1),'-*',[1 3 5 7 9], Pe_sc(:,4,1),'-+',[1 3 5 7 9], Pe_egc(:,4,1),'-*',[1 3 5 7 9], Pe_mrc(:,4,1),'-+')
set(gca, 'YScale', 'log')
title('BER of SC & MRC & EGC & DC (Rayleigh)');
legend('Direct Combining','Selective Combining','Equal Gain Combinig','Maximal Ratio Combining');
xlabel('SNR (dB)');
ylabel('Bit error rate');
% Ricean
figure,plot([1 3 5 7 9], Pe_dc(:,4,2),'-*',[1 3 5 7 9], Pe_sc(:,4,2),'-+',[1 3 5 7 9], Pe_egc(:,4,2),'-*',[1 3 5 7 9], Pe_mrc(:,4,2),'-+')
set(gca, 'YScale', 'log')
title('BER of SC & MRC & EGC & DC (Ricean)');
legend('Direct Combining','Selective Combining','Equal Gain Combinig','Maximal Ratio Combining');
xlabel('SNR (dB)');
ylabel('Bit error rate');
% Comparison between Rayleigh and Ricean
figure,plot([1 3 5 7 9], Pe_egc(:,4,1),'-*',[1 3 5 7 9], Pe_egc(:,4,2),'-+')
set(gca, 'YScale', 'log')
title('BER of Rayleigh and Ricean');
legend('Rayleigh','Ricean');
xlabel('SNR (dB)');
ylabel('Bit error rate');