LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Non-linear curve fitting for complex data

Hi Darin K,

 

Thanks for the explanation. I will like to build a new complexfunction vi and use the ComplexfitExampleVI to call it. I still have some questions and they are as follows:

 

1) When you placed data into the ComplexfitExample vi, did you copy and paste data at once into to the labview data array control on the front panel?

 

2)  How were the following controls and indicators linked to complex function without a direct wire to the For loop? They are; data,f '(x,a), Out put Control and error out controls.   I prefer direct wiring when ever possible to make it easier to undertand codes.

 

3) Is there a reason why you didn't use the formula node inside the For loop to write the model equation ? 

 

4) Why did you have to calculate the Jacobian f '(a,x) and what is the relevance?

 

5) How did you create he Connector pane image/logo in the reference to f(x,a) in the complexfitexample vi? 

0 Kudos
Message 11 of 44
(2,443 Views)

1)  I copied the data to a string control, mumbled a few things when I saw the commas in the frequency values, used string to spreadsheet array to get the values into a 2D array with 3 columns. 

 

GetData.png

 

2)   Data is not used in Complex Function, just in the fit.  f'(x,a) is not used, a finite difference approximation is used instead.  Output control is not needed (it can be used so that f'(x,a) is only calculated when necessary).  Error out is not used, I was in too big of a hurry to connect it.

 

3) I just unveiled some code yesterday that let me copy and paste your formula into a VI and convert to the code you see in the for loop.  It was a good chance to test it, only a few modifications were necessary.  Formula nodes are acceptable, just not the best LV style.  Since you have LV8.2, you will probably want to use a FN (my VI is only 8.6 and above).  Had I not just written the VI to do the conversion, I would probably have used a FN myself.

 

4)  f'(x,a) is not calculated analytically, it is just part of the template used by the fit VI so the indicator is there.  When this array is empty, the fit VI uses a finite difference approximation.  This can be a bit slow and prone to roundoff error, so I suggest that you try to calculate the derivatives.  If you need help with this part, let me know.

 

5)  I created the reference constant by right-clicking the Open VI Reference terminal and selecting create constant.  Then I dragged the icon from the ComplexFunction VI on top of the constant. 

Message Edited by Darin.K on 11-05-2009 10:42 PM
Message 12 of 44
(2,440 Views)

Darin K,

 

Here is my ComplexFunction VI. My model is basically an RC circuit(Rs,C) with a series inductance L, resistance R and a Constarnt phase element represented by a and Y0 while x is the frequency at which each impedance value was measured.

 

I've figured out my formula and used it in a formula node to build the complexfuncion VI but it's got errors in it.

 

When I try to run it, I get an error message saying "formula node: Undefined variable". I believe I defined all the variables and I just couldn't deburg it successfully. I've attached the VI. Please see if you can figure out the source of the error.

 

 

0 Kudos
Message 13 of 44
(2,417 Views)

1. The exponentiation operator is **, not ^.  See the detailed help for the formula node.

2. The constant "pi" is case sensitive. Pi is NOT = to pi.

3. The number of right parentheses is less than the number of left parentheses.

 

Lynn 

0 Kudos
Message 14 of 44
(2,410 Views)

Here you go, the FN does not deal with complex numbers so I just split real and imaginary and cleaned up a couple of errors..  Looks like you now have a winner.  I would still scale L,C and Y0.

 

Even though you don't use the other terminals in My ComplexFunction.vi, they still need to be there so the VI is typed correctly.

 

Message Edited by Darin.K on 11-06-2009 12:05 PM
Download All
0 Kudos
Message 15 of 44
(2,406 Views)

In case you were wondering what your FN would look like in G, here it is.  This helped me spot a small error in my code which I have fixed for the beta version.  Of course, if I were doing this in G I wouldn't separate the real and imaginary parts.

 

ComplexFormulaSnippet.png

0 Kudos
Message 16 of 44
(2,396 Views)

Darin.K,

 

You calculate the  same value multiple times (C2*C2 for example) and repeat constants (pi). Compound arithmetic, Increment, and Sin & Cosine can help simplify it further.  I ran this and it show the same values for the defaults as yours, but it may contain mistakes.  I did not check it closely.

 

Lynn

 

ComplexFormula2.png 

0 Kudos
Message 17 of 44
(2,386 Views)

Hi Darin K,

 

I've attached a screen shot of the raw data plot in excel to give you an idea what the data and the should look like when the Complexfitexample VI executes correctly.

 

Here are more questions I have:

 

1) Did you try to run the Complexfitexample VI after you made those corrections on my complexfunction VI?. Did you get a plot and fit that is similar to the screen shot? I tried to run it and I got error messages.

 

2) How did you get the data,Output,f ' (x,a) and error out controls and indicators on the block diagram of complexfunction VI. This includes the blank data icon on the front panel.

 

3) You said these controls are present so the VI is typed correctly. Could please explain that a little bit more. 

 

4)Why do you suggest scaling of L,C and Y0?. I thought it was already scaled in the formula node.

 

5) I will need help with the f ' (x,a) function. This is the derivative of the residual set to zero in order to find a minimum right? 

 

I'm sorry if I'm asking a lot of questions. It's just that I really need to learn this to complete my experiments correctly.   

0 Kudos
Message 18 of 44
(2,383 Views)

johnsold wrote:

Darin.K,

 

You calculate the  same value multiple times (C2*C2 for example) and repeat constants (pi). Compound arithmetic, Increment, and Sin & Cosine can help simplify it further.  I ran this and it show the same values for the defaults as yours, but it may contain mistakes.  I did not check it closely.

 

Lynn

 

 


 

 

 

That was automatically generated by copying and pasting the formula from the FN into my VI.  My parser is pretty good, but not that good yet...

Message Edited by Darin.K on 11-06-2009 03:36 PM
0 Kudos
Message 19 of 44
(2,381 Views)

 


Mbdeck wrote:

Hi Darin K,

 

I've attached a screen shot of the raw data plot in excel to give you an idea what the data and the should look like when the Complexfitexample VI executes correctly.

 

Here are more questions I have:

 

1) Did you try to run the Complexfitexample VI after you made those corrections on my complexfunction VI?. Did you get a plot and fit that is similar to the screen shot? I tried to run it and I got error messages.

 

2) How did you get the data,Output,f ' (x,a) and error out controls and indicators on the block diagram of complexfunction VI. This includes the blank data icon on the front panel.

 

3) You said these controls are present so the VI is typed correctly. Could please explain that a little bit more. 

 

4)Why do you suggest scaling of L,C and Y0?. I thought it was already scaled in the formula node.

 

5) I will need help with the f ' (x,a) function. This is the derivative of the residual set to zero in order to find a minimum right? 

 

I'm sorry if I'm asking a lot of questions. It's just that I really need to learn this to complete my experiments correctly.   


 

 

1) It runs fine for me, make sure the two VIs are in the same directory.  What error messages are you getting?

 

2)  I copied them from the ComplexFunction VI I posted earlier.  They originally came from a template VI somewhere in the examples shipping with LV.

 

3)   When you open a reference to a VI, you need to specify what its connector pane looks like, ie. what datatypes are connected to what terminals.  That is what I mean by 'typing'.  All generic functions used by the LM fit VI are expected to have those type terminals in those locations, even if they are unused by the fit function subVI.

 

4)  I haven't checked recently, but I seem to recall a time when the numerical approximations for the derivatives were done by adding a small amount to each parameter:  df/da = (f(a+h)-f(h))/h.  If you have a small parameter, h is not necessarily small.  Scaling so the parameters are of order one or larger is just for safety.  If h is chosen as a fraction of a, you should be ok.  At any rate, I like my parameters to  have order unity or larger.

 

5)  If the fit works, it may not be necessary.  Using analytic values may be more trouble than it is worth in this case.

Message Edited by Darin.K on 11-06-2009 03:52 PM
0 Kudos
Message 20 of 44
(2,373 Views)