LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Non-linear curve fitting for complex data

Hi,

 

I am currently facing some issue on Non Linear curve fitting (made some comments on http://forums.ni.com/t5/LabVIEW/Non-linear-curve-fitting-for-complex-data/m-p/2311914, then realised that was from three years ago...).

 

I am doing curve fitting of impedance data.

 

I use a combination of different code written previously on the other topic, in order to do data fitting of impedance
 (circuit described in Complex_Function.vi). I think that's properly implemented (checked it on a few values, that's fine).

 

Initial values

C1 =4.7 uF

R1 = 20 Ohms

R2 = 220 Ohms

 

Yet, I keep having the same error being " error 20068 occrued at NI_Gmath.lvib.LM get new coefficients.vi:1.
 Which I do not understand.

 

Let me know if you have some clues to solve this mistake. I attached the code in the llb and the excel file I am using.

 

thanks :smileyhappy:

 

Kentmey

 

 

Kentmey
Download All
0 Kudos
Message 1 of 11
(3,506 Views)

First things first:  Your model is wrong by inspection.  Your imaginary data is always positive, your model function will produce negative imaginary components for positive parameter values.

 

Next:  You can not feed complex data to the nonlinear fit VI.  You must combine the real and imaginary parts into a single array. You can type cast the complex array into a double array, you can interleave the real and imaginary arrays, or you can simply append one to the other.  Your model function VI has to combine them in a similar fashion.  It does not matter that the X and Y arrays are different lengths (fortunately there is no check so this trick works).

 

After the fit, simply reverse the process you used to combine the real and imaginary parts to separate them again. 

 

Finally, why do you have a constant 1 wired to the For Loop of your Fit model VI?  Remove this and let it autoindex.  I assume this was for debugging.

0 Kudos
Message 2 of 11
(3,486 Views)

Hi,

 

I made the changes (the data has a -1* in processing, so I changed the sign of the imaginary in the model). Thanks for the other mistakes as well. By curiosity, why can't I send the complex number into the fitting, if the function is complex too?

 

I am still getting the same issue with that error I mentioned earlier even with that fix though.

Kentmey
0 Kudos
Message 3 of 11
(3,473 Views)

Works fine for me, only had to add some initial values to your VI.  By the way, you only display two plots, data and fit, both as imaginary versus real, so I also had to autoscale X to see it.  Anyway, no errors for me.

 

ImpedanceFitDisplay.png

0 Kudos
Message 4 of 11
(3,465 Views)

I am still getting that error actually... strange.

Kentmey
0 Kudos
Message 5 of 11
(3,459 Views)

are we using the same version of Labview?

Kentmey
0 Kudos
Message 6 of 11
(3,447 Views)

I do not have LV11 to test.  Works in LV10 and LV12.

 

Are you loading the data properly.  Forgot to mention that I save your data as a CSV file so I had to change the delimiter to a comma in Read from Spreadsheet file.

0 Kudos
Message 7 of 11
(3,439 Views)

Tried with 2012 as well, it does not work either.

 

Can you send me back my code with your modifications, maybe I missed some tiny thing in there? That's still quite odd (and I keep having the same error -20068)

 

Kentmey.

Kentmey
0 Kudos
Message 8 of 11
(3,431 Views)

Here is the LV10 version with a few more simplifications (cut out the file reading and replaced with default values).  Replaced the VI path with a static reference.

0 Kudos
Message 9 of 11
(3,422 Views)

That definitely works, thanks.

 

However, I don't really understand how you load the data from the excel file in this program (apologies for my lack of knowledge of LabVIEW...). And when I try to read from the excel file, it does not work...

Kentmey
0 Kudos
Message 10 of 11
(3,403 Views)