Lab 6: Calculations

Part 1: Differential Pressure Measurments


In [1]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os

In [2]:
dirPath = os.path.realpath('.')
fileName = 'rawData/lab 6 measurements.xlsx'
filePath = os.path.join(dirPath, fileName)
df = pd.read_excel(filePath,sheetname="Part1",header=0)
print(df)
cols = df.columns


    deltah(cm)  error(cm)  V (mV)  error (mV)  deltah(cm).1  error(cm).1  \
0            0          1       1           1           -75            1   
1           -5          1     -17           1           -70            1   
2          -10          1     -34           1           -65            1   
3          -15          1     -54           1           -60            1   
4          -20          1     -67           1           -55            1   
5          -25          1     -86           1           -50            1   
6          -30          1    -106           1           -45            1   
7          -35          1    -122           1           -40            1   
8          -40          1    -141           1           -35            1   
9          -45          1    -160           1           -30            1   
10         -50          1    -177           1           -25            1   
11         -55          1    -194           1           -20            1   
12         -60          1    -213           1           -15            1   
13         -65          1    -232           1           -10            1   
14         -70          1    -251           1            -5            1   
15         -75          1    -270           1             0            1   

    V (mV).1  error(mV)  
0       -270          1  
1       -255          1  
2       -239          1  
3       -222          1  
4       -206          1  
5       -189          1  
6       -171          1  
7       -155          1  
8       -136          1  
9       -119          1  
10      -102          1  
11       -84          1  
12       -66          1  
13       -48          1  
14       -32          1  
15       -15          1  

Plotting


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()


Plot again, but zoom in so that error bars are visible


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()


Sensitivity Calculations


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')


sensitivity = 3.51078806379 mV/cm
sensitivity error = 0.159453662338 mV/cm

Sensitivity with Hysteresis Effects Calculations


In [6]:
sensitivity_h = (270+df['V (mV).1'][1:10])/(75+df['deltah(cm).1'][1:10])
print(sensitivity_h)
print('sensitivity =',np.average(sensitivity_h), 'mV/cm')

sens_error_h = np.sqrt((df['error(cm).1'][1:10]/df['V (mV).1'][1:10])**2 + (df['error (mV)'][1:10]/df['deltah(cm).1'][1:10])**2)*sensitivity_h
print('sensitivity error =', np.average(sens_error_h), 'mV/cm')


1    3.000000
2    3.100000
3    3.200000
4    3.200000
5    3.240000
6    3.300000
7    3.285714
8    3.350000
9    3.355556
dtype: float64
sensitivity = 3.22569664903 mV/cm
sensitivity error = 0.0723568696015 mV/cm

In [7]:
# difference in sensitivity
diff = np.abs(np.average(sensitivity_h)-np.average(sensitivity))
diff_error = np.sqrt(np.average(sens_error_h)**2 + np.average(sens_error)**2)
print('difference in sens =',diff)
print(diff_error)


difference in sens = 0.285091414758
0.175102789845

Effects of Hysteresis


In [8]:
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')


Hysteresis Offset = 16 mV
Hysteresis Error = 1.41421356237 mV

Part 2: Accelerometer Angle Measurements

Make a new data frame dfangle to hold the data from the accelAngle sheet.


In [9]:
dfangle = pd.read_excel(filePath,sheetname="accelAngle",header=0)
print(dfangle)
colsangle = dfangle.columns


    Angle (deg)  error  Voltage (mV)  error.1
0            90      1           0.7      0.5
1            80      1         130.0      0.5
2            70      1         246.0      0.5
3            60      1         362.0      0.5
4            50      1         468.0      0.5
5            40      1         556.0      0.5
6            30      1         628.0      0.5
7            20      1         681.0      0.5
8            10      1         716.0      0.5
9             0      1         728.0      0.5
10           10      1         715.0      0.5
11           20      1         680.0      0.5
12           30      1         630.0      0.5
13           40      1         557.0      0.5
14           50      1         467.0      0.5
15           60      1         361.0      0.5
16           70      1         247.0      0.5
17           80      1         129.0      0.5
18           90      1           0.9      0.5

