1-phase VSI
A pulse width modulated square wave inverter works from $400\,$V DC input with a pulse duration $d=108^{\circ}$ as shown below. The inverter frequency is $50\,$Hz. The other parameters are $R=1\,\Omega$ and $L=10\,$mH.- Plot the load current and voltage.
- At each corner point in the load current waveform, determine the load current value.
- Determine the average current through the DC source.
- Determine the RMS value of the load voltage.
- Determine the RMS value of the fundamental component of the load voltage and load current.
- Determine the RMS values of the two lowest-order harmonics of the load voltage and load current.
- Determine the THD of the load voltage and load current.
In [1]:
from IPython.display import Image
Image(filename =r'VSI_1ph_4_fig_1.png', width=700)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat VSI_1ph_4_orig.in
We now replace the strings such as \$Vdc, \$L, with the values of our choice by running the python script given below. It takes an existing circuit file VSI_1ph_4_orig.in and produces a new circuit file VSI_1ph_4.in, after replacing \$Vdc, \$L, etc. with values of our choice.
In [3]:
import gseim_calc as calc
s_Vdc = '400'
s_R = '1'
s_L = '10e-3'
f_hz = 50.0
s_f_hz = ("%11.4E"%(f_hz)).strip()
d = 108.0
T = 1/f_hz
theta = (180.0-d)/2
t0_1 = (theta/360)*T
t0_2 = t0_1 + (d/360)*T
s_t0_1 = ("%11.4E"%(t0_1)).strip()
s_t0_2 = ("%11.4E"%(t0_2)).strip()
l = [
('$Vdc', s_Vdc),
('$R', s_R),
('$L', s_L),
('$f_hz', s_f_hz),
('$t0_1', s_t0_1),
('$t0_2', s_t0_2)
]
calc.replace_strings_1("VSI_1ph_4_orig.in", "VSI_1ph_4.in", l)
print('VSI_1ph_4.in is ready for execution')
VSI_1ph_4.in is ready for execution
Execute the following cell to run GSEIM on VSI_1ph_4.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("VSI_1ph_4.in")
os.system('run_gseim VSI_1ph_4.in')
get_lib_elements: filename gseim_aux/xbe.aux get_lib_elements: filename gseim_aux/ebe.aux Circuit: filename = VSI_1ph_4.in main: i_solve = 0 main: calling solve_trns mat_ssw_1_ex: n_statevar: 1 Transient simulation starts... i=0 solve_ssw_ex: ssw_iter_newton=0, rhs_ssw_norm=1.0576e+02 Transient simulation starts... i=0 solve_ssw_ex: ssw_iter_newton=1, rhs_ssw_norm=1.9895e-13 solve_ssw_ex: calling solve_ssw_1_ex for one more trns step Transient simulation starts... i=0 solve_ssw_1_ex over (after trns step for output) solve_ssw_ex ends, slv.ssw_iter_newton=1 GSEIM: Program completed.
Out[4]:
0
The circuit file (VSI_1ph_4.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on VSI_1ph_4.in) creates a data file called VSI_1ph_4.datin the same directory. We can now use the python code below to compute/plot the various quantities of interest.
In [5]:
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("VSI_1ph_4.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t1 = u[:, 0]
t = 1e3*t1 # convert time to msec
col_v_out = slv.get_index(i_slv,i_out,"v_out")
col_IR = slv.get_index(i_slv,i_out,"IR" )
col_ISrc = slv.get_index(i_slv,i_out,"ISrc" )
col_P_R = slv.get_index(i_slv,i_out,"P_R" )
col_g1 = slv.get_index(i_slv,i_out,"g1" )
col_g2 = slv.get_index(i_slv,i_out,"g2" )
col_g3 = slv.get_index(i_slv,i_out,"g3" )
col_g4 = slv.get_index(i_slv,i_out,"g4" )
# since we have stored two cycles, we need to divide the last time point
# by 2 to get the period:
T = t[-1]/2
l_IR = calc.avg_rms_2(t, u[:,col_IR ], 0.0, 2.0*T, 1.0e-4*T)
l_P_R = calc.avg_rms_2(t, u[:,col_P_R ], 0.0, 2.0*T, 1.0e-4*T)
l_ISrc = calc.avg_rms_2(t, u[:,col_ISrc ], 0.0, 2.0*T, 1.0e-4*T)
l_v_out = calc.avg_rms_2(t, u[:,col_v_out], 0.0, 2.0*T, 1.0e-4*T)
l_IR_1 = calc.min_max_1(t, u[:,col_IR], 0.0, 2.0*T)
print('average source current:', "%11.4E"%l_ISrc[1][0])
print('rms source current:', "%11.4E"%l_ISrc[2][0])
print('rms load current:', "%11.4E"%l_IR[2][0])
print('rms load voltage:', "%11.4E"%l_v_out[2][0])
print('peak load current:', "%11.4E"%l_IR_1[1])
print('power delivered to load:', "%11.4E"%l_P_R[1][0])
# time points where i_L(t) has corners:
l_t1 = []
# get values of Vin, D, etc from the circuit file:
fin = open("VSI_1ph_4.in", "r")
for line in fin:
if 'name=clock1' in line:
for s in line.split():
if s.startswith('t0='):
t0_1 = float(s.split('=')[1])
if 'name=clock2' in line:
for s in line.split():
if s.startswith('t0='):
t0_2 = float(s.split('=')[1])
fin.close()
l_t1.append(t0_1)
l_t1.append(t0_2)
l_t1.append(t0_1 + 1.0e-3*T/2)
l_t1.append(t0_2 + 1.0e-3*T/2)
print("corner points in IL(t):")
for t_given in l_t1:
IL1 = calc.get_value_1(1.0e-3*t, u[:,col_IR], t_given)
print('t:', "%11.4E"%t_given, 'IL:', "%11.4E"%IL1)
color1='green'
color2='crimson'
color3='goldenrod'
color4='blue'
fig, ax = plt.subplots(2, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5, 5, ax[0])
ax[0].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[0].plot(t, u[:,col_IR], color=color1, linewidth=1.0, label="$i_L$")
ax[0].set_xlim(left=0.0, right=2.0*T)
ax[0].legend(loc = 'lower right',frameon = True, fontsize = 10, title = None,
markerfirst = True, markerscale = 1.0, labelspacing = 0.5, columnspacing = 2.0,
prop = {'size' : 12},)
ax[1].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[1].set_xlim(left=0.0, right=2.0*T)
ax[1].plot(t, u[:,col_v_out], color=color2, linewidth=1.0, label="$V_o$")
ax[1].set_xlabel('time (msec)', fontsize=11)
ax[1].legend(loc = 'lower right',frameon = True, fontsize = 10, title = None,
markerfirst = True, markerscale = 1.0, labelspacing = 0.5, columnspacing = 2.0,
prop = {'size' : 12},)
plt.tight_layout()
plt.show()
filename: VSI_1ph_4.dat average source current: 1.9646E+01 rms source current: 5.5181E+01 rms load current: 8.8392E+01 rms load voltage: 3.0983E+02 peak load current: 1.3161E+02 power delivered to load: 7.8131E+03 corner points in IL(t): t: 2.0000E-03 IL: -8.8058E+01 t: 8.0000E-03 IL: 1.3154E+02 t: 1.2000E-02 IL: 8.8058E+01 t: 1.8000E-02 IL: -1.3154E+02
In [6]:
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("VSI_1ph_4.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t1 = u[:, 0]
t = 1e3*t1 # convert time to msec
col_v_out = slv.get_index(i_slv,i_out,"v_out")
col_IR = slv.get_index(i_slv,i_out,"IR" )
col_ISrc = slv.get_index(i_slv,i_out,"ISrc" )
col_P_R = slv.get_index(i_slv,i_out,"P_R" )
col_g1 = slv.get_index(i_slv,i_out,"g1" )
col_g2 = slv.get_index(i_slv,i_out,"g2" )
col_g3 = slv.get_index(i_slv,i_out,"g3" )
col_g4 = slv.get_index(i_slv,i_out,"g4" )
# since we have stored two cycles, we need to divide the last time point
# by 2 to get the period:
T = t[-1]/2
color1='green'
color2='crimson'
color3='goldenrod'
color4='blue'
color5='cornflowerblue'
fig, ax = plt.subplots(5, sharex=True)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5, 6, ax[0])
for i in range(4):
ax[i].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[i].set_xlim(left=0.0, right=2.0*T)
ax[i].set_ylim(bottom=-0.3, top=1.3)
ax[i].set_yticks([0.0, 1.0])
ax[0].plot(t, u[:,col_g1], color=color1, linewidth=1.0)
ax[0].set_ylabel('g1', fontsize=11)
ax[1].plot(t, u[:,col_g2], color=color2, linewidth=1.0)
ax[1].set_ylabel('g2', fontsize=11)
ax[2].plot(t, u[:,col_g3], color=color3, linewidth=1.0)
ax[2].set_ylabel('g3', fontsize=11)
ax[3].plot(t, u[:,col_g4], color=color4, linewidth=1.0)
ax[3].set_ylabel('g4', fontsize=11)
ax[4].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[4].set_xlim(left=0.0, right=2.0*T)
ax[4].plot(t, u[:,col_v_out], color=color5, linewidth=1.0)
ax[4].set_ylabel("$V_{out}$", fontsize=11)
ax[4].set_xlabel('time (msec)', fontsize=11)
plt.show()
filename: VSI_1ph_4.dat
In [7]:
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("VSI_1ph_4.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t = u[:, 0]
col_v_out = slv.get_index(i_slv,i_out,"v_out")
col_IR = slv.get_index(i_slv,i_out,"IR" )
col_ISrc = slv.get_index(i_slv,i_out,"ISrc" )
col_P_R = slv.get_index(i_slv,i_out,"P_R" )
col_g1 = slv.get_index(i_slv,i_out,"g1" )
col_g2 = slv.get_index(i_slv,i_out,"g2" )
col_g3 = slv.get_index(i_slv,i_out,"g3" )
col_g4 = slv.get_index(i_slv,i_out,"g4" )
T = t[-1]/2
# compute Fourier coeffs:
t_start = 0.0
t_end = T
n_fourier_IR = 20
coeff_IR, thd_IR = calc.fourier_coeff_1C(t, u[:,col_IR],
t_start, t_end, 1.0e-4*T, n_fourier_IR)
print('fourier coefficients (load current):')
for i, c in enumerate(coeff_IR):
print(" %3d %11.4E"% (i, c))
print("THD (load current): ", "%5.2f"%(thd_IR*100.0), "%")
print("load current fundamental: RMS value: ", "%11.4E"%(coeff_IR[1]/np.sqrt(2.0)))
print("load current 3rd harmonic: RMS value: ", "%11.4E"%(coeff_IR[3]/np.sqrt(2.0)))
print("load current 5th harmonic: RMS value: ", "%11.4E"%(coeff_IR[5]/np.sqrt(2.0)))
n_fourier_v_out = 20
coeff_v_out, thd_v_out = calc.fourier_coeff_1C(t, u[:,col_v_out],
t_start, t_end, 1.0e-4*T, n_fourier_v_out)
print('fourier coefficients (load voltage):')
for i, c in enumerate(coeff_v_out):
print(" %3d %11.4E"% (i, c))
print("THD (load voltage): ", "%5.2f"%(thd_v_out*100.0), "%")
print("load voltage fundamental: RMS value: ", "%11.4E"%(coeff_v_out[1]/np.sqrt(2.0)))
print("load voltage 3rd harmonic: RMS value: ", "%11.4E"%(coeff_v_out[3]/np.sqrt(2.0)))
print("load voltage 5th harmonic: RMS value: ", "%11.4E"%(coeff_v_out[5]/np.sqrt(2.0)))
x_IR = np.linspace(0, n_fourier_IR, n_fourier_IR+1)
x_v_out = np.linspace(0, n_fourier_v_out, n_fourier_v_out+1)
y_IR = np.array(coeff_IR)
y_v_out = np.array(coeff_v_out)
fig, ax = plt.subplots(2, sharex=False)
bars1 = ax[0].bar(x_IR, y_IR, width=0.3, color='red', label="$i_{load}$")
bars2 = ax[1].bar(x_v_out, y_v_out, width=0.3, color='blue', label="$V_{out}$")
ax[0].set_xlabel('N', fontsize=11)
ax[0].set_ylabel('$i_{load}$', fontsize=11)
ax[0].set_xlim(left=0, right=n_fourier_IR)
ax[0].xaxis.set_ticks(np.arange(0, n_fourier_IR, 2))
ax[0].legend(loc = 'upper right',frameon = True, fontsize = 10, title = None,
markerfirst = True, markerscale = 1.0, labelspacing = 0.5, columnspacing = 2.0,
prop = {'size' : 12},)
ax[1].set_xlabel('N', fontsize=11)
ax[1].set_ylabel('$v_{out}$', fontsize=11)
ax[1].set_xlim(left=0, right=n_fourier_v_out)
ax[1].xaxis.set_ticks(np.arange(0, n_fourier_v_out, 2))
ax[1].legend(loc = 'upper right',frameon = True, fontsize = 10, title = None,
markerfirst = True, markerscale = 1.0, labelspacing = 0.5, columnspacing = 2.0,
prop = {'size' : 12},)
plt.tight_layout()
plt.show()
filename: VSI_1ph_4.dat fourier coefficients (load current): 0 6.4053E-05 1 1.2469E+02 2 2.0265E-05 3 5.5223E+00 4 4.3009E-05 5 6.4592E+00 6 1.0088E-04 7 1.0200E+00 8 1.1265E-04 9 1.6184E+00 10 8.0827E-05 11 1.0856E+00 12 2.5337E-04 13 2.9761E-01 14 5.5590E-04 15 7.2611E-01 16 7.2551E-04 17 1.7485E-01 18 5.7636E-04 19 3.7205E-01 20 3.2259E-04 THD (load current): 7.09 % load current fundamental: RMS value: 8.8171E+01 load current 3rd harmonic: RMS value: 3.9049E+00 load current 5th harmonic: RMS value: 4.5673E+00 fourier coefficients (load voltage): 0 1.6061E-07 1 4.1201E+02 2 1.6921E-06 3 5.2451E+01 4 1.1036E-05 5 1.0181E+02 6 2.2103E-05 7 2.2464E+01 8 1.7472E-05 9 4.5707E+01 10 7.7065E-05 11 3.7373E+01 12 3.2309E-05 13 1.2060E+01 14 1.2885E-04 15 3.3806E+01 16 1.5488E-04 17 9.2172E+00 18 9.4138E-05 19 2.1527E+01 20 3.1262E-04 THD (load voltage): 36.19 % load voltage fundamental: RMS value: 2.9134E+02 load voltage 3rd harmonic: RMS value: 3.7088E+01 load voltage 5th harmonic: RMS value: 7.1990E+01
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.
In [ ]: