简体   繁体   English

方程拟合数据点

[英]Equation to fit data points

I have an interesting problem and need some coding help. 我有一个有趣的问题,需要一些编码帮助。 I have a hardware DAC that is used to drive a current source. 我有一个用于驱动电流源的硬件DAC。 By setting a particular DAC value I get a particular current reading. 通过设置特定的DAC值,我可以获得特定的电流读数。 This is also dependant on the overall supply voltage. 这也取决于整个电源电压。

The overall objective is to set a desired current in the source I need to calculate the DAC value. 总体目标是在需要计算DAC值的电源中设置所需的电流。 The item is a piece of test equipment so during the calibration phase I read all the currents for the DAC value at a specified voltage. 该项目是一台测试设备,因此在校准阶段,我会在指定电压下读取DAC值的所有电流。 This is all good and in the past I have simply done a simple calculation to get the Y=aX+c and calculated a and c where X is the desired current and Y is the DAC value. 这一切都很好,过去我只是简单地进行了一个简单的计算以获得Y = aX + c并计算了a和c,其中X是所需电流,Y是DAC值。 Line of best fit simple enough and worked ok. 最佳拟合线足够简单并且可以正常工作。 However I now need to improve the accuracy considerably. 但是,我现在需要大大提高准确性。

The plot of DAC and Current is basically linear but in the middle range there is a hump only small but enough to limit the accuracy to 2% I need 0.1% for this version of the hardware, I can get up to 2048 sample points so a good range of data. DAC和电流的图基本上是线性的,但在中间范围内只有一个小峰,但足以将精度限制为2%。对于此版本的硬件,我需要0.1%,我最多可以得到2048个采样点,因此良好的数据范围。

I am hoping that a second or third order polynomial representation of the characteristics will help to improve the accuracy. 我希望特征的二阶或三阶多项式表示将有助于提高精度。 While the maths is not beyond me the coding is! 虽然数学并不超出我的范围,但是编码却是我的! Basically I am an embedded hardware engineer, the C# coding takes me a little longer to get my mind around. 基本上,我是一名嵌入式硬件工程师,C#编码使我花了更长的时间才能理解。 The hardware is an embedded Atmel processor the calibration coding is done using Visual Studio talking to external reference meters and the target hardware. 硬件是嵌入式Atmel处理器,使用与外部参考仪表和目标硬件的Visual Studio进行校准编码。

Basically the polynomial equation will sit in the target hardware using the coefficients calculated during calibration. 基本上,多项式方程式将使用在校准期间计算出的系数放置在目标硬件中。

So any help would be appreciated! 因此,任何帮助将不胜感激! Mark 标记

One could also try a rational function, cubic divided by quadratic. 也可以尝试一种有理函数,三次除以二次。 Asymptotically linear, with the possibility for a bump in the middle. 渐近线性,中间可能会发生颠簸。

For instance, 1+x+0.01/(1+x²) is of that form. 例如, 1+x+0.01/(1+x²)就是这种形式。

The general formula is y = (a*x³+b*x²+c*x+d)/(e*x²+f*x+1) . 通式为y = (a*x³+b*x²+c*x+d)/(e*x²+f*x+1) To get a form that is linear in the coefficients, multiply with the denominator to get 要获得系数线性的形式,请与分母相乘得到

0 = a*x³+b*x²+c*x+d - e*x²y-f*xy-y

This gives a coefficient matrix with rows 这给出了带有行的系数矩阵

[ x³, x², x, 1, -x²*y, -x*y, -y ]

for each data point (x, y)=(x[k], y[k]) . 对于每个数据点(x, y)=(x[k], y[k]) Then apply QR decomposition to this matrix and solve R*v=0 for v=[ a, b, c, d, e, f, 1]^T (obviously disregarding the last 7th row of the system). 然后将QR分解应用于该矩阵,并针对v=[ a, b, c, d, e, f, 1]^T (显然不考虑系统的最后第七行)求解R*v=0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM