import math
from __future__ import division
#initialisation of variables
BW=7; #bandwidth in MHz
SNR=60; #signal to noise ratio in dB
Pin=0; #Launched power in dBm
Trise_source=20; #risetime at source LED in ns
delta_lambda=20; #spectra width in nm
lambda1=850; #operating wavelength in nm
c=2.998*10**5; #velocity of light in Km/sec
R=0.3; #Detector PIN FET responsivity in A/W
Cdiode=3; #diode capacitance in pf
trise_detector=1; #risetime at detector in ns
S=-30; #sensitivity in dbm
Lsplice=0.2; #splice loss in dB/connector
NA=0.2; #numerical aperture for GI/MM
n1=1.46; #refractive index of core
A=2; #attenuation in dB/Km
Ls=3; #loss due to source in dB
Ld=1; #loss due to detector in dB
Psm=5; #system margin in dB
c=3*10**8; #velocity of light in m/s
#CALCULATIONS
Available_power=Pin-S; #available power in dB
Total_loss=Ls+Ld+Psm;
Power_left=Available_power-Total_loss; #power left in dB
L=(Power_left+Lsplice)/(Lsplice/2+2);
tmod=L*10**3*(NA**2)/(2*c*n1); #modal dispersion in s
Bit_rate=1/tmod; #bit rate in bps
#RESULTS
print"Maximum permissible link length is =",round(L,5),"Km";
print"Maximum permissible bit rate is =",round(Bit_rate/10**6,5),"Mbps"; #division by 10^6 to convert the unit from bps to Mbps
print"the answer is different because of rounding off ";
import math
from __future__ import division
#initialisation of variables
BW=7; #bandwidth in MHz
SNR=60; #signal to noise ratio in dB
Pin=0; #Launched power in dBm
Trise_source=4; #risetime at source LED in ns
delta_lambda=1; #spectra width in nm
lambda1=1300; #operating wavelength in nm
c=2.998*10**5; #velocity of light in Km/sec
R=0.3; #Detector PIN FET responsivity in A/W
Cdiode=3; #diode capacitance in pf
trise_detector=5; #risetime at detector in ns
F=2.1; #amplifier noise figure in dB
Camp=2; #amplifier capacitance in pf
L=2; #minimum link length in Km
Lsplice=0.5; #splice loss in dB/connector
NA=0.22; #numerical aperture for GI/MM
BWGI=600; #GI/MM fiber bandwidth in MHz F3dB_optical
Te=630; #temperate in Kelvin
K=(1.38064852 *10)-23; #boltzman constant in m2 kg s-2 K-1
#CALCULATIONS
Rload=1/(2*3.14*(Cdiode+Camp)*BW)*10**6; #maximum load resistance in ohm Actual value
Rload1=4300; #approximated value in ohm
BWRx=1/(2*3.14*(Cdiode+Camp)*Rload1); #receiver BW in Hz
SbyN=10**(SNR/10); #SNR in normal scale
Pmin1=math.log10(math.sqrt((SbyN*4*(-K)*Te*BW)/(0.5*Rload1*R**2)))*10; #input power in W
L1=Pmin1/0.2; #power budget limited link length in Km
Trise_required=(0.35/BW)*10**3; #Bandwith budgetting rise time required is rise time required in ns//multiplication by 10^3 to convert msec to ns
Trise_receiver=2.19*Rload1*(Cdiode+Camp)*10**-3; #rise time of receiver in ns//multiplication by 10^3 to convert msec to ns
Trise_fiber=math.sqrt(Trise_required**2-Trise_receiver**2-Trise_source**2); #fiber dispersion in ns
#for GI
f3dB_electrical=0.71*BWGI; #3dB elctrical BW in MHzKm
t_intra_modal=1; #intra modal dispersion in ns/Km
t_inter_modal=3; #intermodal dispersion in ns/Km
t_fiber_GI=math.sqrt(t_intra_modal**2+t_inter_modal**2); #rise time of fiber in ns/Km
L2=Trise_fiber/t_fiber_GI; #link length in Km
#RESULTS
print"Maximum permissible link length is =",round(L1,5),"fKm";
print"Maximum permissible link length for GI is =",round(L2,5),"fKm";