import numpy as np import matplotlib.pyplot as plt # x is our message x = np.random.binomial(size=pow(10, 6), n=1, p= 0.5) # pe is the error probability of noise pe = np.linspace(0, 0.5, num=11) # bsc is the error matrix bsc = np.zeros(shape=(11,pow(10, 6))) for i in range(11): bsc[i] = np.random.binomial(size=pow(10, 6), n=1, p = pe[i]) y = np.zeros(shape=(11,pow(10, 6))) # below we compare the error matrix and our message with xor and get the output for i in range(11): for j in range(pow(10, 6)): if np.logical_xor(bsc[i,j],x[j]) == True: y[i,j]=1 else: y[i,j]=0 error = np.zeros(shape=(11,pow(10, 6))) # in this part we compare message and the output for i in range(11): for j in range(pow(10, 6)): if np.logical_xor(y[i,j],x[j]) == True: error[i,j]=1 else: error[i,j]=0 # calculating error probabilities for different noise error rates ps = np.zeros(shape=(11)) for i in range(11): ps[i] = np.sum(error[i])/pow(10, 6) # here plotting plt.plot(pe,ps) plt.ylabel('Ps') plt.xlabel('Pe') plt.show()