Skip to content

Instantly share code, notes, and snippets.

@shelling
Created November 5, 2009 02:29
Show Gist options
  • Select an option

  • Save shelling/226647 to your computer and use it in GitHub Desktop.

Select an option

Save shelling/226647 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
sys.path.append("./lib")
from layer_helper import *
from pylab import *
from numpy import *
layers = Layer({
"eps" : 2.0,
"mu" : 1.0,
"l_coef" : 4.0,
})
layers.next = Layer({
"eps" : 4.0,
"mu" : 1.0,
"l_coef" : 3.0,
})
layers.next.next = Layer({
"eps" : 2.0,
"mu" : 1.0,
"l_coef" : 4.0,
})
angle = arange(0, 90, 0.1)
plot(angle, map( (lambda x : gamma_h(layers, x*math.pi/180)), angle))
plot(angle, map( (lambda x : gamma_v(layers, x*math.pi/180)), angle ))
show()
plot(angle, map( (lambda x : tou_h(layers, x*math.pi/180)), angle))
plot(angle, map( (lambda x : tou_v(layers, x*math.pi/180)), angle ))
show()
from pylab import *
from math import *
def find_thita_t1(thita):
return asin( sqrt(1/2) * sin(thita) )
def gamma_h( layer, thita ):
l1_thita = find_thita_t1(thita)
z_ih = 377.0/cos(thita)
z_th = 377.0/cos(thita)
layer.set_thita(l1_thita)
list = layer.total_abcd_matrix().tolist()
ita1 = list[0][0] + list[0][1]/z_th
ita2 = z_ih * ( list[1][0] + list[1][1]/z_th )
return abs( ( ita1 - ita2 ) / ( ita1 + ita2 ) )
def gamma_v( layer, thita):
l1_thita = find_thita_t1(thita)
z_iv = 377.0/cos(thita)
z_tv = 377.0/cos(thita)
layer.set_thita(l1_thita)
list = layer.total_abcd_matrix().tolist()
ita1 = list[1][0] * z_tv + list[1][1]
ita2 = ( list[0][0] * z_tv + list[0][1] ) / z_iv
return abs( ( ita1 - ita2 ) / ( ita1 + ita2 ) )
def tou_h(self, thita):
z_ih = 377.0/cos(thita)
z_th = 377.0/cos(thita)
layer.set_thita(l1_thita)
list = layer.total_abcd_matrix().tolist()
ita1 = list[0][0] + list[0][1]/z_th
ita2 = z_ih * ( list[1][0] + list[1][1]/z_th )
return abs( 2 / ( ita1 + ita2 ) )
def tou_v(self, thita):
z_iv = 377.0/cos(thita)
z_tv = 377.0/cos(thita)
layer.set_thita(l1_thita)
list = layer.total_abcd_matrix().tolist()
ita1 = list[1][0] * z_tv + list[1][1]
ita2 = ( list[0][0] * z_tv + list[0][1] ) / z_iv
return abs( ( 2 / ( ita1 + ita2 ) )
class Layer():
def __init__(self, params = { "next" : None } ):
self.eps = params["eps"]
self.mu = params["mu"]
self.l_coef = params["l_coef"]
self.next = None
def set_thita(self, thita):
self.thita = thita
if self.next:
self.next.set_thita( self.thita_out() )
return None
def thita_out(self):
next_eps = self.next.eps if self.next else 1.0
return asin( sqrt( self.eps / next_eps ) * sin( self.thita ) )
def impedance(self):
return 377.0 * sqrt( self.mu / self.eps )/cos(self.thita)
def beta_l(self):
return 2 * pi * cos(self.thita) / self.l_coef
def abcd_matrix(self):
a = cos( self.beta_l() )
b = 1j * self.impedance() * sin( self.beta_l() )
c = 1j * sin( self.beta_l() ) / self.impedance()
d = cos( self.beta_l() )
return matrix([ [a, b], [c, d] ])
def total_abcd_matrix(self):
if self.next:
return self.abcd_matrix() * self.next.total_abcd_matrix()
else:
return self.abcd_matrix()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment