06-06-2006 09:10 PM
I have a set of data, defined by Y = A + BX + CX^2 + DX^3 + EX^4.
X would be a voltage, A,B,C,D,E are constants, and Y is a resulting measurement ( in engineering units).
I actually implement this (in code) as (((EX + D)X + C)X + B)X + A.
Now, because of design changes, I need to convert that data back to raw ("X") values. Can that be done, and if so, how?
In other words, given the above equation, and values for A,B,C,D,E, and (multiple, if necessary) values for Y, can I extract the X values that produced Y?
Or is it an irreversible equation?
It's been too many years since math class...
Blog for (mostly LabVIEW) programmers: Tips And Tricks
06-07-2006 12:10 AM
06-07-2006 01:28 AM
06-07-2006 01:31 AM - edited 06-07-2006 01:31 AM
@CoastalMaineBird wrote:
I actually implement this (in code) as (((EX + D)X + C)X + B)X + A.
Easier would be to use the "polynomial evaluation" function. 🙂
Yes, in general there are between zero and four solutions, but for a typical calibration curve there is exactly one solution and you even know the lower and upper limits for X and Y. How accurate does it need to be? I agree with Keyser that newton-raphson should converge with a few iterations given a reasonable initial estimate, e.g. halfway between the upper and lower limits of X.
Message Edited by altenbach on 06-06-2006 11:31 PM
06-07-2006 02:30 AM - edited 06-07-2006 02:30 AM
Message Edited by altenbach on 06-07-2006 12:33 AM
06-07-2006 03:46 AM
Hmmm - I know the N-R technique for finding integer square roots, from back in the days when integer math was much faster than floating point...
It says that X(i+1) = X(i) - (X(i) * X(i) - Y) / (2 * X(i)). This will find the square root of Y, given an initial guess of X(0). The more iterations you go, the closer you get to the true answer.
I didn't realize it was generalized to any function.
I had seen the FUNCTIONS | ANALYZE | MATHEMATICS | ZEROES | COMPLEX POLYNOMIAL ROOTS vi. If I feed it the A,B,C,D,E, I get out four complex numbers, but I don't know what to do with them.
I see the NEWTON-RAPHSON ROOT FINDER in that same palette, I'll see what I can do with that.
Thanks...
Blog for (mostly LabVIEW) programmers: Tips And Tricks
06-07-2006 04:48 AM
Not so. Given 100 channels, with 100 {ABCDE} sets, and 100 samples (1 from each channel), it's way simpler (way faster, too) to multiply 100 X's by 100 E's, add 100 D's, multiply by 100 X's, add 100 C's, etc. etc.
The code is simple looking (8 operations total - no loops) and measurably faster (1/4 or so).
Blog for (mostly LabVIEW) programmers: Tips And Tricks
06-07-2006 10:41 AM
@CoastalMaineBird wrote:
Easier would be to use the "polynomial evaluation" function.Not so. Given 100 channels, with 100 {ABCDE} sets, and 100 samples (1 from each channel), it's way simpler (way faster, too) to multiply 100 X's by 100 E's, add 100 D's, multiply by 100 X's, add 100 C's, etc. etc.
The code is simple looking (8 operations total - no loops) and measurably faster (1/4 or so).
By "easier" I meant "dropping a single system VI and hooking up three connectors is easier than explicit multiplications". It is also much easier to modify it later for a 3rd, 5th, or even higher order polynomial, simply change the coefficient array size. 🙂 I usually don't worry about speed unless the difference is at least a factor of 2..10. 🙂
Anyway, If speed is really a concern and accurracy is less important, I would just create a calibration array of reasonable size, then use threshold array to find the solution by linear interpolation. Attached is a quick modification of my above example to demonstrate this suggestion.
06-07-2006 11:49 AM
Ah, but since I do it for a single sample, I have to BUILD ARRAY to turn that one sample into an array, and then INDEX ARRAY on the other side, just to extract it. And I would have to call the VI once for each channel, since each channel has its own ABCDE set.
I usually don't worry about speed unless the difference is at least a factor of 2..10.
Well, the factor is four in my tests, and I'm doing so much stuff I have to scrimp every chance I get.
Anyway, If speed is really a concern and accurracy is less important,
In the REVERSE case, I need accuracy more than speed. I will be undoing some previously recorded data files, and whether it takes a minute or and hour is unimportant, since I will only do that once.
In the FORWARD case, I need speed, which is why I did not use the EVAL POLYNOMIAL thingy.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
06-07-2006 12:03 PM
OK, I made a quick example using Newton-Raphson
That works well PROVIDED I give it an initial guess that's in the right ballpark. But it suffers (just like the papers say) from the fact that if the guess is off, then it will home in on a different root.
In my case, since I'm measuring a continuous signal, I could use the previous value as a starting guess for the next sample, and it would probably STAY on track. But how do I make sure I'm following the right root to start with?
Maybe your linear estimate (example 2) will give me a good enough answer for that. In other words, use that for the initial guess, and then use the N-R technique for the rest. I suppose the curve is not going to be too extremely warped, or else you would lose 1:1 relationship between voltage and pressure (or whatever).
Does that make sense?
Does that sound reasonable?
Blog for (mostly LabVIEW) programmers: Tips And Tricks