'grid_linestyle': 'dotted', 'title': r'CE Amplifier Transient Response ' + flabel, 'xlabel': r'Time [s]', 'ylabel': r'Output Voltage [v]', 'legend_loc': 'upper left', 'add_legend': True, 'legend_title': None } fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax2 = ax.twinx() ax2.set_ylim(-15, 75) ax2.set_ylabel('Input Voltage [V]') ax.set_ylim( np.mean(vo) - ( 2.25 * ( np.mean(vo) - min(vo) )), \ np.mean(vo) + ( 1.5 * ( max(vo) - np.mean(vo) ))) vpp = si_format(max(vo) - min(vo), precision=2) + 'V' ax.plot(t, vo, '-', color='red', \ label = r'$v_{out}, V_{p-p}=$' + vpp) ax2.plot(t, eee51.scale_vec(vi, g51.milli), '-', \ label = r'$v_{in}$') ax2.legend(loc='upper right') eee51.label_plot(plt_cfg, fig, ax) plt.savefig(output_tran_file)
# define the plot parameters plt_cfg = { 'grid_linestyle': 'dotted', 'title': r'Common Emitter CM Bias DC Transfer Curve', 'xlabel': r'$v_{in}$ [mV]', 'ylabel': r'$v_{out}$ [V]', 'legend_loc': 'upper left', 'add_legend': True, 'legend_title': None } # plot the amplifier transfer characteristics fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(eee51.scale_vec(vin, g51.milli), vout, '--', \ label = r'$v_{OUT}$') ax2 = ax.twinx() ax2.set_ylabel(r'$I_C$ [mA]') ax2.plot(eee51.scale_vec(vin, g51.milli), eee51.scale_vec(ic1, g51.milli), \ ':', color='orangered', label = r'$I_C$') ax2.legend(loc='upper right') eee51.add_vline_text(ax, 0, 0, r'$V_{BE}$ = ' + \ '{:.1f}mV'.format(vbe1_used/g51.milli)) eee51.add_hline_text(ax, vo_dc, -75, \ r'$V_{OUT}=$' + '{:.2f}V'.format(vo_dc))
# open the transfer characteristics data file and get the data vbe = [] # declare list for vbe ic = [] # declare a list for ic with vce = vce,sat = 0.2V ic2 = [] # declare a list for ic with vce = 2.5V ib2 = [] # declare a list for ib with vce = 2.5V with open(cfg['transfer_data'], 'r') as f: for line in f: vbe.append(float(line.split()[0])) ic.append(float(line.split()[1])) ic2.append(float(line.split()[3])) ib2.append(float(line.split()[5])) # convert to mV and mA ic_mA = eee51.scale_vec(ic, g51.milli) vbe_mV = eee51.scale_vec(vbe, g51.milli) bjt_beta = [a / b for a, b in zip(ic2, ib2)] # bjt parameters from our dc characterization bjt_Is = 6.924988420125876e-13 bjt_n = 1.2610858394025979 g51.update_bjt_VA(-15.550605626760145) g51.update_bjt_vce(specs['vce']) # calculate the vbe needed for vce = 2.5V reqd_vbe = eee51.bjt_find_vbe(specs['ic'], specs['vce'], \ bjt_Is, bjt_n, g51.bjt_VA) # generate the ic for the ideal bjt model
# define the plot parameters plt_cfg = { 'grid_linestyle': 'dotted', 'title': r'Common Emitter CM Bias DC Transfer Curve', 'xlabel': r'$v_{in}$ [mV]', 'ylabel': r'$v_{out}$ [V]', 'legend_loc': 'upper left', 'add_legend': True, 'legend_title': None } # plot the amplifier transfer characteristics fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(eee51.scale_vec(vin, g51.milli), vout, '--', \ label = r'$v_{OUT}$') ax2 = ax.twinx() ax2.set_ylabel(r'$I_C$ [mA]') ax2.plot(eee51.scale_vec(vin, g51.milli), eee51.scale_vec(ic1, g51.milli), \ ':', color='orangered', label = r'$I_C$') ax2.legend(loc='upper right') eee51.add_vline_text(ax, 0, 0, r'$V_{IN}$ = ' + \ '{:.1f}mV'.format(0)) eee51.add_vline_text(ax, 10, 0, r'$V_{IN}$ = ' + \ '{:.1f}mV'.format(10))
# define the plot parameters plt_cfg = { 'grid_linestyle': 'dotted', 'title': 'BJT 2N2222A Output Characteristics (sim)', 'xlabel': r'$V_{CE}$ [V]', 'ylabel': r'$I_C$ [mA]', 'legend_loc': 'upper left', 'add_legend': False } # plot the output characteristics fig = plt.figure() ax = fig.add_subplot(1, 1, 1) for m, v in enumerate(vbe): ax.plot(vce, eee51.scale_vec(ic[m], g51.milli), \ label = '{:.2f}V'.format(v)) eee51.add_vline_text(ax, 0.2, 1.3, r'$V_{CE,sat}$=' + '{:.1f}V'.format(0.2)) # reorder the legend entries for easier reading handles, labels = ax.get_legend_handles_labels() ax.legend(handles[::-1], labels[::-1], title='$V_{BE}$', bbox_to_anchor=(1, 1)) eee51.label_plot(plt_cfg, fig, ax) plt.savefig('2N2222A_output.pdf') # plot the output characteristics and curve-fitted lines to show VA fig = plt.figure() ax = fig.add_subplot(1, 1, 1)
# plot the common mode characteristics fig = plt.figure() ax = fig.add_subplot(1, 1, 1) for cm_file, cm_label in zip(cm_files, cm_labels): vcm = [] itail = [] vop = [] with open(cm_file, 'r') as f: for line in f: vcm.append(float(line.split()[0])) itail.append(float(line.split()[1])) vop.append(float(line.split()[3])) ax.plot(vcm, eee51.scale_vec(itail, g51.milli), '-', \ label = cm_label) eee51.add_vline_text(ax, vicmin, 0, r'$V_{ic,\min}$ = ' + \ '{:.3f}'.format(vicmin)) eee51.add_vline_text(ax, vicmax, 0, r'$V_{ic,\max}$ = ' + \ '{:.3f}'.format(vicmax)) eee51.label_plot(plt_cfg, fig, ax) plt.savefig('diff_amp1_vcm_itail.png') dm_files = [cfg['transfer_vic=1.2'], \ cfg['transfer_vic=1.8'], \ cfg['transfer_vic=2.4']] vic_values = [1.2, 1.8, 2.4]
# define the plot parameters plt_cfg = { 'grid_linestyle': 'dotted', 'title': r'Common Emitter Amplifier DC Transient Response', 'xlabel': r'Time [ms]', 'ylabel': r'Voltage [V]', 'legend_loc': 'upper left', 'add_legend': True, 'legend_title': None } # plot the amplifier transfer characteristics fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(eee51.scale_vec(t, g51.milli), vin, '-', \ label = r'$v_{IN}$ = ' + '{:.2f} '.format(vinpp/g51.milli) + r'$mV_{p-p}$') ax.plot(eee51.scale_vec(t, g51.milli), vout, '-', \ label = r'$v_{OUT}$ = ' + '{:.2f} '.format(voutpp) + r'$V_{p-p}$') ax.set_ylim(0, 5) eee51.add_hline_text(ax, 682.7e-3, 0, \ r'$V_{IN}=$' + '{:.2f}mV'.format(682.7)) eee51.add_hline_text(ax, 2.58, 0, \ r'$V_{OUT}=$' + '{:.2f}V'.format(2.58)) ax.text(3.1, 4.5, r'$a_v=\frac{V_{OUT,p-p}}{V_{IN,p-p}}=$' + \ '{:.2f}'.format(voutpp/vinpp))
indexn, vin_simn = eee51.find_in_data(vid, -100e-6) # define the plot parameters plt_cfg = { 'grid_linestyle': 'dotted', 'title': r'3-Stage Op-Amp DC Transfer Curve', 'xlabel': r'$v_{id}$ [$\mu$V]', 'ylabel': r'Voltage [V]', 'legend_loc': 'lower left', 'add_legend': True, 'legend_title': None } fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(eee51.scale_vec(vid, g51.micro), vo1, '-', \ label = r'$v_{o1}$') ax.plot(eee51.scale_vec(vid, g51.micro), vo2, '-', \ label = r'$v_{o2}$') ax.plot(eee51.scale_vec(vid, g51.micro), vo3, '-', \ label = r'$v_{o3}$') eee51.add_vline_text(ax, 0, 0, \ '{:.2f}V'.format(0)) eee51.add_hline_text(ax, vo1[index], -750, \ r'{:.3f}V'.format(vo1[index])) eee51.add_hline_text(ax, vo2[index], -750, \ r'{:.3f}V'.format(vo2[index])) eee51.add_hline_text(ax, vo3[index], -750, \ r'{:.3f}V'.format(vo3[index]))
# define the plot parameters plt_cfg = { 'grid_linestyle': 'dotted', 'title': 'BJT 2N2222A Output Characteristics (sim)', 'xlabel': r'$V_{CE}$ [V]', 'ylabel': r'$I_C$ [mA]', 'legend_loc': 'upper left', 'add_legend': False } # plot the output characteristics fig = plt.figure() ax = fig.add_subplot(1, 1, 1) for m, v in enumerate(vbe): ax.plot(vce, eee51.scale_vec(ic[m], g51.milli), \ label = '{:.2f}V'.format(v)) eee51.add_vline_text(ax, 0.2, 1.3, r'$V_{CE,sat}$=' + '{:.1f}V'.format(0.2)) # reorder the legend entries for easier reading handles, labels = ax.get_legend_handles_labels() ax.legend(handles[::-1], labels[::-1], title='$V_{BE}$', bbox_to_anchor=(1, 1)) eee51.label_plot(plt_cfg, fig, ax) plt.savefig('2N2222A_output.png') # plot the output characteristics and curve-fitted lines to show VA fig = plt.figure() ax = fig.add_subplot(1, 1, 1)
# to get the rest of the BJT parameters, let's use the transfer characteristics # open the transfer characteristics data file and get the data vbe = [] # declare list for vbe ic2 = [] # declare a list for ic with vce = 2.5V # we'll use this to check our model ib2 = [] # declare a list for the base currents at vce = 2.5V with open(cfg['transfer_data'], 'r') as f: for line in f: vbe.append(float(line.split()[0])) ic2.append(float(line.split()[3])) ib2.append(float(line.split()[5])) # convert to mV vbe_mV = eee51.scale_vec(vbe, g51.milli) # plot the transistor dc beta g51.update_bjt_VA(-15.550605626760145) bjt_n = 1.2610858394025979 bjt_Is = 6.924988420125876e-13 # calculate the vbe needed for vce = 2.5V reqd_vbe = eee51.bjt_find_vbe(specs['ic'], specs['vce'], \ bjt_Is, bjt_n, g51.bjt_VA) bjt_beta = [a / b for a, b in zip(ic2, ib2)] index, vbe_sim = eee51.find_in_data(vbe, reqd_vbe) plt_cfg = {