Bi-directional voltage source converter
A single-phase bi-directional voltage source converter is connected to an AC voltage source through an inductor $L = 5\,$mH as given below. All the switches are ideal and are operated using the sinusoidal pulse width modulation technique. The dc link voltage is $500\,$V. The AC source voltage is $230\,\angle{0}\,$V. The PWM carrier signal is a triangle wave between $-1$ and $1$ with a frequency of $10\,$kHz, and the modulating signal is $v_{ref}(t) = M\,\sin\,(\omega \,t + \theta)$. Determine $M$ and $\theta$ (in degrees) for which the current injected to the ac voltage source is maximum, has a phase of $-90^{\circ}$, and is free from lower order harmonics.In [1]:
from IPython.display import Image
Image(filename =r'VSC_bi_3_fig_1.png', width=300)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat VSC_bi_3_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 VSC_bi_3_orig.in and produces a new circuit file VSC_bi_3.in, after replacing \$Vdc, \$L, etc. with values of our choice.
In [3]:
import gseim_calc as calc
import numpy as np
s_Vdc = "500"
s_L = "5e-3"
s_f_carrier = "10e3"
s_M = "1.5" # to be changed by user
s_phi = "0" # to be changed by user
s_dt_min = "0.01e-6"
s_dt_nrml = "1e-6"
A_sin = 230.0*np.sqrt(2.0)
s_A_sin = ("%11.4E"%A_sin).strip()
s_f_sin = "50"
f_sin = float(s_f_sin)
T = 1/f_sin
s_2T = ("%11.4E"%(2.0*T)).strip()
s_3T = ("%11.4E"%(3.0*T)).strip()
s_5T = ("%11.4E"%(5.0*T)).strip()
l = [
('$Vdc', s_Vdc),
('$L', s_L),
('$f_carrier', s_f_carrier),
('$f_sin', s_f_sin),
('$A_sin', s_A_sin),
('$2T', s_2T),
('$3T', s_3T),
('$5T', s_5T),
('$M', s_M),
('$phi', s_phi),
('$dt_min', s_dt_min),
('$dt_nrml', s_dt_nrml)
]
calc.replace_strings_1("VSC_bi_3_orig.in", "VSC_bi_3.in", l)
print('VSC_bi_3.in is ready for execution')
VSC_bi_3.in is ready for execution
Execute the following cell to run GSEIM on VSC_bi_3.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("VSC_bi_3.in")
os.system('run_gseim VSC_bi_3.in')
get_lib_elements: filename gseim_aux/xbe.aux get_lib_elements: filename gseim_aux/ebe.aux Circuit: filename = VSC_bi_3.in main: i_solve = 0 main: calling solve_trns Transient simulation starts... i=0 i=50000 i=100000 GSEIM: Program completed.
Out[4]:
0
The circuit file (VSC_bi_3.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on VSC_bi_3.in) creates a data file called VSC_bi_3.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("VSC_bi_3.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]
t0 = t[0]
t = t - t0
col_v_ac = slv.get_index(i_slv,i_out,"v_ac")
col_IL = slv.get_index(i_slv,i_out,"IL")
col_s = slv.get_index(i_slv,i_out,"s")
col_t = slv.get_index(i_slv,i_out,"t")
# 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(3, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(7, 6, ax[0])
for i in range(3):
ax[i].set_xlim(left=0, right=2.0*T*1e3)
ax[i].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[0].tick_params(labelbottom=False)
ax[1].tick_params(labelbottom=False)
ax[0].plot(t*1e3, u[:,col_t ], color=color5, linewidth=1.0, label="$t$")
ax[0].plot(t*1e3, u[:,col_s ], color=color4, linewidth=1.0, label="$s$")
ax[1].plot(t*1e3, u[:,col_v_ac], color=color1, linewidth=1.0, label="$v_{ac}$")
ax[2].plot(t*1e3, u[:,col_IL ], color=color3, linewidth=1.0, label="$i_L$")
ax[1].set_ylabel(r'$V_{ac}$', fontsize=14)
ax[2].set_ylabel(r'$i_L$' , fontsize=14)
ax[2].set_xlabel('time (msec)', fontsize=14)
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},)
#plt.tight_layout()
plt.show()
filename: VSI_bi_3.dat
In [6]:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("VSC_bi_3.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]
t0 = t[0]
t = t - t0
col_IL = slv.get_index(i_slv,i_out,"IL")
# since we have stored two cycles, we need to divide the last time point
# by 2 to get the period:
T = t[-1]/2
# compute Fourier coeffs:
t_start = T
t_end = 2.0*T
n_fourier = 20
coeff_IL, thd_IL = calc.fourier_coeff_1C(t, u[:,col_IL],
t_start, t_end, 1.0e-8, n_fourier)
print('THD in IL:', "%5.2f"%(thd_IL*100.0), "%")
x = np.linspace(0, n_fourier, n_fourier+1)
y_IL = np.array(coeff_IL)
fig, ax = plt.subplots()
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5.5, 2.5, ax)
plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
delta = 5.0
x_major_ticks = np.arange(0.0, (float(n_fourier+1)), delta)
x_minor_ticks = np.arange(0.0, (float(n_fourier+1)), 1.0)
ax.set_xlim(left=-1.0, right=float(n_fourier))
ax.set_xticks(x_major_ticks)
ax.set_xticks(x_minor_ticks, minor=True)
ax.grid(visible=True, which='major', axis='x', color='#CCCCCC', linestyle='-', zorder=0)
ax.set_ylabel('$i_L$',fontsize=14)
ax.set_xlabel('N', fontsize=14)
bars1 = ax.bar(x, y_IL, width=0.7, color='red', label="$i_L$", zorder=3)
plt.tight_layout()
plt.show()
filename: VSI_bi_3.dat THD in IL: 11.33 %
This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.
In [ ]: