Common-emitter amplifier
For the common-emitter amplifier shown in the figure, find $R_C$ to obtain a gain of $-100$ and the corresponding bias values of $I_C$ and $V_{CE}$. Assume $\beta$ to be large.
Note that the simulation results would be slightly different than the theoretical values since we are using a realistic BJT model (2N2222) and not an ideal BJT model.
In [1]:
from IPython.display import Image
Image(filename =r'EC_CE_amp_1_fig_1.png', width=250)
Out[1]:
In [2]:
# run this cell to view the circuit file (operating point analysis)
%pycat EC_CE_amp_1a_orig.in
In [3]:
import gseim_calc as calc
# replace string $RC in EC_CE_amp_1a_orig.in
s_RC = '1.5k' # to be changed by user
l = [
('$RC', s_RC),
]
calc.replace_strings_1("EC_CE_amp_1a_orig.in", "EC_CE_amp_1a.in", l)
print('EC_CE_amp_1a.in is ready for execution')
EC_CE_amp_1a.in is ready for execution
In [4]:
import ngspice_calc as ngcalc
ngcalc.run_ngspice('EC_CE_amp_1a.in')
Circuit: common-emitter amplifier Doing analysis at TEMP = 27.000000 and TNOM = 27.000000 No. of Data Columns : 4 No. of Data Rows : 1 Total analysis time (seconds) = 0 Total elapsed time (seconds) = 0.002 Total DRAM available = 7739.719 MB. DRAM currently available = 2524.223 MB. Total ngspice program size = 19.594 MB. Resident set size = 9.062 MB. Shared ngspice pages = 7.672 MB. Text (code) pages = 5.789 MB. Stack = 0 bytes. Library pages = 1.844 MB.
Out[4]:
'EC_CE_amp_1a.raw'
In [5]:
# get output file information from the circuit file
s = ngcalc.slv('EC_CE_amp_1a.in')
for i in range(s.num_plots()):
print(f" plot {i}: {s.plotname(i)} | type: {s.analysis_type(i)} | vars: {s.variables(i)}")
plot 0: Operating Point | type: op | vars: ['v(1)', 'v(2)', 'v(3)', 'i(vx)']
In [6]:
V_B = s.get_array('v(2)')[0]
V_C = s.get_array('v(1)')[0]
V_E = s.get_array('v(3)')[0]
I_C = s.get_array('i(vx)')[0]
print(f'V_B = {V_B:7.4f} V')
print(f'V_C = {V_C:7.4f} V')
print(f'V_E = {V_E:7.4f} V')
print(f'I_C = {I_C:11.4e} A')
V_BE = V_B - V_E
V_CE = V_C - V_E
print(f'V_BE = {V_BE:7.4f} V')
print(f'V_CE = {V_CE:7.4f} V')
V_B = 2.6329 V V_C = 8.5522 V V_E = 1.9495 V I_C = 9.6518e-04 A V_BE = 0.6834 V V_CE = 6.6028 V
In [7]:
# run this cell to view the circuit file (gain versus frequency)
%pycat EC_CE_amp_1b_orig.in
In [8]:
f_start = 10.0
f_stop = 100.0e6
s_FSTART = ("%11.4E"%(f_start)).strip()
s_FSTOP = ("%11.4E"%(f_stop)).strip()
l = [
('$RC', s_RC),
('$FSTART', s_FSTART),
('$FSTOP', s_FSTOP),
]
calc.replace_strings_1("EC_CE_amp_1b_orig.in", "EC_CE_amp_1b.in", l)
print('EC_CE_amp_1b.in is ready for execution')
EC_CE_amp_1b.in is ready for execution
In [9]:
ngcalc.run_ngspice('EC_CE_amp_1b.in')
Circuit: common-emitter amplifier Doing analysis at TEMP = 27.000000 and TNOM = 27.000000 No. of Data Columns : 3 No. of Data Rows : 141 Total analysis time (seconds) = 0 Total elapsed time (seconds) = 0.002 Total DRAM available = 7739.719 MB. DRAM currently available = 2523.859 MB. Total ngspice program size = 19.590 MB. Resident set size = 9.070 MB. Shared ngspice pages = 7.672 MB. Text (code) pages = 5.789 MB. Stack = 0 bytes. Library pages = 1.840 MB.
Out[9]:
'EC_CE_amp_1b.raw'
In [10]:
# get output file information from the circuit file
s = ngcalc.slv('EC_CE_amp_1b.in')
for i in range(s.num_plots()):
print(f" plot {i}: {s.plotname(i)} | type: {s.analysis_type(i)} | vars: {s.variables(i)}")
plot 0: AC Analysis | type: tran | vars: ['frequency', 'v(5)', 'v(1)']
In [11]:
import numpy as np
import matplotlib.pyplot as plt
freq = s.get_array('frequency')
v_in = s.get_array('v(5)')
v_out = s.get_array('v(1)')
H = v_out/v_in
gain_db = ngcalc.to_db(H)
color1 = 'blue'
fig, ax = plt.subplots(figsize=(7,4))
plt.xlim(f_start, f_stop)
ax.semilogx(freq, gain_db, color=color1, linewidth=1.0, label='gain')
ax.set_xlabel('Frequency (Hz)', fontsize=11)
ax.set_ylabel('Gain (dB)', fontsize=11)
ax.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5, which='both')
fig.suptitle('CE amplifier Frequency Response', fontsize=12)
plt.tight_layout()
plt.show()
In [12]:
# run this cell to view the circuit file (for time-domain waveforms)
%pycat EC_CE_amp_1c_orig.in
In [13]:
t_stop = 10e-3
s_TSTOP = ("%11.4E"%(t_stop)).strip()
l = [
('$RC', s_RC),
('$TSTOP', s_TSTOP),
]
calc.replace_strings_1("EC_CE_amp_1c_orig.in", "EC_CE_amp_1c.in", l)
print('EC_CE_amp_1c.in is ready for execution')
EC_CE_amp_1c.in is ready for execution
In [14]:
ngcalc.run_ngspice('EC_CE_amp_1c.in')
Circuit: common-emitter amplifier Doing analysis at TEMP = 27.000000 and TNOM = 27.000000 No. of Data Columns : 6 No. of Data Rows : 1 No. of Data Columns : 7 Initial Transient Solution -------------------------- Node Voltage ---- ------- 4 10 5 0 1 8.55224 2 2.63289 3 1.94949 1a 8.55224 6 0 vx#branch 0.000965176 vin#branch 0 vcc#branch -0.00123803 No. of Data Rows : 1008 Total analysis time (seconds) = 0.005 Total elapsed time (seconds) = 0.006 Total DRAM available = 7739.719 MB. DRAM currently available = 2496.105 MB. Total ngspice program size = 19.590 MB. Resident set size = 9.715 MB. Shared ngspice pages = 8.082 MB. Text (code) pages = 5.789 MB. Stack = 0 bytes. Library pages = 1.840 MB.
Out[14]:
'EC_CE_amp_1c.raw'
In [15]:
s = ngcalc.slv('EC_CE_amp_1c.in')
print("Number of plots: ", s.num_plots())
for i in range(s.num_plots()):
print(f'plot {i}: {s.plotname(i)} | type: {s.analysis_type(i)} | variables: {s.variables(i)}')
Number of plots: 2 plot 0: Operating Point | type: op | variables: ['v(1)', 'v(2)', 'v(3)', 'v(5)', 'v(6)', 'i(vx)'] plot 1: Transient Analysis | type: tran | variables: ['time', 'v(1)', 'v(2)', 'v(3)', 'v(5)', 'v(6)', 'i(vx)']
In [16]:
t = s.get_array('time', plot=1)
vin = s.get_array('v(5)', plot=1)
vout = s.get_array('v(6)', plot=1)
vin_amp = (vin.max() - vin.min())/2
vout_amp = (vout.max() - vout.min())/2
gain = vout_amp/vin_amp if vin_amp > 0 else 0
print(f'Input amplitude: {vin_amp*1e3:.3f} mV')
print(f'Output amplitude: {vout_amp*1e3:.3f} mV')
print(f'Voltage gain: {gain:.2f}')
Input amplitude: 1.000 mV Output amplitude: 56.024 mV Voltage gain: 56.03
In [17]:
color1 = 'blue'
color2 = 'brown'
t0 = 8e-3
t = t-t0
fig, ax = plt.subplots(2, sharex=True, figsize=(7, 5))
plt.subplots_adjust(hspace=0.0)
plt.xlim(0,t_stop-t0)
for a in ax:
a.grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
a.set_xlim(left=0.0, right=t[-1]*1e3)
ax[0].plot(t*1e3, vin*1e3, color=color1, linewidth=1.0, label=r'$V_{in}$')
ax[0].set_ylabel(r'$V_{in}$ (mV)', fontsize=11)
ax[0].tick_params(labelbottom=False)
ax[1].plot(t*1e3, vout*1e3, color=color2, linewidth=1.0, label=r'$V_{out}$')
ax[1].set_ylabel(r'$V_{out}$ (mV)', fontsize=11)
ax[1].set_xlabel(r'time (msec)', fontsize=11)
plt.show()
This notebook was contributed by Prof. M. B. Patil, IIT Bombay. He may be contacted at mbpatil@ee.iitb.ac.in.
In [ ]: