Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

benj

Member

06-28-2011 02:28 PM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

altenbach

Knight of NI

06-28-2011 02:42 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.

johnsold

Knight of NI

06-28-2011 08:23 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

Henrik_Volkers

Trusted Enthusiast

06-29-2011 06:39 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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...

Greetings from Germany

Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

Download All

Virus scan in progress. Please wait to download attachments.

altenbach

Knight of NI

06-29-2011 10:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

altenbach

Knight of NI

06-29-2011 01:40 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.

- x is an array of times (optional, you can incorporate the x0, dx in the model since the points are linearly spaced)
- y is a 1D array containing your signal.
- f(x,a) is a strictly typed VI reference that contains the model, in your case Y = Y(t)=A * sin(2pi * B * t + C) + D (Check the help for details and where to dinf a template).

@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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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

altenbach

Knight of NI

07-11-2011 10:56 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@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)

altenbach

Knight of NI

07-11-2011 11:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

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.