10-16-2009 11:30 PM
Hello,
I have data sets that I have taken using Signal Express and am analyzing with DIAdem. I was wondering if there's a way to perform a curve fit with a user defined function - in particular one with differentials (and that also has a non-linear term). I know that I can take the derivative of a waveform channel, so if I could specify a function with a few different variables (channels) for input (say one for y, another for dy and yet another for d^2y) that could also handle a y^2 term, that would be perfect. Has anyone ever heard of doing this? I tried to look through all of the examples for DIAdem that I could find that sounded at all related without success.
Thanks, Myra
10-19-2009 05:32 PM
Hi Myra,
With the built in functionality of DIAdem I do not think that this is possible. DIAdem does interface with the LabVIEW Mathscript node, and it is possible that we may be able to use this. Do you have LabVIEW installed by chance?
07-26-2010 10:23 PM
Hi,
I had hoped that I wouldn't need to do this fit, but here I am again! I do have Labview installed, but I don't think I am proficient enough to write the code I would need to do this fit. Do you think there is existing code that I could use with minor modifications? I remember that in my previous research into this, I thought that the Xmath function of MATRIXx could handle it... although I'm not sure how straightforward that would be to learn to use.
Thanks, Myra
07-26-2010 11:02 PM
Hi again,
I was wondering if it would be possible to use the General LS Curve fitting for a DE...can this fit be used on multivariable functions? I thought perhaps I could take the derivative of the data and give it a different variable name (and likewise for the second derivative), and then apply the fit with three independent variables. Since I don't know how to build the observation matrix in Diadem (and don't know about the multivariable part), I'm kind of stuck here!
Thanks, Myra
07-27-2010 11:30 AM
Hi myra,
You can execute the "Differentiate" function on a waveform channel in DIAdem-- there's no problem there at all. Then you can use the Channel Calculator or the Calculation Manager to apply the formula you have in mind. This won't do any sort of fitting inherently, though, so you'd have to loop through parameter space and calculate your own distance/error function and keep track of the best fits yourself. That's probably not what you're looking for. The bottom line is that DIAdem doesn't do differential curve fits natively. You could use the least squares fit function you mentioned as the method of calculating the error of one of the parameter sets.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
07-27-2010 03:02 PM
Hi,
Thanks for the clarification.
Can Xmath work inside Diadem? I was hoping that by using that I could access some of the ODE solvers in Labview - or am I misunderstanding how one would use Xmath? Also, on the discussion boards someone brought up the idea of using GPIs within Diadem to access other code... I think that guy was intending to use some C code, but wouldn't it also work with a Labview vi? It seems that there are a lot of vis out there that I could utilize (hopefully) nearly as is - but do you think it would make more sense for me to just try to use them within Labview, instead of trying to incorporate Diadem? As I mentioned before, I'm not that comfortable with programming, especially with my really large data sets, but if that seems like the best way to go I'll give it a try.
I also have a question about using scripts - is it mainly for automation of the analysis in Diadem?
Thanks very much, Myra
07-28-2010 10:15 AM
Hi myra,
Xmath can work inside DIAdem, but only if you have LabVIEW installed on the same computer as DIAdem. I really don't know if Xmath would give you the curve fitting you're looking for.
The GPI-DLL approach is specifically for adding functionality to DIAdem with custom C code. You can wrap a LabVIEW DLL inside a GPI-DLL, but it's way easier to just call a LabVIEW VI with the object variable "LVRuntime" that is available in DIAdem VBScripts. DIAdem is natively automated with VBScripts, though it also has ActiveX servers so that it can be automated by an external program. I also don't know if LabVIEW has VIs that would do the curve fitting you want.
After I posted my answer yesterday, I got to thinking that I hadn't looked into this closely enough-- I've not worked with the "General LS Linear Fitting" ANALYSIS function much at all. So today I created a little example of f(x) = 1.1*sin(2pi*x) + 0.9*cos(2pi*x). I generated the f(x) channel, a channel with just cos(2pi*x) values and another channel with just sin(2pi*x) values. Then I ran the "General LS Linear Fitting" ANALYSIS function using the f(x) channels as the "Y-channel" parameter and both the sin and cos channels in the "Matrix" parameter (which is a list of linear superposition compenent channels). The result was a new "GenLSFit" channel with the values 1.1 and 0.899999999999998. So I think we've got you covered with native DIAdem functionality after all. You just need to generate each term that adds in your equation as a separate channel. So if you have a constant term, a first derivative term, and a second derivative term, then you would create those 3 channels first, then run the "General LS Linear Fitting" function with each of those 3 component channels in the "Matrix" parameter. The order of the resulting coefficients in the "GenLSFit" channel is the same as the order of the component channels in the "Matrix" parameter.
Please ask if you have questions about this,
Brad Turpin
DIAdem Product Support Engineer
National Instruments
07-28-2010 05:50 PM
Hi Brad,
Thanks for your help! That was what I had hoped I could do - I hadn't tried it yet because I wasn't sure how to make the matrix but I'll try it now with your example. After that I'll practice using my equation (by creating the data), then give the real thing a go. I'll let you know how it works.
Thanks again,
Myra
07-30-2010 05:18 PM
Hi Brad,
I'm having a bit of trouble understanding the results of the General LS fit in Diadem. It outputs two files - GenLSFit and GenLSFitCoefficients. It's not completely clear what the best fit coefficients are in these files, or which of the matrix terms they correspond to. Each file has values labeled 'minimum' and 'maximum', and in one of the cases there was a pretty big range between these two - I didn't expect that since I calculated f(x) (I mean, there's no noise in it). I tried this a few times with different coefficients, and once it seemed that each file corresponded to a different file, but in another it seemed that GenLSFitCoefficients file contained both of the coefficients - one for min and one for max. I don't know if there is a problem with the way I set up the initial matrix? I used the example that you gave, and for the matrix just selected the files corresponding to x, sine, and cosine. I also found that when I added a third term, the coefficient corresponding to the second term didn't seem to show up in either of the result files. I couldn't find any material on how to interpret the Diadem output - do you have any suggestions for it?
Thanks, Myra
07-31-2010 03:37 PM
Hi myra,
I expanded my example to include N sinusoidal components and discovered that you only get the results you expect if your superposed components are truly independent (orthoganal). I first tried f(x) = 1.1sin(x) + 0.9cos(x) - 0.8sin(x), and the General LS Linear Fitting algorythm dutifully calculated 3 different coefficients, but they weren't 1.1 and 0.8, though the 0.9 was exactly correct. Then I realized that this formula could be simplified to f(x) = 0.3sin(x) + 0.9cos(x), and that it was unfair of me to ask for 3 coefficients when I should be asking for 2. Take a look at the N=4 sinusoidal components in the example I'm attaching. I'm confident that the algorythm returns the correct coefficients as long as the component channels really are different.
Brad Turpin
DIAdem Product Support Engineer
National Instruments