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 (SPWM) technique. The dc link voltage is $500\,$V. The AC source voltage is $230\,\cos\,(100\,\pi \,t)$V (rms). 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\,(100\,\pi \,t + \phi)$. If the injected current is varied from $+50\,j$ to $-50\,j$ and $\phi = 0$, plot the locus of the inverter voltage.

In [1]:
from IPython.display import Image
Image(filename =r'Animation_VSC_bi_4_fig_1.png', width=300)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat Animation_VSC_bi_4A_orig.in
In [3]:
import numpy as np
import gseim_calc as calc
import os
import dos_unix
import math
import cmath

NI1 = 21
NI2 = int((NI1-1)/2)

# Note: inductor current (from B to D in the figure) is
# j*I_arr[k]

I_arr = np.linspace(50.0, -50.0, NI1)

real_IL = []
imag_IL = []
real_VL = []
imag_VL = []
real_v_inv = []
imag_v_inv = []
real_v_ac = []
imag_v_ac = []

s_L = '5e-3'
s_Vdc = '500'
s_f_hz = '50'
A_sin = 230.0*np.sqrt(2.0)
s_A_sin = ("%11.4E"%A_sin).strip()
s_phi ='90.0'

slv = calc.slv("Animation_VSC_bi_4A_orig.in")
i_slv = 0
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
col_IL = slv.get_index(i_slv,i_out,"IL")
col_VL = slv.get_index(i_slv,i_out,"VL")
col_v_inv = slv.get_index(i_slv,i_out,"v_inv")
col_v_ac = slv.get_index(i_slv,i_out,"v_ac")

sqrt2 = np.sqrt(2.0)

for I in I_arr:
    M = (230.0 - (100.0*np.pi*0.005*I))*np.sqrt(2.0)/500.0
    s_M = "%11.4E"%M
    l = [
      ('$L', s_L),
      ('$Vdc', s_Vdc),
      ('$M', s_M),
      ('$f_hz', s_f_hz),
      ('$A_sin', s_A_sin),
      ('$phi', s_phi),
    ]
    print('I:', 'j*(' + "%4.1f"%I + ') A (rms),', 'M:', s_M)
    calc.replace_strings_1("Animation_VSC_bi_4A_orig.in", "Animation_VSC_bi_4A.in", l)

    # uncomment for windows:
    #dos_unix.d2u("Animation_VSC_bi_4A.in")
    os.system('run_gseim Animation_VSC_bi_4A.in')

    u = np.loadtxt(filename)
    t = u[:, 0]
    t0 = t[0]
    t = t - t0
    T = t[-1]
    k_fourier = 1

    coeff, thd, coeff_a, coeff_b = calc.fourier_coeff_2A(t, u[:,col_IL], 0.0, T, 1.0e-8*T, 1)
    real_x, imag_x = calc.get_mag_angle_2(k_fourier, coeff_a, coeff_b)
    real_IL.append(real_x/sqrt2)
    imag_IL.append(imag_x/sqrt2)

    coeff, thd, coeff_a, coeff_b = calc.fourier_coeff_2A(t, u[:,col_VL], 0.0, T, 1.0e-8*T, 1)
    real_x, imag_x = calc.get_mag_angle_2(k_fourier, coeff_a, coeff_b)
    real_VL.append(real_x/sqrt2)
    imag_VL.append(imag_x/sqrt2)

    coeff, thd, coeff_a, coeff_b = calc.fourier_coeff_2A(t, u[:,col_v_inv], 0.0, T, 1.0e-8*T, 1)
    real_x, imag_x = calc.get_mag_angle_2(k_fourier, coeff_a, coeff_b)
    real_v_inv.append(real_x/sqrt2)
    imag_v_inv.append(imag_x/sqrt2)

    coeff, thd, coeff_a, coeff_b = calc.fourier_coeff_2A(t, u[:,col_v_ac], 0.0, T, 1.0e-8*T, 1)
    real_x, imag_x = calc.get_mag_angle_2(k_fourier, coeff_a, coeff_b)
    real_v_ac.append(real_x/sqrt2)
    imag_v_ac.append(imag_x/sqrt2)

#print('I_arr[NI2]:', I_arr[NI2])
I: j*(50.0) A (rms), M:  4.2839E-01
I: j*(45.0) A (rms), M:  4.5061E-01
I: j*(40.0) A (rms), M:  4.7282E-01
I: j*(35.0) A (rms), M:  4.9504E-01
I: j*(30.0) A (rms), M:  5.1725E-01
I: j*(25.0) A (rms), M:  5.3947E-01
I: j*(20.0) A (rms), M:  5.6168E-01
I: j*(15.0) A (rms), M:  5.8389E-01
I: j*(10.0) A (rms), M:  6.0611E-01
I: j*( 5.0) A (rms), M:  6.2832E-01
I: j*( 0.0) A (rms), M:  6.5054E-01
I: j*(-5.0) A (rms), M:  6.7275E-01
I: j*(-10.0) A (rms), M:  6.9497E-01
I: j*(-15.0) A (rms), M:  7.1718E-01
I: j*(-20.0) A (rms), M:  7.3940E-01
I: j*(-25.0) A (rms), M:  7.6161E-01
I: j*(-30.0) A (rms), M:  7.8382E-01
I: j*(-35.0) A (rms), M:  8.0604E-01
I: j*(-40.0) A (rms), M:  8.2825E-01
I: j*(-45.0) A (rms), M:  8.5047E-01
I: j*(-50.0) A (rms), M:  8.7268E-01
In [4]:
import matplotlib.pyplot as plt 
import sys
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from matplotlib import animation
from IPython.display import HTML
import gseim_calc as calc

