LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Non-Linear fit of Voltage vs. Angle data

Solved!
Go to solution

Lynn,

I think I figured out what was going wrong and I'll post this into another post if necessary but essentially as the non-linear fitting algorithm is guessing values of refractive index (n) and thickness (d) the angular values input into the system (like say 75 degrees) will return negative values under the square root (meaning it'll return complex numbers like "i=sqrt(-1)"). 

 

That being said, now my task is to somehow allow the fitting to occur whilst excluding the angles that include complex values. I can think of a number of ways this can be done, but a little direction on your part as to what would be easiest would be appreciated.

1. Put an error out on the VI and have Labview fit the function anyway (I'm not sure if this will work or not as I'm not sure how labview treats things like this i.e. if the fitting stops after the error or if it keeps going with whatever non-nan values it has)

2. Use the non-linear curve fit with constraints (though I'd prefer not to use this considering that it will be a pain to do my equation without the formula string).

3. Make sure that when I curve fit data that I am always far beyond the critical angle (which means that the equation will give real values). Unfortunately, this is difficult to do everytime since I do not know the critical angle a priori and there's a chance that the fitting equation won't work anyway since it may guess higher than I realize causing it to return an error again.

0 Kudos
Message 11 of 15
(581 Views)

First, thank you for letting me know what you are working on.  I have worked with some optical physicists so I have a little familiarity with the type of things you are doing.

 

The (2) constrained fit VI is probably the best choice. It already has built-in capabilities to perform the limitations.

 

Implementing your formula in a VI will not be that difficult.  Just keeping track of the matching of all the parentheses in the formula is about as challenging. In a subVI error handling options are much more flexible than in the formula VI where you have essentially none. It also makes it easy to graph the results so you can spot problems easily.  You may also get better performance because the formula parsing VIs tend to be slow.

 

Lynn

0 Kudos
Message 12 of 15
(574 Views)

I put together the necessary code to do the constrained non-linear fitting and it appears to work well with your data.  The fitted curve is completely hidden behind the noisy raw data. When I set the constraints to values between the initial values and the best fit values, the new best fit values are very close to the constraints.  I take that as an indication that the constraint is working.

 

It was necessary to change x to x' = x * 2 * pi / 360 to get everything in radians.  The test code has a switch which allows you to switch between the formula code equivalent (with the ^-1 added) to the code using radians.

 

This is rather sloppy.  I did not do any clean up nor did I add any documentation.  I have the File Read VIs in diagram disable blocks. I read the file you posted once and converted the data to default data in a control.  To run this with other data you will need to restore the File Read capability.

 

The Formula Check VI has a bunch of string constants showing how I manually parsed the formula string.  The a and b in "(a" and "(b" and "b)" and "a)" are markers I used to assure that I was correctly pairing the parentheses. 

 

Lynn

0 Kudos
Message 13 of 15
(562 Views)

Lynn,

Could I get your full name so that I could acknowledge you in my upcoming manuscript? You've been a great programming help and I think you should be acknowledged for it.

0 Kudos
Message 14 of 15
(536 Views)

PM with contact information is on the way.

 

Lynn

0 Kudos
Message 15 of 15
(527 Views)