06-28-2011 02:28 PM
Hi,
I would like to fit my data (about 200 kpoints) with a sine-wave (with 4 parameters : A.sin(2pi.B.t + C) + D) in LabVIEW. I'm looking for a VI with a convergent algorithm (such as least-square solver) which return me the 4 parameters + the RMS error betwen measurement data and model data. Or why not a more efficient algorithm...
I have a look in "Optimisation function set" and also in "Ajustement function set" but I didn't find the good VI, Someone can advice me ?
Regards,
Benjamin
06-28-2011 02:42 PM
This is a fit, not an optimization. Look for nonlinear curve fit.
How many cycles do you have in your dataset? Make absolutely you have reasonable paramter guesses or you'll end up finding an alias frequency.
06-28-2011 08:23 PM
As altenbach said, fitting to a sine is not a straightforward process. The fitting algorithms tend to use derivatives to "move" the values of the parameters toward the desired function. However, the derivative of sine(Bt) is a function with the same frequency, so it does not tend to find the correct frequency well.If you have multiple cycles in your data an FFT can give you a good estimate of the frequency to use as a starting point for fitting.
Lynn
06-29-2011 06:39 AM
You can use the levenberg-marquard fit , but usually the extract single tone information work good enough 🙂
There is a paper from 99 ni'week about the performance of this vi, I added it, because I missed the link
Depending on your signal, it might be wise to try blocks of complete periods and mean the results....
I attached a vi that uses this single tone vi to monitor the line frequency , just abuse a headphone as a coil receiver and plug it into the mic input of your soundcard and place the headphone near a transformer...
06-29-2011 10:42 AM
That's why I asked about the number of cycles. If the number of cycles is very small and fractional, FFT based algorithms won't work well because of spectral leakage and theoretical limitations. It would get even harder of the offset D is much larger than A, for example.
Also, you quote A.sin(2pi.B.t + C) + D), but your paranthesis are no balanced. Guessing Y(t)=A * sin(2pi * B * t + C) + D
Can you attach some typical data so we get a beter idea what you are talking about.
06-29-2011 01:20 PM
Hi,
Thanks for your answers,
First, I know well my signal and I can give to the algorithm very good first approximation of each parameters. For instance, with a FFT transform, I have a very near value of the real frequency value with no ambiguity with others harmonics (my sine-wave is very pure).
Secondly, I have very huge data which as sampled at 20 GSa/s by a numerizer and frequency signal is from 1 MHz to 10 GHz. So, I have a lot of periods but for bigest frequencies there arn't a lot of sample/period.
I saw the VI "Nonlinear Curve fit" but I didn't understand how to use it.
What is "data", "x" and "y"inputs in my case ?
What must I wire to "f(x,a)" input ?
@altenbach : what is the diference between fit and optimization ? Fitting methods can work without an optimization stage ?
Regards,
Benjamin
06-29-2011 01:40 PM
benj wrote:I saw the VI "Nonlinear Curve fit" but I didn't understand how to use it.
What is "data", "x" and "y"inputs in my case ?
What must I wire to "f(x,a)" input ?
Have a look at the example finder. THere are quite a few fitting examples.
@benj wrote:
@altenbach : what is the diference between fit and optimization ? Fitting methods can work without an optimization stage ?
While they are closely related, they are different mathematical disciplines. In LabVIEW they are in different sub-palettes.
Have a look at the VIs in each. Fitting typically deals with parameterizing real data according to a mathematical model, while optimization typically deals with finding key points (e.g. a minimum) of a mathematical model functions.
07-11-2011 04:36 AM
Hi,
I fist worked about acquisistion problem and I have just come back my sine-fitting subject.
1) I did a "sin model VI" :
2) I did another VI which call my model and use "Fit non linear....vi"
3) but I obtain this message error :
What is the problem ?
What about my solution for calling the "sin model.vi". It looks like complicated to obtain the VI refnum but it works ? Is there a easier way to do it ?
For more details, you can download my project (.zip).
Regards,
Benjamin
07-11-2011 10:56 AM
@benj wrote:
It looks like complicated to obtain the VI refnum but it works ? Is there a easier way to do it ?
Yes, use a static VI reference, point ot to the model, and make it strict.
(I'll have a look at your code later)
07-11-2011 11:03 AM
benj wrote:
What is the problem ?
Look at the blue diagram constants! You are indexing element 2 twice and omitting element 3.
If you want elements in order, you should never wire the indices of index array. Delete all these blue diagam constants and it is much less likely to make mistakes like that.