Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. import math
  2. from math import cos, sin, sqrt, atan2, acos
  3.  
  4. def PatchFunction(thetaInDeg, phiInDeg, Freq, W, L, h, Er):
  5. """
  6. Taken from Design_patchr
  7. Calculates total E-field pattern for patch as a function of theta and phi
  8. Patch is assumed to be resonating in the (TMx 010) mode.
  9. E-field is parallel to x-axis
  10.  
  11. W......Width of patch (m)
  12. L......Length of patch (m)
  13. h......Substrate thickness (m)
  14. Er.....Dielectric constant of substrate
  15.  
  16. Refrence C.A. Balanis 2nd Edition Page 745
  17. """
  18. lamba = 3e8 / Freq
  19.  
  20. theta_in = math.radians(thetaInDeg)
  21. phi_in = math.radians(phiInDeg)
  22.  
  23. ko = 2 * math.pi / lamba
  24.  
  25. xff, yff, zff = sph2cart1(999, theta_in, phi_in) # Rotate coords 90 deg about x-axis to match array_utils coord system with coord system used in the model.
  26. xffd = zff
  27. yffd = xff
  28. zffd = yff
  29. r, thp, php = cart2sph1(xffd, yffd, zffd)
  30. phi = php
  31. theta = thp
  32.  
  33. if theta == 0:
  34. theta = 1e-9 # Trap potential division by zero warning
  35.  
  36. if phi == 0:
  37. phi = 1e-9
  38.  
  39. Ereff = ((Er + 1) / 2) + ((Er - 1) / 2) * (1 + 12 * (h / W)) ** -0.5 # Calculate effictive dielectric constant for microstrip line of width W on dielectric material of constant Er
  40.  
  41. F1 = (Ereff + 0.3) * (W / h + 0.264) # Calculate increase length dL of patch length L due to fringing fields at each end, giving total effective length Leff = L + 2*dL
  42. F2 = (Ereff - 0.258) * (W / h + 0.8)
  43. dL = h * 0.412 * (F1 / F2)
  44.  
  45. Leff = L + 2 * dL
  46.  
  47. Weff = W # Calculate effective width Weff for patch, uses standard Er value.
  48. heff = h * sqrt(Er)
  49.  
  50. # Patch pattern function of theta and phi, note the theta and phi for the function are defined differently to theta_in and phi_in
  51. Numtr2 = sin(ko * heff * cos(phi) / 2)
  52. Demtr2 = (ko * heff * cos(phi)) / 2
  53. Fphi = (Numtr2 / Demtr2) * cos((ko * Leff / 2) * sin(phi))
  54.  
  55. Numtr1 = sin((ko * heff / 2) * sin(theta))
  56. Demtr1 = ((ko * heff / 2) * sin(theta))
  57. Numtr1a = sin((ko * Weff / 2) * cos(theta))
  58. Demtr1a = ((ko * Weff / 2) * cos(theta))
  59. Ftheta = ((Numtr1 * Numtr1a) / (Demtr1 * Demtr1a)) * sin(theta)
  60.  
  61. # Due to groundplane, function is only valid for theta values : 0 < theta < 90 for all phi
  62. # Modify pattern for theta values close to 90 to give smooth roll-off, standard model truncates H-plane at theta=90.
  63. # PatEdgeSF has value=1 except at theta close to 90 where it drops (proportional to 1/x^2) to 0
  64.  
  65. rolloff_factor = 0.5 # 1=sharp, 0=softer
  66. theta_in_deg = theta_in * 180 / math.pi # theta_in in Deg
  67. F1 = 1 / (((rolloff_factor * (abs(theta_in_deg) - 90)) ** 2) + 0.001) # intermediate calc
  68. PatEdgeSF = 1 / (F1 + 1) # Pattern scaling factor
  69.  
  70. UNF = 1.0006 # Unity normalisation factor for element pattern
  71.  
  72. if theta_in <= math.pi / 2:
  73. Etot = Ftheta * Fphi * PatEdgeSF * UNF # Total pattern by pattern multiplication
  74. else:
  75. Etot = 0
  76.  
  77. return Etot
  78.  
  79. def sph2cart1(r, th, phi):
  80. x = r * cos(phi) * sin(th)
  81. y = r * sin(phi) * sin(th)
  82. z = r * cos(th)
  83.  
  84. return x, y, z
  85.  
  86. def cart2sph1(x, y, z):
  87. r = sqrt(x**2 + y**2 + z**2) + 1e-15
  88. th = acos(z / r)
  89. phi = atan2(y, x)
  90.  
  91. return r, th, phi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement