import math
from __future__ import division
#initialisation of variables
Xx=-30; #crosstalk in dB
L=0.3; #typical value
N=5; #no. of switches Nb+Nc
#CALCULATIONS
SXR=Xx-L*(N)-10*math.log10(5*(10**(-L*N/10))/N); #Signal power to noise power in dB
#RESULTS
print"Minimum and maximum SXR values=",round(SXR,5),"dB";
import math
from __future__ import division
#initialisation of variables
PB=40; #power budget in dB
x=-30; #crosstalk in dB assumed
N=4; #no. of switches
Lin=1; #insertion loss of in dB
Linw=Lin*N; #worst case insertion loss of in dB
Lc=2; #worst case connector loss in dB
#CALCULATIONS
L=Linw+2*Lc; #total power lost in the worst case signal path in dB
Power_margin=PB-L; #power margin in dB
K=0;
for i in range (0,4):
K=K+(((-1)**(i+1))*(10**(-x/10))**(i+1));
SbyN=10*math.log10(K); #Signal power to noise power in dB
#RESULTS
print"Signal power to noise power =",round(SbyN,5),"dB";
print"Power Margin =",round(Power_margin,5),"dB";
print"The Textbook answer is wrong";