LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

polynomial curve fitting and shifting goal posts

Lets say that your X range for the original data is from X0_old to Xn_old.  Since you are fitting a polynomial to this data, Y=PP(X_old).  PP defines the polynomial.  The assumption is that the X range has changed, but the curve is the same over this new interval.  If we assume that the new interval (X0_new to Xn_new) maps linearly to the old interval, then the old and new are related as: Xold=m*Xnew+b

So if we can find the m and b that map Xnew to Xold it is possible to evaluate the original polynomial.  Because your problem indicates that X0_new and Xn_new are known, we can solve for the mapping (two equations in 2 unknowns).  On the VI diagram I solved for the mapping from Xold to Xnew, then inverted the mapping.  One way to use the mapping would be to take any desired X_new value, apply the linear mapping, and then evaluate the original fit polynomial.  Instead of this two step process, lets just substitue:

Since Y=PP(X_old) and Xold=m*Xnew+b, we can substitute and get Y=PP(m*Xnew+b).  Keep in mind that m*Xnew+b is just a first order polynomial (coefficients=[b,m]), we can use the polynomial composition VI to perform the substitution.  The inputs to the VI are P(x) and Q(x) (two polynomials), and the output is the new polynomial P(Q(x)).  For this problem P=PP, Q=[b,m].  The new polynomial is Pnew=P(Q(x)).

Now consider the more complicated case where both the Y and X intervals must be remapped.  The process is to first map the new X interval into the old interval, as above.  Then we have to map the old Y interval to the new Y interval.  For this second mapping, using the same notation as for X, we have Ynew=scale*Yold+offset.  I'm using scale and offset to show that these are different values than m and b.  We know that Yold=Pnew(X), so substituting Ynew=scale*Pnew(x)+offset.  This is another polynomial composition, with P(x)=[offset,scale], and Q(x)=Pnew.

The data values you showed as an example seem to indicate the the X interval changes, but the y interval does not.  If this is the case, then only the first polynomial composition is required.  
Hope this helps.
-Jim

0 Kudos
Message 11 of 16
(493 Views)

Thank you so much Jim! This helps immensely. I am kinda a Math guy, so now this makes total sense.

Yes, you are correct. My (X values) are the ones that change. Y range remains the same. For any range of X values, my Y values are from 0 to 13. So, from your vi, I wouldn't have to calculate Y_new as you have done.

 

This really helps. I will try it out and let you know how it works. Have a good day!

 

VB

I may not be perfect, but I'm all I got!
0 Kudos
Message 12 of 16
(486 Views)

Also, I see from the vi that you have generated some Y_old values for interval (X_0_old, X_n_old). But, from my initial calibration process, I already have 20 points, i.e. I have data for (X_0_old, X_n_old) --> (Y_0_old, Y_n_old). So to reproduce your vi for my application, I can just read off of that data without the need to generate Y values. And, I also have the old polynomial coefficients. I will reproduce my vi from yours and post it and please do take a look. Thanks!

I may not be perfect, but I'm all I got!
0 Kudos
Message 13 of 16
(483 Views)

Hi Jim,

 

Please find attached vi and data from my application. I have used the first method described in your vi. The reverse mapping method is not getting into my head. I will look at it again. Please point out any flaws in my vi.

 

Here, we are assuming linear shift of end points. What if the shift is not exactly linear? What if it is random? FOr eg. (X_0_old,X_n_old) = (2,5) shifts to (2.2, 4.9) or (2.1,6) etc. Can linear fit be a good approximation of the shift of end points to reconstitute new X values? Can we do a polynomial evaluation as opposed to linear evaluation to better approximate the shift?

 

Thanks!

 

P.S. If I were to understand reverse mapping, Can I interchange the inputs to the linear fit vi? (X old) would be Y vaues and (X new) would be X values as opposed to how your vi shows? Is that all there is?

I may not be perfect, but I'm all I got!
Download All
0 Kudos
Message 14 of 16
(477 Views)

I think the only way to determine if the linear shift idea is valid is to either derive/analyze the root cause of the shifts from first principles, or sample enough instances of a shift (before and after) to convince yourself that the shift is as expected.  If it is not linear, then it becomes more important to understand the underlying cause of the shifts, so that a mapping can be modeled properly.  Otherwise you may just as well perform a new calibration from scratch.

 

"P.S. If I were to understand reverse mapping, Can I interchange the inputs to the linear fit vi? (X old) would be Y vaues and (X new) would be X values as opposed to how your vi shows? Is that all there is?"

Yes.  In the code I wanted to view the forward mapping using the indicators.  Then I reversed the mapping.  To compute the reverse mapping directly just swap the inputs as you mention.

 

-Jim

0 Kudos
Message 15 of 16
(463 Views)

Jim! Thank you for that clear explanation. I do know the under lying cause of the shift. It is the mechanical design of my design that causes it. If there is a misalignment between the transmitter and receiver of my fiber optic system, I get a different voltage everytime. And I cant estimate what sort of misalignment can lead me to believe it is a linear shift. But, as an estimate, I thought, assuming a linear shift could reduce my errors and save me time in actually doing the whole calibration process from scratch.

I may not be perfect, but I'm all I got!
0 Kudos
Message 16 of 16
(452 Views)