-
Notifications
You must be signed in to change notification settings - Fork 0
/
hydroflask_water_mode_analysis.py
69 lines (57 loc) · 2.08 KB
/
hydroflask_water_mode_analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# %%
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
# %%
mode_data = np.loadtxt('hydroflask_water_modes.csv', dtype=np.complex128)
# %%
x = np.linspace(0, 1, 7)
x_long = np.linspace(0, 1, 100)
def rev_sigmoid(x, a, b, c, d):
return c * (1.0 - (1.0 / (1.0 + np.exp(-b*(x-a))))) + d
# %%
plt.figure()
mode_freqs = np.flip(np.abs(mode_data[:,0]))
plt.scatter(x, mode_freqs, marker='x', color='r', label='Measured')
popt, pcov = curve_fit(rev_sigmoid, x, mode_freqs, bounds=([0, 1, -100, -200], [1, 100, 100, 200]))
plt.plot(x_long, rev_sigmoid(x_long, *popt), label='Model')
print(popt)
# plt.title('First mode frequency vs water amount')
plt.ylabel('Frequency [Hz]')
plt.xlabel('Water as fraction of bottle volume')
plt.xticks(x, ['0', '1/32', '1/16', '1/8', '1/4', '1/2', '1'])
plt.legend()
plt.grid()
plt.savefig('Figures/Water_Freq.png')
# %%
plt.figure()
colors = ['r', 'k']
for i in range(2):
mode_damps = np.abs(mode_data[:,40+i])
tau_gains = np.exp(-1.0 / mode_damps)
t60s = np.log(0.001) / (48000 * np.log(tau_gains))
plt.scatter(x, t60s, label='Mode #{}'.format(i+1), marker='x', color=colors[i])
mode_damps1 = np.mean(np.abs(mode_data[:,40:41]), axis=1)
mode_damps2 = np.mean(np.abs(mode_data[:,41:42]), axis=1)
mode_damps_avg = np.mean(np.abs(mode_data[:,40:42]), axis=1)
# # plt.plot(x, mode_damps, label='Avg')
def model_mode_damp(mode_damps, label, order=4):
z_damp = np.polyfit(x, mode_damps, order)
p_damp = np.poly1d(z_damp)
tau_gains = np.exp(-1.0 / p_damp(x_long))
t60s = np.log(0.001) / (48000 * np.log(tau_gains))
plt.plot(x_long, t60s, label=label)
# print('Damp function:')
# print(p_damp)
model_mode_damp(mode_damps1, 'Mode 1 Model', 5)
model_mode_damp(mode_damps2, 'Mode 2 Model', 5)
# model_mode_damp(mode_damps_avg, 'Avg Model')
plt.legend()
# plt.title('First 2 modes damping vs water amount')
plt.ylabel(r'$T_{60}$ [seconds]')
plt.xlabel('Water as fraction of bottle volume')
plt.xticks(x, ['0', '1/32', '1/16', '1/8', '1/4', '1/2', '1'])
plt.grid()
plt.savefig('Figures/Water_Damping.png')
# %%
plt.show()