LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Polynomial curve fitting

 I have 13 points in the shape of a trapezoid (x range = 0 to 3). I used General Polynomial fit.vi to obtain a 12th order polynomial which matched the trapezoidal shape. However, when the coefficients were used to evlauate the same (x points) in MATLAB and EXCEL the results were as follows:
     From x = 0 to 1 the results (y) matched with the input array y's.
     From x > 1 and ❤️  the results (y) suddenly shoots off.
      
       The numer of points for a 12 order polynomial fitting is less...no wonder...but then why does the shape matches in the General Polynomial fit.vi?  
0 Kudos
Message 1 of 11
(5,748 Views)
Hi.
 
12 order polinomial evaluation always passes through your 13 points.
But between of the points will not.
 
Look at this illustration.

Jack
Win XP
LabVIEW 6.1, 7.0, 7.1, LabWindows/ CVI 7.1
Let us speek Russian 🙂
0 Kudos
Message 2 of 11
(5,741 Views)
One more picture.
 
General polynomial fit VI returns the only given point "y" value. To check your evaluation you can plot a graph with x=[0:3], delta_x=0.001 using polynomial coefficients just like in the previous message.
 
I can not edit my prev. message? Why?..

Message Edited by EVS on 08-26-2005 02:42 PM


Jack
Win XP
LabVIEW 6.1, 7.0, 7.1, LabWindows/ CVI 7.1
Let us speek Russian 🙂
0 Kudos
Message 3 of 11
(5,734 Views)
Ritu,

Are you using the correct X-values for the data when generating the fit data and when re-calculating the data?

Are you saving the coefficients to disk? If so, how many significant decimal pints are you saving?  You might have a rounding error from saving data as string.

Hope this helps

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 11
(5,727 Views)
If you know the wave shape is trapezoidal, why not fit straight lines to each segment? If a data point is close to a vertex and the data is noisy, it may be difficult to tell which segment contains it. Once you have the straight lines, finding the intersection or interpolating points is easy.

Lynn
0 Kudos
Message 5 of 11
(5,707 Views)
I have tested the VI again and  found out that a high order polynomial behaves erratically. In fact 4th order polynomial yielded least mean square error.  However I am still intrigued how the Polynomial fit. vi shows the matching plot. I request the NI members interested in this topic to kindly test their VIs and plot the  expression with coeffecients obtained from this vi in the sam x points used for curve fitting
0 Kudos
Message 6 of 11
(5,682 Views)

Why don't you attach your VI containing some sample data in the controls?

What is your LabVIEW version? Have you tried different algoritms (yes, there is an algoritm input to the poly. fit)?

0 Kudos
Message 7 of 11
(5,670 Views)
Hi, ritu,
 
Try the algorithms such as "givens". As you said, a 4th order polynomial fits your curve well. A high order polynomial fit using "SVD" algorithm may cause the result unstable.
0 Kudos
Message 8 of 11
(5,658 Views)
Another possible reason is that in Labview, the polynomial coefficients are in ascending order of power, while in Matlab, the polynomial coefficients are in descending order of power. If you perform polynomial evaluation in Matlab using the coefficients obtained by Labview, you need to reverse the coefficient array.
0 Kudos
Message 9 of 11
(5,639 Views)
Hi...
Basically i want to convert a graph to a polynomial, i.e. I want to generate a polynomial on the basis of x and y values obtained from the graph
(e.g. if i give (x,y) values as (1,1), (2,4), (3,9), (4,16) then it should give me a polynomial y = x square).
 
Also, i want to use this polymomial such that any x input i give, it gives me the corresponding y value. Is this possible to do in labview? i havent found any useful function for this as yet...
 
regards
abhi
0 Kudos
Message 10 of 11
(5,026 Views)