In [1]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
import math
In [2]:
dirPath = os.path.realpath('.')
fileName = 'rawData/lab 6 measurements (2).xlsx'
filePath = os.path.join(dirPath, fileName)
df = pd.read_excel(filePath,sheetname="Part1",header=0)
print(df)
cols = df.columns
In [3]:
plt.figure(1)
plt.errorbar(df[cols[0]],df[cols[2]],xerr=2*df[cols[1]],yerr=2*df[cols[3]])
plt.errorbar(df[cols[4]],df[cols[6]],xerr=2*df[cols[5]],yerr=2*df[cols[7]])
plt.title('Voltage vs delta h')
plt.xlabel('delta h (cm)')
plt.ylabel('Voltage (mV)')
plt.legend(['Ramp Down','Ramp Up'])
plt.grid()
plt.savefig('pressure.png')
plt.show()
In [4]:
plt.figure(1)
plt.errorbar(df[cols[0]],df[cols[2]],xerr=2*df[cols[1]],yerr=2*df[cols[3]])
plt.errorbar(df[cols[4]],df[cols[6]],xerr=2*df[cols[5]],yerr=2*df[cols[7]])
plt.title('Voltage vs delta h (Hysteresis Effects)')
plt.xlabel('delta h (cm)')
plt.ylabel('Voltage (mV)')
plt.legend(['Ramp Down','Ramp Up'])
plt.axis([-10,1,-50,5])
plt.grid()
plt.savefig('pressureHysteresis.png')
plt.show()
In [5]:
sensitivity = df['V (mV)'][1:]/df['deltah(cm)'][1:]
print('sensitivity =',np.average(sensitivity), 'mV/cm')
sens_error = np.sqrt((df['error(cm)'][1:]/df['V (mV)'][1:])**2 + (df['error (mV)'][1:]/df['deltah(cm)'][1:])**2)*sensitivity
print('sensitivity error =', np.average(sens_error), 'mV/cm')
In [6]:
sensitivity_h = df['V (mV).1'][0:10]/df['deltah(cm).1'][0:10]
print(sensitivity_h)
print('sensitivity =',np.average(sensitivity_h), 'mV/cm')
sens_error_h = np.sqrt((df['error(cm).1'][0:10]/df['V (mV).1'][0:10])**2 + (df['error (mV)'][0:10]/df['deltah(cm).1'][0:10])**2)*sensitivity_h
print('sensitivity error =', np.average(sens_error_h), 'mV/cm')
In [7]:
hysteresisOffset = df[cols[1]][0]-df[cols[6]][len(df[cols[4]])-1]
print('Hysteresis Offset =', hysteresisOffset,'mV')
hysteresisError = np.sqrt(1**2 + 1**2)
print('Hysteresis Error =',hysteresisError, 'mV')
In [8]:
dfangle = pd.read_excel(filePath,sheetname="accelAngle",header=0)
print(dfangle)
colsangle = dfangle.columns
In [9]:
plt.figure(2)
plt.errorbar(dfangle[colsangle[2]],dfangle[colsangle[0]],xerr=2*dfangle[colsangle[3]],yerr=2*dfangle[colsangle[1]])
plt.grid()
plt.title('Voltage vs Angle')
plt.ylabel('Angle (degrees)')
plt.xlabel('Voltage (mV)')
plt.savefig('VoltAngle.png')
plt.show()
In [10]:
accArray = []
accArrayError = []
for i in range(0,len(dfangle[colsangle[0]])):
accArray.append(math.cos(math.radians(np.array(dfangle[colsangle[0]][i]))))
for i in range(0,len(dfangle[colsangle[0]])):
accArrayError.append(math.sin(math.radians(np.array(dfangle[colsangle[0]][i]))))
acc = 9.8*np.array(accArray)
accError=9.8*math.radians(1)*np.array(accArrayError)
plt.figure(3)
plt.errorbar(dfangle[colsangle[2]],acc,xerr=2*dfangle[colsangle[3]],yerr= accError)
plt.grid()
plt.title('Voltage vs Acceleration')
plt.ylabel('Acceleration (m/s$^2$)')
plt.xlabel('Voltage (mV)')
plt.savefig('VoltAcceleration.png')
plt.show()
In [11]:
dfstatic = pd.read_excel(filePath,sheetname="staticMeasurements",header=0)
print(dfstatic)
colsstatic = dfstatic.columns
In [12]:
gravity = 9.81 # m/s/s
kstatic = dfstatic['Force']/dfstatic['disp (m)']
print('kstatic')
print(kstatic)
kstatic_error = kstatic*np.sqrt((dfstatic['Force Error']/dfstatic['Force'])**2 + (dfstatic['error (cm)']/dfstatic['Displacement (cm)'])**2)
print('\n error in kstatic =')
print(kstatic_error)
In [13]:
dfdynamic = pd.read_excel(filePath,sheetname="dynamicMeasurements",header=0)
print(dfdynamic)
colsdynamic = dfdynamic.columns
NOTE: We also need to define the mass
In [14]:
MASS = 0.2772
In [15]:
kdynamic = MASS*dfdynamic['omega']**2
print('kdynamic =')
print(kdynamic)
# now calculate error
num = range(0,5)
kdynamic_error = dfdynamic['error']/dfdynamic['freq (Hz)']*kdynamic*2
print('\nkdynamic error =')
print(kdynamic_error)
In [16]:
plt.figure(4)
plt.errorbar(num,kdynamic,yerr=kdynamic_error,fmt='o')
plt.title('Kdynamic, multiple calculations')
plt.xlabel('Trial Number')
plt.ylabel('k dynamic (N/m)')
plt.legend(['k dynamic'])
plt.axis([-0.1,4.1,0,55])
plt.grid()
plt.savefig('kdynamic.png')
plt.show()
In [17]:
dfWheat = pd.read_excel(filePath,sheetname="Wheatstone",header=0)
print(dfWheat)
colsWheat = dfWheat.columns
In [23]:
R3 = np.linspace(110,130,11)
R1 = 120
R2 = 120
R4 = 120
expectedVout = 30*(R2/(R2+R1)-R4/(R3+R4))
print(expectedVout)
In [19]:
wheatArray = []
for i in range(0,len(dfWheat[colsWheat[0]])):
wheatArray.append(1/(np.array(dfWheat[colsWheat[0]][i])+120))
plt.figure(5)
plt.plot()
plt.errorbar(wheatArray,dfWheat[colsWheat[1]],xerr=0,yerr=2*dfWheat[colsWheat[2]])
plt.grid()
plt.title('Resistance vs Bridge Output Voltage')
plt.ylabel('Voltage (V)')
plt.xlabel('1/(R$_x$ + 120) (mho)')
plt.savefig('Wheatstone.png')
plt.show()