From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange observation related to polynomial fitting

Solved!
Go to solution

Hi,

I am trying to get the polynomial fit a particular data set. The nature of fitted plot is correct but its Y axis is behaving strangely. I ham selecting some region of the parent plot and then trying to fit it using polynomial fit VI. Every time, the fit is giving some strange Y axis data.

I order to cross check its behavior, I fitted the same data set using origin, with same polynomial order (2), but in origin, no such behavior is observed. In origin, the fitted curve is always lying with the data points (which is expected).

Also, in order to verify again, I used some data generated by a quadratic equation and got a proper fitting in LabVIEW as well as in origin. 

Now my problem is why LabVIEW polynomial VI is misbehaving for my data points (origin it is coming proper, but I need to use LabVIEW for some real-time calculations)?  

 

The concerned VI with both the data points are attached.

Thank you.

Download All
0 Kudos
Message 1 of 10
(2,867 Views)

There's are quite a few problems with that code, so it's no wonder you get strange results. 

 

It seems you want to be able to fit the data based on the positions of the cursors on a graph and update everytime the cursor moves.  But, you're code suggests you are new to LabVIEW.  There's no issue with fitting, just your poor implementation.  (If you want to compare to your Origin fit then just do a basic fit over the same range.  I'll guarantee they match.  Use this as a reference - https://www.ni.com/en-ca/innovations/white-papers/08/overview-of-curve-fitting-models-and-methods-in...)

 

So you need to learn some LabVIEW programing basics - http://www.ni.com/getting-started/labview-basics/.  Next you should learn how to use event driven state machines design pattern, then when the cursor values change, you update the fit and re-plot the fit data.  This will avoid the rather convoluted loops you have there.  This might take some time but well worth the effort.

 

Craig

0 Kudos
Message 2 of 10
(2,826 Views)

But using the same VI, when I am fitting the quadratic equation data, the fitting is proper. Then why for the other data set, it is giving different Y values? 

0 Kudos
Message 3 of 10
(2,797 Views)

As suggested, I tried to use polynomial fit VI simply (no complications in the code). I am again having the same problem. VI and a data set is attached.

Download All
0 Kudos
Message 4 of 10
(2,791 Views)
Solution
Accepted by topic author Ben121

Using the supplied code and data I was successful with the following algorithms:

  • Givens
  • Givens2
  • Householder

SVD gave the right shape, but the wrong values (this is the default by the way) and LU Decomp, Cholesky and SVD for Rank Deficient H all gave fairly straight lines.

 

So I'd suggest you look at the algorithms in more depth, and/or just choose a different value (e.g. Givens).

Tweaking the "method" also adjusted the fit - you might prefer one over another.


GCentral
0 Kudos
Message 5 of 10
(2,775 Views)

Actually, I am not really able to understand your suggestion. I dont have much idea about these technical term. Im sorry for that.

Can you please help me getting a correct set of Y axis values? The shape of the plot is correct (I cross-checked with that obtained by origin). I think I am missing some very basic point.

 

Thank you.

0 Kudos
Message 6 of 10
(2,770 Views)

On your fitting VI, hover near the bottom and find the "algorithm" input.

Right click on it and choose "Create Constant" or "Create > Constant" depending on LabVIEW version. You could also create a control if you prefer.

Change the value (via dropdown box in the created constant/control) to one of the ones I listed and rerun the VI.


GCentral
0 Kudos
Message 7 of 10
(2,756 Views)

(Posting by phone, but this thread should be appended to (i.e. merged with) your other thread. No need for diverging discussions of the same vi.)

0 Kudos
Message 8 of 10
(2,745 Views)
Solution
Accepted by topic author Ben121

Yes, you need to learn some more of the basics of LabVIEW - controls, constants, indicators.  In the block diagram press CTRL+H (display help window) then hover over the poly fitting VI.  Notice the inputs to the VI?  You need to select method and algorithm as cbutcher mentioned.  (Origin probably does this for you or only implements one method.)

 

poly_fit_help.png

 

  

 

Here's a simple example where I've added cbutcher's suggestions and made the polynomial fitting options into controls that you can easily change on the front panel.  I did provide a method to select a section of the data of interest, but it's not doing anything with cursors... you got lots of help on that here - https://forums.ni.com/t5/LabVIEW/How-to-fix-cursor-at-one-particular-value-X/td-p/4017281

 

 

Craig

0 Kudos
Message 9 of 10
(2,738 Views)

Thank you so much for guiding me regarding some very basics of polynomial fit VI. I was really unable to understand what was going on. The confusing thing was that same VI was giving proper Y axis values for a data set generated by using a quadratic equation, but for my other data point, I was getting different Y values.

 

Thank you again.

0 Kudos
Message 10 of 10
(2,706 Views)