08-06-2013 10:48 AM
I am trying to create a curve fitting VI in Labview that I keep getting error 20068 for which is "Analysis: Input parameters has at least one element that is Inf, NaN, DBL_MAX, or DBL_MIN". I have attached my data file "Peak.csv" that I am using to fit the curve to as well as the vi, "fitting.vi".
Here's what I've noticed is incorrect.
1. The X values seem to count to 1500 (the number of x values I have) despite the fact that I have wired the output X values to the non-linear fit function. Is it supposed to do this? How can I wire the vi so that the fit actually fits to the values 70-85 degrees (increments of .01 degrees which is why it's 1500 points) as opposed to simply fitting to the number of x values without regard to their individual values?
2. My function "may" be incorrect due to the fact that it's so long, but at this point I'd like to eliminate other possibilities since I've checked it many times.
3. My actual data on the graph shows up fine (despite the fact that the fit is so bad it's hard to tell unless you zoom in from y=0 to y=.05)
This fitting algorithm is for a thin film analyzer that uses the equations found in the paper "Frustrated Total Internal Reflection and Applications of Its Principle to Laser Cavity Design" which can be found at: http://www.opticsinfobase.org/ao/abstract.cfm?uri=ao-3-6-719
Thank you for your help in advance!
Solved! Go to Solution.
08-06-2013 12:36 PM - edited 08-06-2013 12:37 PM
One useful thing to try when having problems fitting data (as learned from altenbach) is to visualize the data and the calculations from the model. When I do that with your data this is what I get:
Note that both graphs contain the same data and the same X-axsi scaling. The Y-axis scales are a factor of 10^5 apart! Although you cannot see it in the graphs the large majority of the points calculated by your formula produce NaN, which is what the error from the fitting VI told you. Here is an expanded view of one of the peaks. Observe that there are no points below 70.3 or above 71.1 for plot 1 because those have NaN values which do not plot.
I did not try to determine what the formula should be but clearly what you have does not match your data.
I did this calculation with Parse Formula String.iv and Eval Parsed Formula String.vi using the formula string you wired to the fitting VI and the X values from your file.
Lynn
08-06-2013 01:50 PM
I figured out why the equation wasn't fitting. I accidentally forgot to add the ^-1 at the end of the equation which makes it look right.
However, I'm still having the problem that when I try to graph this using either the non-linear fit vi or the signal express curve fitting version of that it uses the absolute number of x values instead of the actual values. Could you please provide your code so that I could see how to accomplish this?
Thank you!
08-06-2013 03:02 PM
Here is my code. It is not very neat and I did not include any documementaion or notes. If you have more questions, just ask. I may be off the Forum for the next several hours.
Lynn
08-06-2013 08:16 PM
Lynn,
Thank you for your help. Although my program still isn't fitting (I've narrowed it down to the equation itself) all the labview portions seem to work just fine now after I converted to radians and took the equation^-1.
What would you recommend I do to figure out where the equation is incorrect? I've gone over it several times, but that doesn't seem to be leading me anywhere. I guess I'm going to plot it like you did to figure out where the values are going "NaN" etc.
08-06-2013 08:22 PM
Yes, plotting the equation is a good start.
Do I understand correctly that the formula should be the reciprocal of the formula in your VI?
Lynn
08-06-2013 09:15 PM
I think your formula still has problems. When I take the reciprocla of the original formula I still get lots of NaN values:
What physical process does the formula represent?
Lynn
08-06-2013 09:45 PM
LabVIEW functions calculate trigonmetric functions of arguments in radians!
Lynn
08-07-2013 08:20 AM
Lynn,
Yes indeed that is why I mentioned that earlier in my comments about converting to radians, etc. However, my fitting still doesn't work so I'm working with the equation and cross checking with Matlab/plotting it to see where I went wrong. I do appreciate your help though, you're awesome.
08-07-2013 08:22 AM
Yes, the forumula should be to the ^-1. Additionally, the physical process that the formula represents is optical quantum tunneling through a barrier, otherwise known as frustrated total internal reflection.