# Theoretical results $BER = Q(1/\sqrt{2SNR})$
import numpy as np
import math
= 10
SNRdB = 10**(SNRdB/10)
SNR = 1 # rate of the code
R
= 0.5*math.erfc(math.sqrt(SNR))
BER_th
# Implementing the simulation
= 1000000
N = np.random.randint(0,2,N)
msg = 2*msg - 1
s = s + np.sqrt(1/2/R/SNR)*np.random.randn(N)
r
= (r > 0).astype(int)
msg_cap
= np.mean(msg != msg_cap)
BER_sim
print(f"BER theoretical = {BER_th}", f"BER simulation = {BER_sim}", sep='\n')
BER theoretical = 3.872108215522037e-06
BER simulation = 5e-06