??? 03/25/04 02:49 Read: times |
#67389 - RE: Linearisation using curve fitting Responding to: ???'s previous message |
Michael wrote:
Plus.....I like to repeat that if the linear interpolation (not extrapolation) not precise enough between the known data points then all you need to add is more known data points!! If you have a look at Nagarajan's latest Excel-file, you can see how much better a linear interpolation would be, compared to any kind of parabola approximation!!! Another thing to keep in mind is that the math to perform the linear interpolation is easy to code up, even if you have to do it in assembly language, because it can be done with fixed point numbers. Exact! What a difference.... There is a big likely hood that the math to perform a real time computation of a curve fit needs to be either a double float (see Kai's comment) or would need to use fixed point out to 64 bits. Yes, indeed! From my parabola apporximation, stated in last reply, namley Y = 2001.9 * X -0.003167 * X^2 (Deviation from calibration curbve then is <+-23.) you can see, how big the difference of both coefficents is. I actually thought that this would have clearly demonstrated, that a power expansion series would not be the best way to go... Further more: If parabola approximation will not satisfy, as in this example, and you need to add X^3 term, then according coefficent is getting even smaller and even more precise calculation is needed. From above parabola approximation, which fits to the whole curve, the fit to error term, Nagarajan might be interested in, can easily be derived: ERROR_fit = WHOLE_curve_fit - IDEAL_curve = 2001.9 * X -0.003167 * X^2 - 2000 * X = 1.9 * X - 0.003167 * X^2 I got a deviation from calibration curve of less than +-23. I choosed the coefficents in such a way, 1. that NO additional Offset error is introduced, means Y = 0 with X = 0, 2. that NO additional Gain error is introduced, means Y = 1200000 with X = 600 for whole curve fit, or Y = 0 for X = 600 for ERROR_fit, 3. and that maximum deviation is symmetrical referring to sign. Of course, if introduce of offset error and gain error is not an issue, then coefficents might be changed slightly. BUT: You will never get another parabola approximation curve, which is MUCH better then the above. You can improve error with positive sign, but then you increase error of negative sign, and vice versa. Latest excel file from Nagarajan is a good example for this. He gets a deviation of -6.5 and +37.0, which is only slightly better than +-23 in the sum. No, in this case here, where the calibration curve is so well documented (I assume it is....), it would be very strange NOT to try a piece wise linear fit, e.g. in the way Eric described so nicely. And if someone has a closer look to curve of Nagarajan's latest excel file, he will note the very special 'pig tail' arround X = 560...600. This is so sharp, that it can never be approximated by a parabola. Not even by using much higher orders terms... Of course, piece wise parabola approximation could improve situation. But why making a multi parabola approximation if a piece wise linear one is fully satisfying?? What, if calibration curve differs from sensor to sensor? Every time generating new sets of coefficents for multi parabola fit??? Finally, I think there's one mistake in our whole discussion: Input and output are substituted by mistake! Nagarajan gets counts between 0...1200000 from sensor electronics. From this 'input' he wants to find the corresponding weight. Actual 'input' is 'counts' [0...1200000], and actual 'output' is 'weight' [0...600]. So, he needs to do the inverse fit, with 'counts' on the X-axis and 'weight' on the Y-axis. Or am I wrong? Kai |