Wednesday, January 1, 2020

probability error

Probability Error

from __future__ import division
from numpy import ones,arange,cos,sin,pi
##matplotlib inline
from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show,legend,grid
from scipy.special import erfc
from math import log10,sqrt,exp
#Comparison of Symbol Error Probability
#of Different Digital Transmission System
#Eb =  Energy of the bit  No = Noise Spectral Density
Eb_No =[18,0.3162278]
x = arange(Eb_No[1],1/100+Eb_No[0],1./100)
x_dB = [10*log10(xx) for xx in x]
Pe_BPSK=ones(len(x))
Pe_BFSK=ones(len(x))
Pe_DPSK=ones(len(x))
Pe_NFSK=ones(len(x))
Pe_QPSK=ones(len(x))
for i in range(0,len(x)):
  #Error Probability of Coherent BPSK
  Pe_BPSK[i]= (1/2)*erfc(sqrt(x[i]))#
  #Error Probability of Coherent BFSK
  Pe_BFSK[i]= (1/2)*erfc(sqrt(x[i]/2))#
  #Error Probability Non-Coherent PSK = DPSK
  Pe_DPSK[i]= (1/2)*exp(-x[i])#
  #Error Probability Non-Coherent FSK
  Pe_NFSK[i]= (1/2)*exp(-(x[i]/2))#
  #Error Probability of QPSK
  Pe_QPSK[i]= erfc(sqrt(x[i]))-((1/4)*(erfc(sqrt(x[i]))**2))
plot(x_dB,Pe_BPSK)
plot(x_dB,Pe_BFSK)
plot(x_dB,Pe_NFSK)
plot(x_dB,Pe_QPSK)
xlabel('Eb/No in dB ---->')
ylabel('Probability of Error Pe--->')
title('Comparison of Noise Performance of different PSK & FSK Scheme')
legend(['BPSK','BFSK','DPSK','Non-Coherent FSK','QPSK'])
grid()
show()


Rayleigh Fading channel


from numpy import ones,arange,cos,sin,pi
from math import log10,sqrt,exp
import random
import matplotlib.pyplot as plt
N = 10000
EbNodB_range = range(0, 11)
itr = len(EbNodB_range)
ber = [None]*itr
tx_symbol = 0
noise = 0
ch_coeff = 0
rx_symbol = 0
det_symbol = 0
for n in range (0, itr):
     EbNodB = EbNodB_range[n] 
     EbNo=10**(EbNodB/10.0)
     noise_std = 1/sqrt(2*EbNo)
     noise_mean = 0
     no_errors = 0
     for m in range (0, N):
      tx_symbol = 2*random.randint(0,1)-1
      noise = random.gauss(noise_mean, noise_std)
      ch_coeff = sqrt(random.gauss(0,1)**2+random.gauss(0,1)**2)/sqrt(2)
      rx_symbol = tx_symbol*ch_coeff + noise
      det_symbol = 2 * (rx_symbol >= 0) - 1
      no_errors += 1*(tx_symbol != det_symbol) 
      ber[n] = no_errors / N
print("EbNodB:", EbNodB)
print ("Numbder of errors:", no_errors)
print ("Error probability:", ber[n])
plt.plot(EbNodB_range, ber, 'bo-')
plt.axis([0, 10, 0, 0.1])
#plt.xscale('linear')
#plt.yscale('log')
plt.xlabel('EbNo(dB)')
plt.ylabel('BER')
#plt.grid(True)
plt.title('BPSK Modulation')
plt.show()

No comments:

Post a Comment

qpsk

from numpy import ones,arange,cos,sin,pi from matplotlib.pyplot import plot,subplot,title,xlabel,ylabel,show M =4# i = range(0,M) t = a...