-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBER_computation.m
More file actions
119 lines (78 loc) · 3.13 KB
/
BER_computation.m
File metadata and controls
119 lines (78 loc) · 3.13 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
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
%% BER computation in function of Eb_N0
Eb_N0 = 14;%db
Eb_N0_lin = 10^(Eb_N0/10);
fprintf('\n\n\n\n\n===== WITH Eb/N0 = %.2f dB =====\n', Eb_N0);
fprintf('\n-------------------\n')
fprintf('AWGN BPSK and QPSK, Pb = %d \n\n', 0.5*exp(-Eb_N0_lin));
fprintf('AWGN BFSK, Pb = %d \n', 0.5*exp(-0.5*Eb_N0_lin));
fprintf('-------------------\n')
fprintf('Rayleigh BPSK, Pb = %d \n\n', 0.5*(1-sqrt(Eb_N0_lin/(1 + Eb_N0_lin))));
fprintf('Rayleigh QPSK, Pb = %d \n\n', 1/(2+2*Eb_N0_lin));
fprintf('Rayleigh BFSK, Pb = %d \n\n',1/(2+Eb_N0_lin));
%% Eb_N0 in function of BER
Pb = 1e-6;
fprintf('\n\n===== WITH Pb = %d =====\n\n', Pb);
a = -log(2*Pb);
b = dec_to_db(a);
fprintf('AWGN BPSK,\nEb_N0 = %.3f [lin]\nEb_N0 = %.3f [db]\n\n', a, b);
a = -2*log(2*Pb);
b = dec_to_db(a);
fprintf('AWGN BFSK,\nEb_N0 = %.3f [lin]\nEb_N0 = %.3f [db]\n\n', a, b);
inter = (1-2*Pb)^2;
a = inter/(1-inter);
b = dec_to_db(a);
fprintf('Rayleigh BPSK,\nEb_N0 = %.3f [lin]\nEb_N0 = %.3f [db]\n\n', a, b);
a = (1-2*Pb)/(2*Pb);
b = dec_to_db(a);
fprintf('Rayleigh QPSK,\nEb_N0 = %.3f [lin]\nEb_N0 = %.3f [db]\n\n', a, b);
a = (1-2*Pb)/(Pb);
b = dec_to_db(a);
fprintf('Rayleigh BFSK,\nEb_N0 = %.3f [lin]\nEb_N0 = %.3f [db]\n\n', a, b);
%% CODED : EB_N0 in function of BER
fprintf("\n\n\n\n\n\n\n\n\n\n\n\n=======================\n")
Pb = 1e-8;
fprintf("Pb = %.2d\n", Pb);
% We need 2 coded bits to transmit 1 bit of pure information
% => Hence Eb will correspond to 2Ec = Ec/0.5
r = 0.5;
fprintf("coding rate (#InputBits / #OutputBits) = %.2f\n", r);
% k = nb of bits per symbol,
% k=1 for BPSK, k=2 for QPSK...
% The formulas for Ec given below never take into consideration the number
% of bits per symbol ! In other words, they always give the EC considering BPSK.
% In theory (and for a 'general' modulation scheme), we should indeed
% divide Ec by 'k'. But as we consider only BPSK, QPSK and BFSK, and as
% QPSK can be modeled as BPSK, 'k' is always considered to be 1 (cf homework 3)
D = compute_D(Pb);
fprintf("\nThe 3-term approximation:\nD = %.4f\n", D );
fprintf("\n\n------- SOFT PART -------\n\n");
% Soft AWGN
Ec_N0 = -log(D);
fprintf("AWGN BPSK soft decision :\n");
fprintf("\tEc_N0 = %.3f [lin]\n", Ec_N0);
fprintf("\tEb_N0 = %.3f [lin]\n", Ec_N0/r);
fprintf("\tEb_N0 = %.2f [db]\n", dec_to_db(Ec_N0/r));
% Soft Rayleigh
Ec_N0 = (1-D)/D;
fprintf("\nRAYLEIGH BPSK soft decision:\n");
fprintf("\tEc_N0 = %.3f [lin]\n", Ec_N0);
fprintf("\tEb_N0 = %.3f [lin]\n", Ec_N0/r);
fprintf("\tEb_N0 = %.2f [dB]\n", dec_to_db(Ec_N0/r));
% -------- Now for hard decisions : ---------
delta = (16-4*4*D*D);
hard_eps = (-4 + sqrt(delta)) / (-8);
fprintf("\n\n------- HARD PART -------\n");
fprintf("hard eps = %f\n\n", hard_eps);
% Hard AWGN
Ec_N0 = -log(2*hard_eps);
fprintf("AWGN BPSK hard decision :\n");
fprintf("\tEc_N0 = %.3f [lin]\n", Ec_N0);
fprintf("\tEb_N0 = %.3f [lin]\n", Ec_N0/r);
fprintf("\tEb_N0 = %.2f [db]\n", dec_to_db(Ec_N0/r));
% Hard Rayleigh
temp = (1-2*hard_eps)^2;
Ec_N0 = temp/(1-temp);
fprintf("\nRAYLEIGH BPSK hard decision:\n");
fprintf("\tEc_N0 = %.3f [lin]\n", Ec_N0);
fprintf("\tEb_N0 = %.3f [lin]\n", Ec_N0/r);
fprintf("\tEb_N0 = %.2f [dB]\n", dec_to_db(Ec_N0/r));