Advertisement
Guest User

Smith Chart Python

a guest
Nov 14th, 2019
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.69 KB | None | 0 0
  1. # ==============================================================================#
  2. #
  3. #
  4. #
  5. #
  6. #
  7. # ==============================================================================#
  8.  
  9. # begin imports
  10. import math
  11. import os
  12. import numpy as np
  13. from smithplot import SmithAxes
  14. from matplotlib import rcParams, pyplot as plt, cm
  15. from matplotlib.colors import Normalize
  16.  
  17. # end imports
  18.  
  19. #####  DATA ACQUISITION FROM CSV FILE  #####
  20.  
  21. # open data file
  22. if os.path.exists('load_pull.csv'):  # check for file
  23.     file = np.genfromtxt("load_pull.csv", delimiter=',')  # open file of name load_pull.csv
  24. else:
  25.     print("error, file not found")
  26.  
  27. # populate data into arrays
  28. z_mag = file[:, 2]
  29. z_phase = file[:, 3] * (math.pi / 180)
  30. gen_fwd = file[:, 7]
  31. gen_rev = file[:, 8]
  32. gen_load = gen_fwd - gen_rev
  33. freq = file[:, 9]
  34. v_rail = file[:, 10]
  35. pai = file[:, 11] / 10
  36. dc_pwr = np.array(pai * v_rail)
  37. p_diss = file[:, 12]
  38.  
  39. # convert magnitude to real and imaginary parts
  40. zr = z_mag * np.cos(z_phase)
  41. zi = z_mag * np.sin(z_phase)
  42.  
  43. # combine real and imaginary parts
  44. z = np.array(zr + (1j * zi))
  45.  
  46.  
  47. #####  END DATA ACQUISITION FROM CSV FILE  #####
  48.  
  49. def z2gamma(input_array, load):
  50.     """
  51.    converts the impedance z to the reflection coefficient gamma using a reference impedance of z0 (load) ohms
  52.    :param input_array: array of element style (real + imag)
  53.    :param load: number in ohms
  54.    :return: reflection coefficient
  55.    """
  56.     for i in np.nditer(input_array):
  57.         reflection_coefficient = np.array(np.subtract(input_array, load) / np.add(input_array, load))
  58.         return reflection_coefficient
  59.  
  60.  
  61. gamma = z2gamma(z, 50)  # creates new array called gamma and calls the z2gamma function with 50 ohm
  62. gr = np.real(gamma)  # the real part of each value from gamma
  63. gi = np.imag(gamma)  # the imaginary part of each value from gamma
  64.  
  65. """
  66. Graphing
  67. """
  68.  
  69.  
  70. def graph_PARail_vs_Load():
  71.     min_vrail = min(v_rail)
  72.     max_vrail = max(v_rail)
  73.  
  74.     fig = plt.figure(figsize=(10, 10))
  75.     ax = fig.add_subplot(1, 1, 1, projection='smith', grid_major_xmaxn=5, grid_major_ymaxn=14, grid_minor_enable=False)
  76.  
  77.     norm_vrail = Normalize(vmin=int(float(max_vrail)), vmax=int(float(min_vrail)))  # normalize vrail for contour
  78.  
  79.     img = plt.imshow(np.array([[0, 1]]), cmap='YlOrRd_r', norm=norm_vrail)  # create countour chart
  80.     img.set_visible(False)
  81.     cmap = plt.cm.YlOrRd_r
  82.     plt.colorbar()
  83.  
  84.     for g in gamma:
  85.         plot = plt.plot(gamma, datatype=SmithAxes.S_PARAMETER, color=cmap(norm_vrail(float(v_rail))), marker='o',
  86.                         markersize=12, alpha=0.3, markeredgewidth=0.5)
  87.  
  88.     plt.cla()
  89.     plt.title("PA Rail V vs. Load")
  90.  
  91.  
  92. graph_PARail_vs_Load()
  93. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement