LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Curve Fitting with Automatic XY Redraw Following Parameter Adjustment

Hi All -

 

I'm trying to fit experimental data with several parameters in LabVIEW 8.2.

 

Right now, my VI takes raw time and voltage data, converts it to the desired units, smooths it, and parameter fits it.  The initial parameter fit is typically not very good, however.  This can been seen when one plugs the parameters back in and attempts to recreate the experimental data (see attached xy graph, Plot 0 is experimental, Plot 1 is generated by me).

 

After I see how well/poorly the initial parameters fit the data, I would like to be able to nudge the parameters to provide a good fit to the experimental data.  I want to set up the VI so I can look at the Plot 1 on the graph and decide if I want to adjust the necessary parameter, the "broadening factor."  If I choose yes, I input a new broadening factor, and it uses a MathScript node to recalculate the y-axis values (a 1-D array).  After these are calculated, I want them to appear as Plot 2 on the pre-existing xy-graph....and continue to have this happen until I tell the user prompt that I no longer want to adjust the parameter.

 

I've tried a couple of things based on other posts here - the bundling, array building, shift registers, etc. in there definitely isn't working, however.  The while loop keeps prompting me for a new value like I want it to, but nothing plots on the graph for me to see how well my new value works.

 

I apologize in advance for the use of local variables which will probably make some of you cringe.  I'm just learning, and while my code works for the most part, I'm sure it's not very elegant.

 

Thanks!


 

 

Download All
0 Kudos
Message 1 of 9
(3,867 Views)

Think dataflow!

 

Your xy graph is connected outside (before) the while loop, meaning that it will never get updated again. If you want to update the graph during the while loop, the terminal needs to be inside the while loop.

 

With every iteration of the while loop, you are appending a new graph until you have an infinite amount of graphs (that you never display!) and run out of memory. You should use "replace array subset" to overwrite one of the two graphs.

 

I don't seen where you are fitting anything.

 

You are currently using LabVIEW literallly like a text programmer. What's up with all these local variables? For example, in the left frame you are reading from "adjusted wavelenght" from three seperate instances of the same local variable. Don't be afraid to branch a wire! Where's the terminal? Why can't you read from the actual terminal?

 

If you don't mind, please attach the VI instead of an image so we get a better idea about the code. Thanks!

0 Kudos
Message 2 of 9
(3,855 Views)

Will work through your comments.  Thanks.

 

Here is the VI and an example text file that I am trying to analyze.  One needs to enter a starting wavelength (436 nm), scan speed (0.3 nm/sec), and fitting parameter (0.05) and select all of the LEDs on the front panel to get to the stage where I'm having the problems.  Sorry...I figured this was fairly involved, which was why I didn't post the entire thing in the first place.

 

 

Download All
0 Kudos
Message 3 of 9
(3,844 Views)

Here is a new version of the VI. 

 

I haven't gotten to fixing the graphing yet, but in the meantime I got rid of most of the local variables and set the inputs to default values so they wouldn't need to be entered.

 

Thanks again.

0 Kudos
Message 4 of 9
(3,813 Views)
Sorry, you seem to be using some toolkit that I don't have. I cannot run your VI.
0 Kudos
Message 5 of 9
(3,807 Views)

MerRhosyn,

 

Regarding the updating of your graph, they are still located outside of your while loop that is changing your parameters. Because of this, you won't see any updates on the graph itself.

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 6 of 9
(3,766 Views)

Will -

 

I now have the graph inside the while loop.  It is working better, but not exactly how I want it to.

 

Graph on bottom right should show white and red plots not overlapping.  Should be able to iterate broadening factor and phase factor to see changes in red plot on top right graph.

 

Also now using 8.6.  Thanks.

 

Meredith

0 Kudos
Message 7 of 9
(3,764 Views)

Meredith,

 

I also cannot run your VI. Did you create subVIs or are you using a 3rd party toolkit? This is in regard to "get weight coefficients.vi", "Lienar Fit Coefficients with Weights.vi", and "tricube or bicube weight function.vi." 

 

Regarding the plots not overlapping in the bottom right graph, why should they not overlap? Are they supposed to be on different scales?

 

The top right graph, only has inputs from standard tunnels. Because of this, graph will pull the same value as it did on the first iteration. You will need to use another method to make sure the graph is pulling updated values. One option would be a shift register. I've attached a small example that shows the difference between these two methods.

Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 8 of 9
(3,734 Views)

I incorporated one of the example VIs found on your website in order to accomplish the data smoothing.  The original VI is attached.

 

At any rate, I solved the problem about an hour ago.  Since you can't run the VI, there's probably no point me attaching it.

 

I'm put a user prompt in a while loop asking if one wants to adjust the broadening factor to better fit the experimental data (they shouldn't overlap because the first attempt to simulate the data is fairly rough...and needs further refinement via iteration of the key variables that produce the new y-axis data).  The new y-axis data is calculated within the while loop and written to the parameter fitting graph.  Once I decide that the experimental data has been fit sufficiently, I tell the user prompt that I don't want to enter a new broadening factor - it then proceeds to go through the same routine for the phase factor...and complete.

 

Thank you for all of your suggestions.  Sorry that the incorporated VI wasn't functional.  I don't want to change it however, because it works perfectly for the data smoothing I'm trying to accomplish.
Download All
0 Kudos
Message 9 of 9
(3,729 Views)