import math
#variable declaration
bon = 1.0 #signal on level
boff = 0.0 #signal off level
sigma_on = 1.0 #variance sigma-on level
sigma_off = 1.0 #variance sigma-on level
#calculation
Q = (bon - boff)/(sigma_on + sigma_off) #parameter value
Vth = bon-Q*sigma_on #optimum decision threshold
#result
print "Q parameter value = " ,Q
print "Optimum decision threshold Vth = ",Vth
import math
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
from scipy import special
%matplotlib inline
#variable declaration
Q = 6.0 #parameter value from figure
#calculation
Pe = (1.0/2.0)*(1-math.erf(Q/math.sqrt(2.0))) #probability of error
S_N_dB = 10*math.log10(2*Q) #signal to naoise ratio (dB)
#result
print "Probability of error = " ,round(Pe,10)
print "Signal to naoise ratio =",round(S_N_dB,1),"dB"
#plot
q1=arange(0.0, 8.0, 0.5)
Pe1 = (1.0/2.0)*(1-sp.special.erf(q1/sqrt(2.0)))
plot(-q1+8,-Pe1)
ylabel('BER (Pe)')
xlabel('factor Q')
title('Plot of BER (Pe) versus the factor Q')
text(6,-0.3,'Q=5.99 for')
text(6,-0.35,' Pe=10^-9')
import math
#variable declaration
s_n=8.5 #signal-to-noise ratio
s_n_db=18.6 #signal-to-noise ratio (dB)
tele_rate=1.544 #telephone rate
v_by_sig=12.0 #peak signal-to-rms-noise ratio
v_by_sig_db=21.6 #peak signal-to-rms-noise ratio(dB)
#calculation
Pe1=(1.0/math.sqrt(2.0*math.pi))*(math.exp(-((s_n**2.0)/8.0))/(s_n/2.0)) #Probability of error 1
q=v_by_sig/2 #parameter value
ber=(1.0/2.0)*(1.0-math.erf(q/math.sqrt(2.0))) #bit error rate or Probability of error 2
#result
print "Probability of error for signal-to-noise ratio 8.5 = ", round(Pe1,5)
print "Probability of error for peak signal-to-rms-noise ratio 12.0 = ", round(ber,10)
import math
#variable declaration
v_by_sig=13.0 #peak signal-to-rms-noise ratio for SONET
v_by_sig_db=22.3 #peak signal-to-rms-noise ratio(dB) for SONET
#calculation
q=v_by_sig /2 #parameter value
ber=(1.0/(2.0*4.0))*(1.0-math.erf(q/math.sqrt(2.0))) #bit error rate or Probability of error
#result
print "Probability of error for peak signal-to-rms-noise ratio 13.0 = ", round(ber,11), "OR",round(ber/10,12)
import math
#variable declaration
h = 6.625*10**-34 #planks constant(J*s)
C = 3*10**8 #freespace velocity(m/s)
B = 10**6 #data rate(Mb/s)
Lambda = 850*10**-9 #Wavelength (m)
#calculation
tuo = 2.0/B
E = 20.7*h*C/Lambda #Energy of incident photon
Pi = E/tuo #Minimum incident optical power(W)
Pi_db = 10.0*(math.log10(Pi))-(-40) #optical power level with reference 1mW = -40dBm
#result
print "Minimum incident optical power = ",round(Pi*10**13,2),"pW"
print "Optical power level with reference 1mW = ",round(Pi_db,1),"dBm"