11-09-2009 08:59 AM
It is hard to know for sure when I am missing your text conversion VI, not to mention default values for your initial guesses. It is usually an issue of providing initial guesses. I am not sure what you think this code is doing.
Just wire it straight through. No error here, just a waste of operations.
11-09-2009 09:51 AM
Hi,
I think I already did exactly that in the code I posted. The text conversion subvi is there in my code.
Infact I've gone back to re-lable the VI so you can see it. Double click on the subvi and you'd see the text conversion code. The text conversion code lable is "Data and frequency text conversion.vi". I've also included my initial parameter guesses. I've attached the vi again the labels on the block diagram.
11-09-2009 10:10 AM
Mbdeck wrote:Anyways, I have finished my new code and there are no errors in it. The issue now is that it doesn't work properly. For example, I put in my initial parameters and run the vi, it returns the same numbers and doesn't plot the graphs. It just plots a straight line on the xy graph. I copied and pasted the raw data into the VI and used a subvi to convert the data. Everything seems to be in order I just don't know why it is not functioning as it should.
11-09-2009 11:29 AM
Hi Altenbach,
The initial estimates are very close to the raw data. I've attached the data conversion subvi that I used in the my code as well as the VI itself. I indexed the columns of the data. I've also made the initial parametas the default. I'm trying to obtain both the fit and the data on the same graph. See the conversion subvi and the VI itself in the attachments below:
11-09-2009 12:15 PM - edited 11-09-2009 12:21 PM
A few problems along the way.
The type of your data array out of the spreadsheet conversion VI should be complex double, not double
Wire an indicator from the error out of the LM VI to double-check for errors.
The parameter order was not consistent between your initial guesses and the order used in My ComplexFunction.vi
You left some commas in your string
Here is my version incorporating your spreadsheet conversion. The default values you see are what I get when it runs on my machine, so clearly the fit is "working". Working doesn't necessarily mean giving good values, it only does what it is told. Better guesses and constraints on parameters are sometimes needed to help out. In this case, your guesses look good.
Edit: Fit shape looks good, values are a little unrealistic. Usually either a function choice problem, or large uncertainties in the parameters. Constraints may help, harder to do in 8.2.
11-09-2009 07:04 PM
Hi Darin K
Thanks for making those adjustments on VI. Your Nyquist plot of the data and the fit was what I was trying to get my VI to do. I have made those changes that you pointed out but my VI plots only the data without the fit. The best fit parameters that come out of the LM fit VI are the same parameters I had entered as initial guesses. There was an error code 1026 in the error indicator. Here is the entire message:
Call By Reference Node in NI_Gmath.lvlib:LM call model function.vi:44->NI_Gmath.lvlib:LM function and gradient.vi:3->NI_Gmath.lvlib:LM abx.vi:2->NI_Gmath.lvlib:Nonlinear Curve Fit LM.vi->My ComplexCurveFit.vi
The corrected vi is attached below.
11-09-2009 07:25 PM
11-10-2009 06:32 AM
Hi Darin K,
I just want to say thanks for all your help. My VI now works the way I want it. I just have do a better job with the initial guesses to obtain more realistic numbers. keep up the good work.
02-23-2010 02:41 AM
Hello,
I am using an agilent impedance analyzer 4294A for measuring and fitting complex data. Now I want to write a labview application to fit data, which wasn't measured with the 4294A.
Thanks to you guys, who helped me for the first steps.
The equivalent circuit (used in the 4294A and in my program) is a capacitor with a parallel series of capacitor, inductor and resistor.
My Problem
The program works, but the fit parameters are really different from the ones the impedance analyzer calculated. I am not sure if my complex function is right. Maybe someone could have a look a the code.
Fitting of the 4294A
C0 = 466,094 pF
C1 = 72,1754 pF
L1 = 22,1951 mH
R1 = 6,3739 Ohm
Fitting of my LabVIEW Application
C0 = 695,885 pF
C1 = 115,8 pF
L1 = 13,972 mH
R1 = 2,687 Ohm
You will find attached
- A llb file which includes
- ComplexFit.vi (LabVIEW Code for the fitting, mainly the one from you)
- Complex_Function.vi (LabVIEW Code with my complex function)
- Z_C.vi (LabVIEW Code for a complex capacity, which is used in the Complex_Function.vi)
- Z_L.vi (LabVIEW Code for a complex inductor, which is used in the Complex_Function.vi)
- Z_R.vi (LabVIEW Code for a complex resistor, which is used in the Complex_Function.vi)
- Original.xls (Original Data out of the impedance analyzer 4294A including a screenshot with the fit)
- Input_File_LabVIEW.csv (The input data for the ComplexFit.vi - it the same data like the original.xls, just a bit modified for easy import in labview)
Thanks a lot for ypur help.
Best regards,
Michael
02-23-2010 12:07 PM
This fun thread again. I looked at your VIs and they look fine, the commas in the data got me at first. A few thoughts: The fit is very sensitive to your initial guesses, and it seemed to work fine for certain values after I tweaked the termination condition on the LM fit VI. Right click, create control, and use something like 1e-6 instead of 1e-8. It still didn't think it had converged, but the final values were pretty much in agreement with the Agilent values. It also helps sometimes to restrict the data to near resonance. Another trick I use is to fit the data once and then use those values as the initial guess for a second fit. Takes longer but works a lot of the time. Another thing to keep in mind is that your data is causal, or in other words, the impedance function is analytic, or in still other words, the real and imaginary parts are related. In some cases I find that the real part is more conducive to fitting so I just fit that part (at least to find initial guesses).
The other thought is that most of the issues are probably related to the finite differencing which takes place to estimate the derivatives. It is a pain, but I will usually find the analytic functions for the partial derivatives and use those. I may have this circuit somewhere, it is a matter of digging through some lab notebooks.