shelling (owner)

Revisions

gist: 226647 Download_button fork
public
Public Clone URL: git://gist.github.com/226647.git
Embed All Files: show embed
em_theory_assignment3.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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()
layer_helper.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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()