Created
November 11, 2009 12:13
-
-
Save shelling/231892 to your computer and use it in GitHub Desktop.
EM theory assignment 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from math import * | |
| from numpy import * | |
| class Layer: | |
| def __init__(self, params = {}): | |
| self.eps = params["eps"] | |
| self.l_coef = params["l_coef"] | |
| self.n = sqrt( self.eps ) | |
| def impedance(self, thita): | |
| return 377.0 * sqrt( 1.0 / self.eps ) | |
| def beta_l(self, thita): | |
| return sqrt(self.eps) * 2.0 * pi * cos(thita) / self.l_coef | |
| def abcd_matrix_hor(self, thita): | |
| a = cos(self.beta_l(thita)) | |
| b = 1j * (self.impedance(thita) / cos(thita)) * sin(self.beta_l(thita)) | |
| c = 1j * sin(self.beta_l(thita)) / (self.impedance(thita) / cos(thita)) | |
| d = cos(self.beta_l(thita)) | |
| return matrix([ [a, b], [c, d] ]) | |
| def abcd_matrix_ver(self, thita): | |
| a = cos(self.beta_l(thita)) | |
| b = 1j * (self.impedance(thita) * cos(thita)) * sin(self.beta_l(thita)) | |
| c = 1j * sin(self.beta_l(thita)) / (self.impedance(thita) * cos(thita)) | |
| d = cos(self.beta_l(thita)) | |
| return matrix([ [a, b], [c, d] ]) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| sys.path.extend(["lib"]) | |
| from em_helper import Layer | |
| import matplotlib as mpl | |
| mpl.use("Agg") | |
| import pylab | |
| import numpy | |
| import scipy | |
| import math | |
| t = numpy.arange(0,90,0.1) | |
| tt = t * math.pi / 180 | |
| layer_list = [] | |
| layer_list.append(Layer({ "eps": 2, "l_coef": 4 })) | |
| layer_list.append(Layer({ "eps": 4-1j, "l_coef": 3 })) | |
| layer_list.append(Layer({ "eps": 2, "l_coef": 4 })) | |
| gamma_h = [] | |
| tau_h = [] | |
| gamma_v = [] | |
| tau_v = [] | |
| for angle in tt: | |
| thita1 = math.asin(math.sin(angle) / layer_list[0].n) | |
| thita2 = math.asin(math.sin(angle) / layer_list[1].n) | |
| thita3 = math.asin(math.sin(angle) / layer_list[2].n) | |
| # prepare hor | |
| hor_matrix = layer_list[0].abcd_matrix_hor(thita1) * layer_list[1].abcd_matrix_hor(thita2) * layer_list[2].abcd_matrix_hor(thita3) | |
| [[a,b], [c,d]] = hor_matrix.tolist() | |
| ita1h = a + b / (377.0/math.cos(angle)) | |
| ita2h = (c + d / (377.0/math.cos(angle))) * (377.0/math.cos(angle)) | |
| gamma_h.append( abs(( ita1h - ita2h ) / ( ita1h + ita2h )) ) | |
| tau_h.append( abs( 2 / ( ita1h + ita2h ) ) ) | |
| ver_matrix = layer_list[0].abcd_matrix_ver(thita1) * layer_list[1].abcd_matrix_ver(thita2) * layer_list[2].abcd_matrix_ver(thita3) | |
| [[a, b], [c, d]] = ver_matrix.tolist() | |
| ita1v = c * (377.0 * math.cos(angle)) + d | |
| ita2v = ( a * (377.0 * math.cos(angle)) + b ) / (377.0 * math.cos(angle)) | |
| gamma_v.append( abs( ( ita1v - ita2v ) / ( ita1v + ita2v ) ) ) | |
| tau_v.append( abs( 2 / ( ita1v + ita2v ) ) ) | |
| p1 = pylab.plot(t, gamma_h) | |
| p2 = pylab.plot(t, tau_h) | |
| p3 = pylab.plot(t, gamma_v) | |
| p4 = pylab.plot(t, tau_v) | |
| pylab.xlabel("thita") | |
| pylab.ylabel("ratio") | |
| pylab.legend([p1, p2, p3, p4], ["Horizontal Reflection", "Horizontal Transmission", "Vertical Reflection", "Vertical Transmission"], loc = "upper left") | |
| pylab.grid(True) | |
| pylab.savefig("ratio.png") | |
| pylab.gcf().clear() | |
| p1 = pylab.plot(t, map((lambda x,y: x**2+y**2), gamma_v, tau_v)) | |
| p2 = pylab.plot(t, map((lambda x,y: x**2+y**2), gamma_h, tau_h)) | |
| pylab.title("Average Power Transmission") | |
| pylab.legend([p1,p2], ["Vertical Polarization", "Horizontal Polarization"]) | |
| pylab.grid(True) | |
| pylab.savefig("power.png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



