简体   繁体   中英

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. By setting a particular DAC value I get a particular current reading. 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. 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. 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. 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.

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. The hardware is an embedded Atmel processor the calibration coding is done using Visual Studio talking to external reference meters and the target hardware.

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.

The general formula is 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]) . 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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