LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Non-linear curve fitting for complex data

Hi,

 

I want to perform a non-linear curve fitting for complex impedance data obtained at different frequencies. The model impedance equation contains real and imaginary parts and I'm trying to use the Non-linear Curve fit LM Formula string instance of the non-linear curve fit VI. Can someone give me a guide on how to proceed?.

 

The model equation is as shown below:

                                                            Z = R + i((2pi*f)^a)/Y0 - i(Rs)/(C - i/(C*2pi*f)) + i(L*2pi*f)

 Where R,Rs,a,Y0,C and L are parameters while f is the frequency. 

 

I just don't know how to handle the complex parts of the equation in the curve fitting VI. Any assistance will be appreciated. 

 

Thanks 

0 Kudos
Message 1 of 44
(9,594 Views)

A couple of quick thoughts.  First, I would give serious consideration to using a VI instead of the string.  You can pass complex data into and out of the fit using this trick, and the VI can perform complex math.  I have done this many times to fit complex impedance data.

 

If you insist on the string VI you could break up the function into real and imaginary parts and fit them separately.  Or just fit one component since the impedance is an analytic function the real and imaginary parts are related by Kramers-Kronig relations (finding one fixes the other).  You are only fitting half of your data though.

0 Kudos
Message 2 of 44
(9,584 Views)

Thanks Darin K,

 

I will try it and let you how it turned out for me.  Thanks again 

0 Kudos
Message 3 of 44
(9,570 Views)

Hi Darin K,

 

I tried to write the code and follow the tip you included but I couldn't finish the coding. I've attached the extent of what I was able to do. I needed to start with a 2D array of of complex data but I couldn't use both the type cast and the decimate 1D array functions.  For example the decimate 1d array function on the funtion pallet had only one input while the one you attached had two inputs. 

 

Anyways, I wanted to create two arrays, one Real and one Imaginary and make them the x and y inputs while designating the frequency as the independent variable as you can see in the attached unfinished VI.  I used the formular instance of the Non-linear curve fit VI so I can input my model equation and define the paramenters. 

 

I'm just stuck at this point and would like some help to fix and finish it.  I've attached the vi and my Labview software version is 8.2.

 

 Thanks

0 Kudos
Message 4 of 44
(9,556 Views)
Some data to test with would be very useful.
0 Kudos
Message 5 of 44
(9,553 Views)

Here is a data set you can use. I couldn't paste it directly so I've attached it as text file in note pad.

                                

 

                                                 

                                                         

0 Kudos
Message 6 of 44
(9,541 Views)
Please double check your formula, it doesn't make sense from a units standpoint.
0 Kudos
Message 7 of 44
(9,532 Views)
Your data doesn't seem to match your function so I went ahead and generated some fake data using your function and then fit to it.  When you correct your formula, you can change the ComplexFunction VI to reflect the change.  At any rate here is a nonlinear fit with complex data points.  Just make sure the two VIs are in the same directory when you run ComplexFitExample.
Download All
0 Kudos
Message 8 of 44
(9,524 Views)

Hi Darin K,

 

I didn't quite understand your code but here is the impedance function again separated clearely into real and imaginary parts. Can you make the change and them explain the code and how you made the change.  Thanks again for the help.

 

Real part=

R + Rs/(1 + 39.4784176043574*(0.000000001*C)^2*f^2*Rs^2) + COS(1.57079632679489*a)/(6.28318530717958^a*f^a*0.000001*Y0)

 

Imaginary part =

 6.28318530717958*f*(0.000000001*L - (0.000000001*C*Rs^2)/(1 + 39.4784176043574*(0.000000001*C)^2*f^2*Rs^2)) - SIN(1.57079632679489*a)/(6.28318530717958^a*f^a*0.000001*Y0)

 

 

0 Kudos
Message 9 of 44
(9,503 Views)

Your function never did make much sense to me, so I just assumed it was a series RLC with a separate R in parallel with C and some frequency dependent reactance. 

 

ComplexFitExample takes a complex array of data, converts it to a DBL array [Re,Im,Re,Im...] passes it to the fit function along with a reference to the VI which calculates f(x,a) [ComplexFunction.vi].  Complex Function.vi calculates Z for each value of x (frequency) and generates an array of the form [Re,Im,Re,Im] to match the form of the data.  All math is done using complex numbers, no need to deal with real and imaginary components.  After the fit, the data is type cast back to an array of complex numbers, and plotted on an XY graph.

 

When you sort out the function (keep it complex), just change the code inside the for loop of ComplexFunction.vi, that's all.

 

 

Download All
Message 10 of 44
(9,493 Views)