def Angle_calibration(plot1=False, plot2=False, printA=False): plt.close('all') angle_data = np.load(nppath + "angle_cal.npy") X = angle_data[:, 0] # sec Y = angle_data[:, 1] # mRad x_minima = [62, 178, 293, 407] # sec x_maxima = [120, 235, 350] # sec minima, maxima = dg.extrema(X, Y, 10, x_minima, x_maxima) ext = minima + maxima ext = dg.sort(np.array(ext), 0) if plot1 == True: # '0_1_Angles_cal', angles for angle calibration # plots: X , Y , style , label p1 = dp.data(X, Y, '-', 'b', '$\\theta_{comp}$') p2 = dp.data(ext[:, 0], ext[:, 1], 'r*', 'r', 'Extrema') ax = dp.ax([p1, p2], 111, 'time [sec]', "$\\theta_{comp}$ [mRad]", "$\\theta_{comp}$ for Angle Calibration") dp.plot([ax], name=gp + '0_1_Angles_cal') X_data, Y_data = AuxOne(L.val, S.val, ext[:, 1]) m, m_err = df.m_exp(X_data, Y_data), df.sig_m(X_data, Y_data) b, b_err = df.b_exp(X_data, Y_data), df.sig_b(X_data, Y_data) m_err_p, b_err_p = m_err * 100 / m, b_err * 100 / b r2 = df.R2(X_data, Y_data) X_lin = np.linspace(0, max(X_data) + 10, 1000) Y_lin = df.lin_fit(X_data, Y_data, X_lin) if plot2 == True: p1 = dp.data(X_data, Y_data, 'bs', 'b', 'Laser vs Comp') p2 = dp.data(X_lin, Y_lin, 'r-', 'r', 'Linear Fit') n2 = dp.note( "Y = C x + B\nm = %s $\pm$ %s\nb = %s $\pm$ %s\nR$^2$ = %s" % (round(m, 2), round(m_err, 2), round(b, 1), round( b_err, 1), round(r2, 5)), 20, 7, p2.color) ax = dp.ax([p1, p2], 111, '$\\theta_{comp}$ [mRad]', '$\\theta_{laser}$ [mRad]', '$\\theta_{laser}$ vs. $\\theta_{comp}$') ax.notes = [n2] dp.plot([ax], name=gp + '0_2_laser_vs_comp') if printA == True: print("") print("Calibrtion:") print("theta_comp = %s" % X_data) print("theta_laser = %s" % Y_data) print("calibration constant = %s +/- %s (%s)" % (m, m_err, m_err_p)) print("intercept = %s +/- %s (%s)" % (b, b_err, b_err_p)) print("R2 = %s" % r2) print("") return m, m_err
def part3(printA=True,saveA=True,figsize=(15,15), fs=20, lw=2): print("") print("Part III") # compare G2 = 1*10*100 R = 10e3 # Ohm delta_f = 110961 # Hz vout = .94 # V vrms_conv = out2rms(G2,vout) # V vrms_calc = v_rms(delta_f,k_default,R_default) vrms, perr = err(vrms_conv,vrms_calc) if printA == True: print("compare") print("v_out = ", vout) print("v_rms_conv = ", vrms_conv) print("v_rms_calc = ", vrms_calc) print("v_rms = %s +/- %s V (%s percent)" % (vrms.pval,vrms.perr,perr) ) print("") # amplifier noise R = np.array([ 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6 ]) G2 = np.array([ 10*10*20, 10*10*20, 10*10*20, 10*10*20, 10*10*10, 1*10*40, 1*10*30 ]) VOUT = np.array([ .9727, .9722, .9715, .9718, .9743, .9773, .9747, .9755, 1.0005, 1.0025, .9998, 1.0010, 1.2441, 1.2492, 1.2468, 1.2435, .9323, .9319, .9355, .9337, .8912, .8882, .8863, .8877, .9585, .9550, .9595, .9650 ]).reshape([7,4]) VOUT = np.array([ np.average(VOUT[i]) for i in range(7) ]) Y_data = ( VOUT * (1e6)**2 ) / ( gain(G2)**2) # micro V^2 X_fit = np.linspace(0, 2e4, 1000) # Ohm cutoff = 2 # num Y_fit, m, b = df.lin_fit( R[:-cutoff] , Y_data[:-cutoff] , X_fit ) # micro V^2 R2 = df.R2(R[:-cutoff],Y_data[:-cutoff]) # num amp = np.sqrt(b.val) amp_err = b.err/(2*np.sqrt(b.val)) ampN = dg.var( amp,amp_err ) # micro V fig = plt.figure(figsize=figsize) plt.title('Part III: Amplifier Noise', fontsize=fs+2) plt.xlabel('R [$\\Omega$]', fontsize=fs) plt.ylabel('<Vj$^2$> [$\\mu$ V$^2$]', fontsize=fs) plt.xlim(min(X_fit),max(X_fit)) plt.plot(R[:-cutoff],Y_data[:-cutoff], 'bo', markersize=15, label='data') plt.plot(X_fit,Y_fit, color='r', lw=lw, label='fit') note = '$Vj^2 = mR + b$\n$m = %s \pm %s\ \\mu\ V^2/\\Omega$\n$b = %s \pm %s\ \\mu\ V^2$\n$R^2 = %s$' % (m.pval,m.perr,b.pval,b.perr,round(R2,6) ) plt.annotate(note, xy=(1e3,35), color='r', fontsize=fs) note2 = 'Pre-Amp Noise = $\sqrt{b} \pm \\Delta b/(2 \sqrt{b})$\n $= %s \pm %s\ \\mu V$' % (ampN.pval,ampN.perr) plt.annotate(note2, xy=(1e3,30), color='m', fontsize=fs+2) plt.legend(loc='best', fontsize=fs) if saveA == True: fig.savefig('../graphs/fig02.png') plt.close(fig) else: plt.show(fig) if printA == True: print('amplifier noise') print('R = %s Ohm' % R) print('Vj^2 = %s micro V^2' % Y_data ) print("The best fit was found by not considering the last %s data points" % cutoff ) print("n = %s +/- %s micro V^2/Ohm" % (m.pval,m.perr) ) print("b = %s +/- %s micro V^2/Ohm") print('amplifer noise = %s +/- %s micro V^2' % (ampN.pval,ampN.perr) ) print('') # experimental k DELTA_f = np.array([ 355, 1077, 3554, 10774, 35543, 107740 ]) # Hz G2 = np.array([ 10*10*60, 10*10*40, 10*10*20, 10*10*10, 1*10*60, 1*10*40 ]) VOUT = np.array([ .8, 1.0, .9, .7, .8, .9 ]) # V R = 100e3 # Ohm Y_data = ( VOUT * (1e9)**2 ) / ( gain(G2)**2 * 4 * R * T_room ) # nV^2/Ohm/K X_fit = np.linspace(0,120000,1000) # Hz Y_fit, m, b = df.lin_fit( DELTA_f , Y_data , X_fit ) R2 = df.R2(DELTA_f,Y_data) kval = m.val/(1e9)**2 # J/K kval_err = m.err/(1e9)**2 k = dg.var( kval,kval_err ) fig = plt.figure(figsize=figsize) plt.title('Part III: Bolzmann Constant', fontsize=fs+2) plt.xlabel('$\\Delta$ f [Hz]', fontsize=fs) plt.ylabel('<Vj$^2$>/R/T [nV$^2$/$\\Omega$/K]', fontsize=fs) plt.xlim(min(X_fit),max(X_fit)) plt.plot(DELTA_f,Y_data, 'bo', markersize=15, label='data') plt.plot(X_fit,Y_fit, color='r', lw=lw, label='fit') note = '$V^2 = m f + b$\n$m = %s \pm %s\ nV^2/ \\Omega/ K / Hz$\n$b = %s \pm %s\ nV^2/ \\Omega/ K$\n$R^2 = %s$' % (m.pval,m.perr,b.pval,b.perr,round(R2,3) ) plt.annotate(note, xy=(1.5e3,1.2), color='r', fontsize=fs) note2 = '$k = (m \pm \\Delta m)/(1_{+9})^2$\n $= %s \pm %s\ J/K$' % (k.pval,k.perr) plt.annotate(note2, xy=(1.5e3,1), color='m', fontsize=fs+2) plt.legend(loc='best', fontsize=fs) if saveA == True: fig.savefig('../graphs/fig03.png') plt.close(fig) else: plt.show(fig) if printA == True: print("Bolzmann constant") print("m = %s +/- %s 1e18 J/K" % (m.pval,m.perr) ) print("k = %s +/- %s J/K" % (k.pval,k.perr) ) return
def part4(printA=True,saveA=True,figsize=(15,15),fs=20,lw=2): print("") print("Part IV:") R = np.array([ 10, 10e3 ]) # Ohm G2 = np.array([ 10*10*20, 10*10*10 ]) # JOHNSON NOISE AT T_room with A_ext and B_ext VOUT = np.array([ np.average([.9831, .9843, .9841, .9820]), np.average([.7650, .7653, .7669, .7662]) ]) # V^2 Y_data = ( VOUT * (1e6)**2 ) / (gain(G2)**2) # (micro V)^2 X_fit = np.linspace(0, 11e3, 1000) # Ohm Y_fit, m, b = df.lin_fit( R , Y_data , X_fit ) R2 = df.R2(R,Y_data) mval = round(m.val,4) merr = 5e-4 bval = round(b.val,1) berr = .5 noise = round(np.sqrt(b.val),1) # micro V^2 noise_err = round(berr/(2*np.sqrt(b.val)),1) # ampN = dg.var( noise,noise_err ) fig = plt.figure(figsize=figsize) plt.title('Part IV: Amplifier Noise from A$_{ext}$ and B$_{ext}$', fontsize=fs+2) plt.xlabel('R [$\\Omega$]', fontsize=fs) plt.ylabel('<Vj$^2$> [$\\mu$V$^2$]', fontsize=fs) plt.xlim(min(X_fit),max(X_fit)) plt.plot(R,Y_data, 'bo', markersize=15, label='data') plt.plot(X_fit,Y_fit, color='r', lw=lw, label='fit') note = '$Vj^2 = mR + b$\n$m = %s \pm %s\ \\mu V^2/\\Omega$\n$b = %s \pm %s\ \\mu V^2$\n$R^2 = %s$' % (mval,merr,bval,berr,round(R2,4) ) plt.annotate(note, xy=(1e2,19), color='r', fontsize=fs) note2 = 'Pre-Amp Noise = $\sqrt{b} \pm \\Delta b/(2 \sqrt{b})$\n $= %s \pm %s\ \\mu V$' % (noise,noise_err) plt.annotate(note2, xy=(1e2,17), color='m', fontsize=fs+2 ) plt.legend(loc='best', fontsize=fs) if saveA == True: fig.savefig('../graphs/fig04.png') plt.close() else: plt.show() if printA == True: print('amplifier noise from Aext and Bext') print('it was found that Cext did not measure at an correct value and was discarded.') print('m = %s +/- %s micro V^2/Hz' % (mval,merr) ) print('b = %s +/- %s micro V^2' % (bval,berr) ) print('amplifer noise = %s +/- %s micro V' % (noise,noise_err) ) print('') # experimental k at T = 77 K VOUT2 = np.array([ np.average([.9825, .9832, .9804, .9827]), np.average([.3909, .3905, .3905, .3911]) ]) # V^2 Y_data2 = ( VOUT2 * (1e9)**2 ) / (gain(G2)**2 * 4 * 77 * 110961 ) # nV^2 / K / Hz Y_fit2, m, b = df.lin_fit( R , Y_data2 , X_fit ) R22 = df.R2(R,Y_data2) bval = round(b.val,2) berr = .05 mval = round(m.val,6) merr = 5e-6 kval = round(m.val/(1e9)**2,24) # J/K kerr = round(merr/(1e9)**2,24) # k = dg.var( kval,kval_err ) fig = plt.figure(figsize=figsize) plt.title('Part IV: Boltzmann Constant at 77 K', fontsize=fs+2) plt.xlabel('R [$\\Omega$]', fontsize=fs) plt.ylabel('[nVj$^2$/K/Hz]', fontsize=fs) plt.xlim(min(X_fit),max(X_fit)) plt.plot(R,Y_data2, 'bo', markersize=15, label='data') plt.plot(X_fit,Y_fit2, color='r', lw=lw, label='fit') note = '$nVj^2/T/\\Delta f = mR + b$\n$m = %s \pm %s\ nV^2/K/Hz/\\Omega$\n$b = %s \pm %s\ nV^2/K/Hz$\n$R^2 = %s$' % (mval,merr,bval,berr,round(R22,4) ) plt.annotate(note, xy=(1e2,3e-1), color='r', fontsize=fs) note2 = '$k = (m \pm \\Delta m)/(1_{+9})^2$\n $= %s \pm %s\ J/K$' % (kval,kerr) plt.annotate(note2, xy=(1e2, 2.8e-1), color='m', fontsize=fs+2) plt.legend(loc='best', fontsize=fs) if saveA == True: fig.savefig('../graphs/fig05.png') plt.close() else: plt.show() if printA == True: print('Bolzmann Constant at 77 K') print('it was found that Cext did not measure at an correct value and was discarded.') print('experimental k = %s +/- %s J/m' % (kval,kerr) ) print('')