IL1 = []
for i in range(len(real_IL)):
    IL_phasor = complex(real_IL[i], imag_IL[i])
    IL1.append(IL_phasor)

fig, ax = plt.subplots()
fig.set_size_inches(8, 4)

xmin = min(real_IL) - 10.0
xmax = max(real_IL) + 10.0
ymin = min(imag_IL) - 10.0
ymax = max(imag_IL) + 10.0

ax.set_aspect('equal', adjustable='box')
ax.set(xlim=[xmin, xmax], ylim=[ymin, ymax])

plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)

plt.xlabel('$Re(i_L)$',fontsize=12)
plt.ylabel('$Im(i_L)$',fontsize=12)

fig.suptitle('Note: current is in A (rms)', fontsize=12)

line = ax.plot([], [], color='blue', linestyle = '--', linewidth=0.8, dashes=(3,3))[0]
line2 = []
for i in range(3):
    line2a = ax.plot([], [], color='blue', linestyle = '-', linewidth=1.0)[0]
    line2.append(line2a)

ax.axhline(y=0.0, color='#777777', linestyle = '-', linewidth=0.5)
ax.axvline(x=0.0, color='#777777', linestyle = '-', linewidth=0.5)

l3 = []
l_labels = []

props = dict(boxstyle='round', facecolor='grey', alpha=0.15)  # bbox features
text1 = ax.text(1.03, 0.98, '', transform=ax.transAxes, fontsize=11, verticalalignment='top', bbox=props)
theta_deg = 20.0

def update(frame):
    line.set_xdata(real_IL[:frame+1])
    line.set_ydata(imag_IL[:frame+1])
    l3.clear()
    l_labels.clear()
    calc.phasor_append_1(l3, l_labels, IL1[frame], "$i_L$")
    length_arrow = 0.03*(ymax-ymin)

    l4  = calc.phasor_2(l3 , theta_deg, length_arrow, 0.4)

    for k, t in enumerate(l4[0]):
        line2[k].set_xdata(t[0])
        line2[k].set_ydata(t[1])

    text1.set_text(
      'I' + ' = j(%4.1f' % I_arr[frame] + ')\n' +
      'Re($i_L$) = %6.1f' % real_IL[frame] + '\n' +
      'Im($i_L$) = %6.1f' % imag_IL[frame]
    )
    return

anim = animation.FuncAnimation(
    fig=fig,
    func=update,
    frames=NI1,
    interval=500,
    repeat=False)

plt.tight_layout()
plt.close()

HTML(anim.to_jshtml())
Out[4]:
In [5]:
import matplotlib.pyplot as plt 
import sys
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
from matplotlib import animation
from IPython.display import HTML
import gseim_calc as calc

IL1 = []
VL1 = []
v_inv1 = []
v_ac1 = []

for i in range(len(real_IL)):
    IL1.append   (complex(real_IL   [i], imag_IL   [i]))
    VL1.append   (complex(real_VL   [i], imag_VL   [i]))
    v_inv1.append(complex(real_v_inv[i], imag_v_inv[i]))
    v_ac1.append (complex(real_v_ac [i], imag_v_ac [i]))

fig, ax = plt.subplots()
fig.set_size_inches(8, 4)

xmin = min(real_IL + real_VL + real_v_inv + real_v_ac) - 10.0
xmax = max(real_IL + real_VL + real_v_inv + real_v_ac) + 10.0
ymin = min(imag_IL + imag_VL + imag_v_inv + imag_v_ac) - 10.0
ymax = max(imag_IL + imag_VL + imag_v_inv + imag_v_ac) + 10.0

ax.set_aspect('equal', adjustable='box')
ax.set(xlim=[xmin, xmax], ylim=[ymin, ymax])

plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)

plt.xlabel('$Re$',fontsize=12)
plt.ylabel('$Im$',fontsize=12)

fig.suptitle('Note: units are A (rms), V (rms)', fontsize=12)

c_IL    = 'blue'
c_VL    = 'red'
c_v_inv = 'green'
c_v_ac  = 'grey'

line_IL    = ax.plot([], [], color=c_IL,    linestyle='--', linewidth=0.8, dashes=(3,3))[0]
line_VL    = ax.plot([], [], color=c_VL,    linestyle='--', linewidth=0.8, dashes=(3,3))[0]
line_v_inv = ax.plot([], [], color=c_v_inv, linestyle='--', linewidth=0.8, dashes=(3,3))[0]

