#calculate VSWR
#chapter-7 page 278 example 7.1
import math
a=4.##Length of Waveguide in cm
b=2.5##breadth Waveguide in cm
f=10.**10.##Frequency in Hz
x=0.1##distance between twice minimum power points in cm
c=3.*10.**10.##Velocity of Light in cm/sec
#CALCULATION
wc=2.*a##Cutoff wavelength in TE10 mode in cms
w0=(c/f)##Free space wavelength in cms
wg=(w0/math.sqrt(1-(w0/wc)**2.))##Guide wavelength in cms
S=(wg/(x*(math.pi)))##Voltage Standing Wave Ratio(VSWR) for double minimum method
#OUTPUT
print '%s %.1f' %('\nFor double minimum method, Voltage Standing Wave Ratio(VSWR) is S=',S)#
#calculate reflected power and VSWR
#chapter-7 page 279 example 7.2
import math
x=3##O/P incident power from first directional coupler in mW
y=0.1##O/P reflected power from second directional coupler in mW
#CALCULATION
Pi=x*100.##Incident Power in mW
Pr=y*100.##Reflected Power in mW
p=math.sqrt(Pr/Pi)##Reflection Coefficient
S=((1+p)/(1-p))##Voltage Standing Wave Ratio(VSWR)
#OUTPUT
print '%s %.f %s %s %.2f' %('\nReflected Power is Pr=',Pr,'mW','\nVoltage Standing Wave Ratio(VSWR)in the main waveguide is S=',S)#
#calculate VSWR
import math
#Variable declaration
Pr = 0.15*10**-3 #reflected power(W)
Pi = 2.5*10**-3 #incident power(W)
#Calculations
rho = math.sqrt(Pr/Pi)
s = (1+rho)/(1-rho)
#Results
print "VSWR =",round(s,2)
#calculate reflected power
import math
#Variable declaration
s = 2. #VSWR
Pi = 4.5*10**-3*1000 #incident power(W)
c = 30 #couplers
#Calculations
#s = (1+rho)/(1-rho)
rho = (s-1)/(s+1)
Pr = rho**2*Pi
#Results
print "Reflected power =",Pr,"W"