-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAWGN.m
37 lines (31 loc) · 888 Bytes
/
AWGN.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
clc;
clear all;
close all;
N = 10^6; % Number of Samples
BER = []; % Array to store BER for each SNR
for SNRdB = 0:1:10 % SNR in dB
SNR = 10^(SNRdB/10); % SNR
input = randi([0,1],1,N); % Randomly generating 0 and 1
data = 2*input - 1; % Converting data to -1 and 1
error = 0;
for i = 1:N
n = sqrt(1/2)*randn(1,1); % Distribution of noise N(0,1/2)
y = (sqrt(SNR)*data(i)) + n; % Received Signal
if(y > 0)
received = 1;
else
received = -1;
end
error = error + nnz(received - data(i));
end
BER = [BER error/N];
end
SNRdB = 0:1:10;
SNR = 10.^(SNRdB/10); % SNR
BER_theo = qfunc(sqrt(2*SNR)); % Theoretical BER
semilogy(SNRdB,BER);
hold on;
semilogy(SNRdB,BER_theo,'+');
legend('Experimental','Theoretical');
ylabel('Bit Error Rate');
xlabel('SNR in dB');