我正在尝试对不同温度传感器进行线性组合,并用应变传感器将其弯曲。
我所做的是我可以将一个温度传感器和一个应变传感器装配在一起。
但是我不知道如何在一个应变传感器上对不同温度传感器进行线性组合。
这是我的尝试:
LocalDate ld = odt.toLocalDate() ;
答案 0 :(得分:2)
作为两个温度传感器的“概念验证” (在这里既不要喧noise,也不要考虑现实的参数):
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import leastsq
def strain( t, a, b, c, d ):
return a * t**3 + b * t**2 + c * t + d
def residuals( params, x1Data, x2Data, yData ):
s1, s2, a, b, c, d = params
cxData = [ (s1**2 * x1 + s2**2 * x2) /( s1**2 + s2**2 ) for x1, x2 in zip( x1Data, x2Data) ]
diff = [ strain( x, a, b, c, d ) -y for x, y in zip( cxData, yData ) ]
return diff
timeList = np.linspace( 0, 25, 55 )
t1List = np.fromiter( ( 5 + 25. * (1 - np.exp( -t / 9. ) )for t in timeList ), np.float )
t2List = np.fromiter( (30. * (1 - np.exp( -t / 7. ) ) * ( 1 - np.exp( -t / 3. ) ) for t in timeList ), np.float )
combinedList = np.fromiter( ( (.7 * a + .2 * b)/.9 for a, b in zip( t1List, t2List ) ), np.float )
strainList = np.fromiter( ( strain( t, .01, -.1, .88, .2 ) for t in combinedList ), np.float )
fit, ier = leastsq( residuals, [.71,.22, 0,0, .1, .1 ], args=( t1List, t2List, strainList ), maxfev=5000 )
print fit
fittedT = [ (fit[0]**2 * x1 + fit[1]**2 *x2 ) /( fit[0]**2 + fit[1]**2 ) for x1, x2 in zip( t1List, t2List) ]
fittedS = [ strain( t, *(fit[2:]) ) for t in fittedT ]
fig = plt.figure()
ax = fig.add_subplot( 3, 1, 1 )
bx = fig.add_subplot( 3, 1, 2 )
cx = fig.add_subplot( 3, 1, 3 )
ax.plot( timeList, t1List )
ax.plot( timeList, t2List )
ax.plot( timeList, combinedList )
bx.plot( combinedList, strainList, linestyle='', marker='x' )
bx.plot( fittedT, fittedS )
cx.plot( timeList, fittedT ,'--')
cx.plot( timeList, combinedList,':' )
plt.show()
给予
[ 4.21350842e+03 2.25221499e+03 1.00000000e-02 -1.00000000e-01 8.80000000e-01 2.00000000e-01]
并显示:
顶部:温度1(蓝色)和2(橙色)以及线性组合(绿色) 中心:“模拟数据”(蓝色)和适合度(橙色) 底部:适合温度(蓝色),真实温度(橙色)
根据实际数据,可能需要一些摆弄。