In [10]:
plt.figure(2)
plt.errorbar(dfangle[colsangle[0]],dfangle[colsangle[2]],xerr=2*dfangle[colsangle[1]],yerr=2*dfangle[colsangle[3]])
plt.grid()
plt.title('Voltage vs Angle')
plt.xlabel('Angle (degrees)')
plt.ylabel('Voltage (mV)')
plt.savefig('accelAngle.png')
plt.show()


Calculate Accelerometer Sensitivity


In [11]:
Vout = dfangle['Voltage (mV)'][1:8]
accelSensitivity = Vout/(np.cos(np.deg2rad(dfangle['Angle (deg)'][1:8])))
accelError = np.sqrt(1/30**2 + 0.5/628**2)*727
print('Accel Sensitivity =',np.average(accelSensitivity), 'mV/g')
print('Accel Error =', accelError, 'mV/g')
print(accelSensitivity)
print('std dev.', np.std(accelSensitivity))
print('variance', np.var(accelSensitivity))

dfangle['Voltage (mV)']


Accel Sensitivity = 727.948321464 mV/g
Accel Error = 24.2471547499 mV/g
1    748.640163
2    719.255882
3    724.000000
4    728.078751
5    725.806453
6    725.151938
7    724.705063
dtype: float64
std dev. 8.801324046028146
variance 77.46330496319327
Out[11]:
0       0.7
1     130.0
2     246.0
3     362.0
4     468.0
5     556.0
6     628.0
7     681.0
8     716.0
9     728.0
10    715.0
11    680.0
12    630.0
13    557.0
14    467.0
15    361.0
16    247.0
17    129.0
18      0.9
Name: Voltage (mV), dtype: float64

Part 2: Static Measurements


In [12]:
dfstatic = pd.read_excel(filePath,sheetname="staticMeasurements",header=0)
print(dfstatic)
colsstatic = dfstatic.columns


   mass added  Mass(kg)     Force  Force Error  Displacement (cm)  error (cm)  \
0      0.0000    0.1316  1.290996     0.129100                0.5        0.05   
1      0.0935    0.2251  2.208231     0.061340                1.8        0.05   
2      0.1097    0.3348  3.284388     0.049763                3.3        0.05   
3      0.1456    0.4804  4.712724     0.045315                5.2        0.05   
4      0.1486    0.6290  6.170490     0.040068                7.7        0.05   

   disp (m)  
0    0.0005  
1    0.0018  
2    0.0033  
3    0.0052  
4    0.0077  

In [13]:
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)


kstatic
0    2581.992000
1    1226.795000
2     995.269091
3     906.293077
4     801.362338
dtype: float64

 error in kstatic =
0    365.148810
1     48.193059
2     21.326107
3     12.323961
4      7.359075
dtype: float64

Part 2: Dynamic Measurements


In [14]:
dfdynamic = pd.read_excel(filePath,sheetname="dynamicMeasurements",header=0)
print(dfdynamic)
colsdynamic = dfdynamic.columns


   freq (Hz)  error  period  error.1      omega
0       2.17   0.05     440       20  13.634512
1       2.08   0.05     470       20  13.069025
2       2.17   0.05     480       20  13.634512
3       2.22   0.05     440       20  13.948671
4       2.17   0.05     460       20  13.634512

NOTE: We also need to define the mass


In [15]:
MASS = 0.2772

Now lets calculate $k_{dynamic}$


In [16]:
kdynamic = MASS*dfdynamic['omega']**2
print('kdynamic =')
print(kdynamic)
print(np.average(kdynamic))

# now calculate error
num = range(0,5)
kdynamic_error = dfdynamic['error']/dfdynamic['freq (Hz)']*kdynamic*2
print('\nkdynamic error =')
print(kdynamic_error)
print(np.average(kdynamic_error))

print(np.var(kdynamic))


kdynamic =
0    51.531458
1    47.345601
2    51.531458
3    53.933538
4    51.531458
Name: omega, dtype: float64
51.1747026143

kdynamic error =
0    2.374722
1    2.276231
2    2.374722
3    2.429439
4    2.374722
dtype: float64
2.36596683387
4.531003334068481

In [17]:
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()