-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComputeBER_Numerically_1.m
73 lines (58 loc) · 2.17 KB
/
ComputeBER_Numerically_1.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
function BER = ComputeBER_Numerically_1(SNR_dB)
%Numerically.
Eb = 1;
a = 1;
Es = a^2 * Eb;
Ts_symbol = 1e-6;
signal_length = 1000;
%Sampling parameters
Fs = 20e6;
Ts = 1 / Fs;
%According to Relative Frequency Theorem, Many trials are required in order to converge to the real probabilty of error.
num_iterations = 50;
BER = zeros(size(SNR_dB));
SNR_dim = 10.^(SNR_dB/10);
%Triangular Pulse
t = 0 : Ts : Ts_symbol;
p = abs (2 * (t / Ts_symbol - floor ( t / Ts_symbol + 0.5 )));
p = p ./ sqrt(sum(p.^2) * (1 / Fs));
%Matched Pulse: Triangular Pulse
g = abs (2 * ((Ts_symbol-t) / Ts_symbol - floor ( (Ts_symbol-t) / Ts_symbol + 0.5 )));
g = g ./ sqrt(sum(g.^2) * (1 / Fs));
%LPF
LPF = 1; %Unlimited Bandwidth in Frequency is Delta in Time.
for i = 1 : length(SNR_dB)
accumulated_BER = 0; %Required for averaging.
No = Fs * Es / SNR_dim(i); %WTF
for j = 1 : num_iterations
num_bit_errors = 0;
%Delta Stream
t = 0 : Ts : Ts_symbol * (signal_length - 1);
deltas = zeros(size(t));
deltas(1 : Fs * Ts_symbol : end) = randi([1 2], 1, signal_length);
deltas(deltas == 2) = -1;
%PROCESS OF TRANSIMITION AND RECEPTION
%Pulse Convolution
s = conv(deltas, p, 'same');
%LPF Convolution
s_LPF = conv(s, LPF, 'same');
%Noise Addition
N = sqrt(No/2) * randn(1,length(s_LPF)); %Generate AWGN
r = s_LPF + N; %Received Signal
%Matched Filter Convolution
X = conv(r, g, 'same');
%Decision Making
sampling_deltas = zeros(size(t));
sampling_deltas(1 : Fs * Ts_symbol : end) = 1;
X_sampled = sampling_deltas .* X;
for k=1:length(X_sampled)
if ((X_sampled(k) > 0 && deltas(k) < 0)||(X_sampled(k) < 0 && deltas(k) > 0))
num_bit_errors=num_bit_errors+1;
end
end
avg_bit_error = num_bit_errors / signal_length;
accumulated_BER = accumulated_BER + avg_bit_error;
end
BER(i) = accumulated_BER / num_iterations;
end
end