Time constants
Consider the circuit shown in the figure in its periodic steady state. Given: $T_1=0.6\,ms$, $T_2=0.4\,ms$, $R=1\,k\Omega$, $V_0=5\,V$, and $V_{\mathrm{max}}/V_{\mathrm{min}}=2.72$.
- Show that $V_{\mathrm{max}}=V_0\,\displaystyle\frac{1-k_1}{1-k_0}$, $V_{\mathrm{min}}=k_2V_{\mathrm{max}}$, with $k_1=e^{-T_1/\tau}$, $k_2=e^{-T_2/\tau}$, $k_0=k_1k_2$ ($\tau=RC$).
- Find $C$.
- Find the corresponding values of $V_{\mathrm{min}}$ and $V_{\mathrm{max}}.
from IPython.display import Image
Image(filename =r'time_constant_6_fig_1.png', width=650)
# run this cell to view the circuit file.
%pycat time_constant_6_orig.in
We now replace the string \$C with the value of our choice by running the python script given below. It takes an existing circuit file time_constant_6_orig.in and produces a new circuit file time_constant_6.in, after replacing \$C with the value of our choice.
import gseim_calc as calc
s_C = '1u' # to be changed by user
l = [
('$C', s_C),
]
calc.replace_strings_1("time_constant_6_orig.in", "time_constant_6.in", l)
print('time_constant_6.in is ready for execution')
time_constant_6.in is ready for execution
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("time_constant_6.in")
os.system('run_gseim time_constant_6.in')
Circuit: filename = time_constant_6.in main: calling solve_sss solve_sss starting: sss_n_st: 1 solve_sss_ex: sss_iter_newton=0, rhs_sss_norm=2.06826e-06, sss_period_1_compute=0.002 solve_sss_ex: sss_iter_newton=1, rhs_sss_norm=1.2282e-19, sss_period_1_compute=0.002 solve_sss_ex: calling sss_solve_trns_ex for one more trns step Transient simulation starts... i=0 i=1000 GSEIM: Program completed.
0
The circuit file (time_constant_6.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on time_constant_6.in) creates the data file time_constant_6.dat, in the same directory. We can now use the python code below to compute and display the quantities of interest.
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("time_constant_6.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]
t_end = t[-1]
VS = slv.get_array_double(i_slv, i_out, 'VS', u)
VC = slv.get_array_double(i_slv, i_out, 'VC', u)
Vmin = min(VC)
Vmax = max(VC)
r = 2.72
print("Vmin =", "%5.2f"%(Vmin), "V")
print("Vmax =", "%5.2f"%(Vmax), "V")
print("(Vmax/Vmin) =", "%5.2f"%((Vmax/Vmin)))
print("desired (Vmax/Vmin) =", "%5.2f"%(r))
color1='blue'
color2='green'
color3='red'
fig, ax = plt.subplots()
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5, 2.5, ax)
plt.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax.plot(t*1e3, VS, color=color1, linewidth=1.0, label="$V_s$")
ax.plot(t*1e3, VC, color=color3, linewidth=1.0, label="$V_C$")
ax.axhline(y=Vmin, color=color2, linewidth=0.8, label="_Vmin", linestyle='-.')
ax.axhline(y=Vmax, color=color2, linewidth=0.8, label="_Vmax", linestyle='-.')
ax.set_xlim(0.0, 1e3*t_end)
plt.xlabel('time (msec)', fontsize=11)
ax.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: time_constant_6.dat Vmin = 2.39 V Vmax = 3.57 V (Vmax/Vmin) = 1.49 desired (Vmax/Vmin) = 2.72
This notebook was contributed by Prof. M. B. Patil, IIT Bombay. He may be contacted at mbpatil@ee.iitb.ac.in.