from __future__ import division
from math import exp, log10, pi, sqrt, log
#Given,
z0=50 #ohm
t=0.001 #mm
b=0.32 #cm
er=2.20
tandel= 0.0005
rs=0.026 #ohm
f=10e9 #Hz
c=3e8 #m/sec
p=sqrt(er)*z0
#As p<120
w=b*(((30*pi)/p)-0.441)
print 'Width %0.3f'%w,'cm'
#Attenuation
k=((2*pi*f*sqrt(er))/c)
ad=(k*tandel)/2
#and
A=1+((2*w)/(b-t))+(((b+t)/((b-t)*pi))*log(((2*b)-t)/t))
#Hence
ac=(2.7e-3*rs*er*z0*A)/(30*pi*(b-t)*1e-2)
#Total attenution
a=ad+ac
#Total attenution in db
x=exp(a)
alp=20*log10(x) #db/m
#Total attenution in db/lambda:
lam=c/(sqrt(er)*f)
lamm=lam*1e2
alph=alp/lamm
print 'Total attenution in db/lambda: %0.3f'%alph, 'db/lambda'
#Answer in book for alph is given as 0.856 but it should be 0.0856 as value of f is taken as 10e10 but it should be 10e9
#Given,
er=9.7
h=0.25 #mm
w=0.25 #mm
f=5e9 #Hz
c=3e8 #m/s
#(i) Dielectric constant
dc=((er+1)/2)+(((er-1)/2)*(1/sqrt(1+12*h/w)))
print 'Dielectric constant: %0.3f'%dc
#(ii) Phase constant
lam0=c/f
pc=sqrt(dc)*(2*pi/lam0)
print 'Phase constant: %0.3f'%(pc/100),'rad/m'
#(iii) Microstrip wavelength
lams=lam0/sqrt(dc)
print 'Microstrip wavelength: %0.3f'%(lams*100),'cm'
#(iv) Capacitance per unit length
e0=8.854e-12
cap=(2*pi*e0)/log((8*h/w)-(w/(4*h)))
print 'Capacitance per unit length: %0.3e'%cap, 'F/cm'
#(v) Characterstic Impedance
ci=(60/sqrt(dc))*log((8*h/w)+(w/(4*h)))
print 'Characterstic impedance: %0.3f'%ci, 'ohm'
#Given,
er=5.23
w=10 #mils
t=2.8 #mils
h=7 #mils
dc=((er+1)/2)+(((er-1)/2)*(1/sqrt(1+12*h/w)))
print 'Dielectric constant: %0.3f'%dc
#As w/h>1
ci=(120*pi)/(sqrt(dc)*((w/h)+1.393+0.667*log((w/h)+1.444)))
print 'Characterstic impedance: %0.3f'%ci, 'ohm'
#Given,
q=2.5
dh=1.58
er=9
f=10
c=3e8
erff=((er+1)/2)+(((er-1)/2)*((1+(12/q))**(-1/2)))
vp=(c/sqrt(erff))*erff
fe1=c/(sqrt(vp)*2*dh*q)
if f<fe1:
print 'Strip supports TEM mode only'
else:
print 'Strip does not support TEM mode only'
#Given,
er=9.7
h=0.5 #mm
w=0.5 #mm
lt=2e-4
t=0.02 #mm
f=5e9 #Hz
fg=5 #HZ
c=3e8
rs=8.22e-3*sqrt(fg)
#(i) Dielectric constant
dc=((er+1)/2)+(((er-1)/2)*(1/sqrt(1+12*h/w)))
print 'Dielectric constant: %0.3f'%dc
#(ii) Characterstic Impedance
ci=(60/sqrt(dc))*log((8*h/w)+(w/(4*h)))
print 'Characterstic impedance: %0.3f'%ci,'ohm'
#(iii) Dielectric attenuation
lam0=c/f
alphd=(pi/lam0)*(er/sqrt(dc))*((dc-1)/(er-1))*lt
print 'Dielectric attenuation: %0.3f'%alphd,'Np/m'
#Conductor attenuation
r1=(0.94+(0.132*(w/h))-(0.0062*((w/h)**2)))*((1/pi)+(1/(pi**2))*log((4*pi*w)/t))*(rs/(w*1e-3))
r1m=r1*1e-2
r2=(w/h)/(((w/h)+5.8+(0.03*(h/w))))*(rs/(w*1e-3))
r2m=r2*1e-2
alphc=(r1+r2)/(2*ci)
print 'Conductor attenuation: %0.3f'%alphc,'Np/m'
#(iv) Total attenuation
A=alphc+alphd
Adb=A*8.686*1e-2
print 'Total attenuation: %0.3f'%Adb,'db/cm'
#Given
sig=5.8e7
f=10 #GHz
h=0.12e-2 #m
q=62.8*h*sqrt(f*sig)
print 'conductor Q of the stripline:' ,round(q)
#Given
Er=6
h=4e-3 #m
#(i) W for Z0=50W
Z0=50 #W
W=(120*pi*h)/(sqrt(Er)*Z0)
print 'Required Width: %0.3f'%(W*1000), 'mm'
#(ii)Stripline capacitance
E0=8.854e-12
C=(E0*Er*W)/h
print 'Stripline capacitance: %0.3f'%(C*10**12),'pF/m'
#(iii)Stripline inductance
Mu0=4*pi*10e-7
L=(Mu0*h)/W
print 'Stripline inductance: %0.3f'%(L*10**5),' muH/m'
#(iv)Phase velocity
c=3e8
vp=c/sqrt(Er)
print 'Phase velocity',vp, 'm/s'
#Given
cl=3e8 #m/s
f=5e9 #Hz
Er=9
C=-10 #db
Z0=50 #ohm
#Length
L=(cl/f)/(4*sqrt(Er))
print 'Length:' ,L*100,'cm'
#Coupling coefficient
C0=10**(C/20)
print 'Coupling coefficient: %0.3f'%C0
#Even and odd mode impedance
Z0e=(Z0*sqrt(1+C0))/sqrt(1-C0)
print 'Even mode impedance: %0.3f'%Z0e,'ohm'
Z0o=(Z0*sqrt(1-C0))/sqrt(1+C0)
print 'Odd mode impedance: %0.3f'%Z0o,'ohm'
#Given
Z0=50 #ohm
C=3 #db
#Line impedance
Z01sqr=(1-(10**(C/-10)))
Z01=sqrt(Z0*Z0*Z01sqr)
print 'Z01: %0.3f'%Z01, 'ohm'
Z02=Z01/(sqrt(1-(1/sqrt(2))**2))
print 'Z02:' ,round(Z02),'ohm'
#Given
W=6 #m
s=2.2 #m
b=4.8 #m
Er=2.2
#Even and odd mode impedance
Z0e=((120*pi)*(b-s))/(2*sqrt(Er)*W)
print 'Even mode impedance: %0.3f'%Z0e,'ohm'
Z0o=(Z0e*s)/b
print 'Odd mode impedance: %0.3f'%Z0o,'ohm'
#Mid band coupling
x=(Z0e-Z0o)/(Z0e+Z0o)
C=-20*log10(x)
print 'Mid band coupling: %0.3f'%C,'db'
#Answer in book for C is given as 54.2 but it should be 8.60
#Given
Er=6
d=3e-3 #m
Z0=50 #ohm
E0=8.854e-12 #F/m
Mu0=4*pi*10e-7 #H/m
#(i) W
W=(377*d)/(sqrt(Er)*Z0)
print 'Required Width: %0.3f'%(W*1000),'mm'
#(ii)Stripline capacitance
C=(E0*Er*W)/d
print 'Stripline capacitance: %0.3f'%(C*10**12),'pF/m'
#(iii)Stripline inductance
L=(Mu0*d)/W
print 'Stripline inductance: %0.3f'%(L*10**6), 'muH/m'
#(iv)Phase velocity
c=3e8
vp=c/sqrt(Er)
print 'Phase velocity' ,vp,'m/s'
#Given
Er=2.56
w=25 #mils
t=14 #mils
d=70 #mils
E0=8.854e-12 #F/m
#(i) K factor
K=1/(1-(t/d))
print 'K factor:' ,K
#(ii) Fringe capacitance
C=((E0*Er)*(2*K*log(K+1)-(K-1)*log(K**2-1)))/pi
print 'Fringe capacitance: %0.3f'%(C*10**12), 'pF/m'
#(iii) Charecteristic Impedance
X=1/(((w*K)/d)+(C/(E0*Er)))
Z0=(94.15*X)/sqrt(Er)
print 'Charecteristic Impedance: %0.3f'%Z0,'ohm'
#Answer in book for Z0 is given as 50.29 but it should be 51.7
#Given
Z0=50 #ohm
#Sincr ratio of power is 2:3
x1=5/2
y1=5/3
#Output Impedance
Z1=x1*Z0
Z2=y1*Z0
print 'Output Impedance 1:',Z1,'ohm'
print 'Output Impedance 2: %0.3f'%Z2,'ohm'
#Input Impedance
Zin=[((Z2*2*Z2)/3)/((Z2+(2*Z2)/3))]
#Looking into Z1, Z2 is || to Z0
A1=(Z2*Z0)/(Z2+Z0)
#Looking into Z, Z2 is || to Z0
A2=(Z1*Z0)/(Z1+Z0)
#Reflection Coeffcients
R1=(A1-Z1)/(A1+Z1)
R2=(A2-Z2)/(A2+Z2)
print 'Reflection Coeffcients:\n', R1,'\n',R2,