line2_IL    = []
line2_VL    = []
line2_v_inv = []
line2_v_ac  = []

for i in range(3):
    if i == 0:
        line1_IL    = ax.plot([], [], color=c_IL,    linewidth=1.0, label='$i_L$')[0]
        line1_VL    = ax.plot([], [], color=c_VL,    linewidth=1.0, label='$v_L$')[0]
        line1_v_inv = ax.plot([], [], color=c_v_inv, linewidth=1.0, label='$v_{inv}$')[0]
        line1_v_ac  = ax.plot([], [], color=c_v_ac,  linewidth=1.0, label='$v_{ac}$')[0]
    else:
        line1_IL    = ax.plot([], [], color=c_IL,    linewidth=1.0)[0]
        line1_VL    = ax.plot([], [], color=c_VL,    linewidth=1.0)[0]
        line1_v_inv = ax.plot([], [], color=c_v_inv, linewidth=1.0)[0]
        line1_v_ac  = ax.plot([], [], color=c_v_ac,  linewidth=1.0)[0]

    line2_IL   .append(line1_IL)
    line2_VL   .append(line1_VL)
    line2_v_inv.append(line1_v_inv)
    line2_v_ac .append(line1_v_ac)

ax.axhline(y=0.0, color='#777777', linestyle = '-', linewidth=0.5)
ax.axvline(x=0.0, color='#777777', linestyle = '-', linewidth=0.5)

ax.legend(loc='lower left', fontsize=11, bbox_to_anchor=(1.05, 0.0))

l3_IL    = []
l3_VL    = []
l3_v_inv = []
l3_v_ac  = []

l_dummy_sum = []

l_labels_IL    = []
l_labels_VL    = []
l_labels_v_inv = []
l_labels_v_ac  = []

props = dict(boxstyle='round', facecolor='grey', alpha=0.15)  # bbox features
text1 = ax.text(1.03, 0.98, '', transform=ax.transAxes, fontsize=11, verticalalignment='top', bbox=props)
theta_deg = 20.0
length_arrow = 0.03*(xmax-xmin)

def update(frame):
    line_IL.set_xdata(real_IL[:frame+1])
    line_IL.set_ydata(imag_IL[:frame+1])

    line_VL.set_xdata(real_VL[:frame+1])
    line_VL.set_ydata(imag_VL[:frame+1])

    line_v_inv.set_xdata(real_v_inv[:frame+1])
    line_v_inv.set_ydata(imag_v_inv[:frame+1])

    l3_IL.clear()
    l_labels_IL.clear()
    calc.phasor_append_1(l3_IL, l_labels_IL, IL1[frame], "$i_L$")
    l4_IL  = calc.phasor_2(l3_IL , theta_deg, length_arrow, 0.4)

    for k, t in enumerate(l4_IL[0]):
        line2_IL[k].set_xdata(t[0])
        line2_IL[k].set_ydata(t[1])

    l3_VL.clear()
    l_labels_VL.clear()
    calc.phasor_append_1(l3_VL, l_labels_VL, VL1[frame], "$i_L$")
    l4_VL  = calc.phasor_2(l3_VL , theta_deg, length_arrow, 0.4)

    for k, t in enumerate(l4_VL[0]):
        line2_VL[k].set_xdata(t[0])
        line2_VL[k].set_ydata(t[1])

    l3_v_inv.clear()
    l_labels_v_inv.clear()
    calc.phasor_append_1(l3_v_inv, l_labels_v_inv, v_inv1[frame], "$i_L$")
    l4_v_inv  = calc.phasor_2(l3_v_inv , theta_deg, length_arrow, 0.4)

    for k, t in enumerate(l4_v_inv[0]):
        line2_v_inv[k].set_xdata(t[0])
        line2_v_inv[k].set_ydata(t[1])

    l3_v_ac.clear()
    l_labels_v_ac.clear()
    calc.phasor_append_1(l3_v_ac, l_labels_v_ac, v_ac1[frame], "$i_L$")
    l4_v_ac  = calc.phasor_2(l3_v_ac , theta_deg, length_arrow, 0.4)

    for k, t in enumerate(l4_v_ac[0]):
        line2_v_ac[k].set_xdata(t[0])
        line2_v_ac[k].set_ydata(t[1])

    text1.set_text(
      'I' + ' = j(%4.1f' % I_arr[frame] + ')\n' +
      'Re($i_L$) = %6.1f' % real_IL[frame] + '\n' +
      'Im($i_L$) = %6.1f' % imag_IL[frame]
    )
    return

anim = animation.FuncAnimation(
    fig=fig,
    func=update,
    frames=NI1,
    interval=500,
    repeat=False)

plt.tight_layout()
plt.close()

HTML(anim.to_jshtml())
Out[5]:

This notebook was contributed by Prof. Nakul Narayanan K, Govt. Engineering College, Thrissur. He may be contacted at nakul@gectcr.ac.in.

In [ ]: