LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Curve fitting sin*Exp

Hi,
I have a few questions,
1- Can I put my initial guesses to the `curve fitting express` via an array control instead of editing each time the express itself?
2- I have trouble with the fitting of my signal. it`s far beyond my initial guesses. I tried playing with the numbers and it seems when I put the right numbers in the function instead of using the parameters, the fitting is perfect, but when I put the same numbers as initial guesses I don`t get even close to data fitting, instead I get most of my signal as a residual.can someone help?
3- the fitting itself takes ages, is there any way to make it faster?
 
SubVI, and the text data file attached.
thanks.
Smiley Indifferent
Download All
0 Kudos
Message 1 of 4
(3,893 Views)

You are trying to fit

y(x)=a*cos(b*x)*cos(c*x)*exp(d*x)+e

with [a, b, c, d, e] as adjustable parameters. This seems like a poorly defined model, for example you will have an equally good solution swapping b and c. Also from looking at the data, d should be negative, yet you give it a large positive value as guess. Periodic functions such as "cos" (I am not sure why you use "sin" in the title of the post) are always problematic, because you can fit equally well to an alias frequency by mistake. You need to be absolutely sure about good initial guesses here. Is the model really sufficient? For example, you don't account for possibe phase.

Your file also does not contain enough significant digits, so there are multiple x values for each y. It seems however, that the x-values are linearly spaced, so it is possible to approximate the real x ramp (see attached).

Anyway, to your question. You can skip the express VI and use "nonlinear curve fit" instead. If speed is a concern, you should use the VI model, which is pretty simple in this case. (fitting takes much less than a second)



Aristofel wrote:
... I tried playing with the numbers and it seems when I put the right numbers in the function instead of using the parameters, the fitting is perfect,...

Is this synthetic or real data? As a first step, you should generate fake data with known parameters and see how well the fit does if the estimates are somewhat off.

What are the "right numbers" in this case?
 
In any case, Your problem is probably better solved using e.g. a fourier transform. You should get two lorentzian peaks with the midpoint between the two related to (b) the separation between the two related to (c) and the lorentzian width related to (d). Your data gives a much more complex transform, so your model seems way too simplistic for your data anyway.
Can you give us a bit more background on the origin of the data, the physics behind it, and the model?
 
Attached is a literal translation of your VI to the plain "VI model" fitting. Still, nonlinear fitting seems to be the wrong choice for this problems as outlined above.
0 Kudos
Message 2 of 4
(3,865 Views)
Hello,
Firstly, thank you for your quick reply!
 
The data is experimental and generally it looked like  a*sin(wx)*Exp(-tx)+c
 
concerning the phase shift, the model with the 2 cosine functions seemd to give a better fit. but yet its too simplistic as you said.
Indeed the FFT spectrum is quite complex, therefore,I`m still tryng to figure how to analyze the signal.
 
The signal is actually a short force pulse applied on a piezo crystal so I get a decaying graph of Volts=f(time)
I want to get the following 2 parameters from the signal:
*tau- time of decay to 37%
*Amplitude of the signal
and any other parameter that could define uniquely such signal for different materials.
 
I thought I might get those parameters from the curve fit.
I`m not sure how to handle the complex fourier transform and which lorentzian could give me the 1/pi*tau
 
hope you could help,
:manhappy:
0 Kudos
Message 3 of 4
(3,842 Views)
Did anyone had an experience with multi frequency exponential decay?
how should I fit/treat such signal?
 
Good day,
0 Kudos
Message 4 of 4
(3,788 Views)