sandeep03edu

Mann Morrision Python Software Simulation

May 4th, 2023
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. import math
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. pi = 3.14159265359
  6.  
  7. f=0.25
  8. Over_samp_factor =100*f
  9.  
  10. Vm = 5
  11. Phi_v=30
  12.  
  13. R_perKm =.01
  14. XbyR =10
  15. Line_Length = 100
  16.  
  17. R = R_perKm * Line_Length
  18. X = R * XbyR
  19. w = 2 * pi * f
  20. L = X / w
  21. Z = math.sqrt(pow(R,2) + pow(X,2))
  22. Im = Vm / Z
  23.  
  24. Phi_i = (math.atan2(XbyR, 1))*(180/pi)
  25.  
  26. fsamp = 2* f * Over_samp_factor
  27. dT = 1/ fsamp
  28. T = 1 / f
  29. k=0
  30.  
  31. v = []
  32. I = []
  33. v_das = []
  34.  
  35. for t in np.arange(0, T+dT, dT):
  36.     a = Vm * math.sin(2 * pi * f * t + (Phi_v)*(pi/180))
  37.     v.append(a)
  38.  
  39. no_of_samples = len(v)
  40.  
  41. Vm_estimate = []
  42. Phi_V_estimate = []
  43. time = []
  44. start = 0
  45.  
  46. print(v)
  47.  
  48. for k in range(1, no_of_samples-1):
  49.     v_dash = (v[k+1]-v[k-1])/(2*dT)
  50.  
  51.     Vm_est= math.sqrt(pow(v[k],2) + pow(v_dash/w,2))
  52.  
  53.     Vm_estimate.append(round(Vm_est, 8))
  54.  
  55.     Phi_V_est_rad = (math.atan2(((v[k])/((v_dash)/w)),1))-(w*k*dT);
  56.     Phi_V_est_deg= (Phi_V_est_rad)*(180/pi);
  57.  
  58.     if(Phi_V_est_deg<0):
  59.         pass
  60.         # Phi_V_est_deg = ((-Phi_V_est_deg)//180+1)*180 + Phi_V_est_deg;
  61.     Phi_V_est_deg = (Phi_V_est_deg)%180;
  62.  
  63.     Phi_V_estimate.append(Phi_V_est_deg)
  64.  
  65.     time.append(start)
  66.     start = start + dT
  67.  
  68. xPoints = np.array(time)
  69. yPoints = np.array(Vm_estimate)
  70.  
  71. plt.plot(xPoints, yPoints, color='r', label='VPeak')
  72.  
  73. yPoints = np.array(Phi_V_estimate)
  74. plt.plot(xPoints, yPoints, color='g', label='Phase')
  75.  
  76. plt.legend(loc='best')
  77.  
  78. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment