LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

fit curve with equation

Solved!
Go to solution

I have a program in which I get a response signal that is of the form  A*cos(w*t)*exp(-t/T2), where A is amplitude, w is frequency, t is time, and T2 is spin relaxation time. Is there any way to fit a curve to this graph and ouput the values of the variables? I have tried many of the options in labview but cannot seem to find a way to add the T2 variable. 

 

Thanks,

Justin

0 Kudos
Message 1 of 10
(3,665 Views)

Hi!

Try using the "Curve Fitting" Express vi.

By selecting "Non-linear fit" in the configuration panel you can define your own fitting function with all your three parameters.

 

Marco

0 Kudos
Message 2 of 10
(3,650 Views)

For some reason every time I try to enter my formula into the non-linear model input box the indicator to the right turns red and it doesn't allow my inputted equation. I am fairly certain that the form in which I inputted the equation is correct so I am not sure what the problem is unless it does not work with both cosine and exponential fxns or something of that nature.

 

Thanks,

Justin

0 Kudos
Message 3 of 10
(3,635 Views)

 

Disregard my second post. You are right, Marco, it works, I'm not sure what I was doing wrong before. But, I have related question.  Is there any way to get the VI to output the final values of the variables after the curve has been produced? Or is there another way to fit a curve that would do this?

 

Thanks,

Justin

0 Kudos
Message 4 of 10
(3,617 Views)

My last choice would be the Express VI, my next-to-last choice is to use the Nonlinear LM fit with a formula string as the input.  Still an improvement (IMO) over the Express VI.  If I had to guess about your previous trouble, it is probably that you were using A and T2 as variables instead of a and t2.

 

Here is a quick example to generate fake data and fit it to your function.

 

 

0 Kudos
Message 5 of 10
(3,610 Views)

I should have mentioned I am on labview 8.6.  Is there any way that you could attach that in as an 8.6 compatible version or attach a screen shot of the block panel?

0 Kudos
Message 6 of 10
(3,601 Views)
Solution
Accepted by topic author jstrad
0 Kudos
Message 7 of 10
(3,597 Views)

I am not sure how to draw out the x and y arrays from my response to input into the Lev-Mar vi that you used in your example. My response signal is waveform(DBL) that is outputted from a DAQmx read vi. I have attached my vi along with the necesary subvi's.  The one in question is Signal and Response. The data that needs a curve fit is outputted from the Record.vi subvi.

Download All
0 Kudos
Message 8 of 10
(3,550 Views)

Hi Justin,

 

If the data is in a waveform format, you can use "Get Waveform Components" to extract out dt, t0, and Y values.  If you need an array of X, you can use the dt and t0 values to build it.

 

Cheers,

 

Marti C
Applications Engineer
National Instruments
NI Medical
0 Kudos
Message 9 of 10
(3,481 Views)

It turns out he real reason it wasn't working when I tried all of your suggestions was a hardware issue. Thank you all very much for your time and help!

 

Justin

0 Kudos
Message 10 of 10
(3,441 Views)