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

slucas

Member

03-13-2007 03:44 AM

Options

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

thank you in advance.

lucas

Mikk

Member

03-13-2007 05:53 AM

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

03-13-2007 11:48 AM

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

lucas

johnsold

Knight of NI

03-14-2007 08:14 AM

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

I have found in some preliminary testing that fitting to sine is tricky. The Lev-Mar fit VIs work quite well if you have a portion of one cycle. If you have ten cycles it will not work unless the initial guesses are very close to the correct values.

I think it has to do with the fact that the partial derivatives of sin(2*Pi*f*t) with respect to f do not force the function to move toward the correct value for the fit. I am not working on this at the moment but intend to return to it some day.

Lynn

03-15-2007 07:37 AM

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

but ultimately i am using the fit to find the roots, t at y=0, values. so partial fits are ok for me where i load the fit with 95% of one side of the sine wave, either the negative slope side or the positive slope side. when i plot the "best nonlinear fit" points against the original raw sine data, it matches up beautifully. however, when i attempt to solve for the equation at y=0 usng the "best fit coefficients", i get some ungodly roots. like say the root should be like 2271.9. when i solve, i will get -803,432.233. and it is not a simple number of integer cycles because i tried those divisions and i am not get close to integer values.

so i am wondering how to solve for the damn equation now.

lucas

03-15-2007 07:43 AM

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

lucas

03-15-2007 07:52 AM

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

lucas

johnsold

Knight of NI

03-15-2007 08:07 AM

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

Lynn

Mikk

Member

03-16-2007 01:49 AM

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

more easily by simply taking an FFT. You can then find the largest amplitude component,

which would be the frequency that you are trying to detect. The phase of that component

is what you get from the sine function fitting. An FFT does not require parameter guessing

and is much faster than fitting.

DSPGuy

Active Participant

03-16-2007 11:51 AM

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

What version of LabVIEW are you using? Do you have any data you could share? If you are using LabVIEW 8.0 or later, then there is a VI that could be a real help. Take a look at Extract Multiple Tones.vi. This is similar to the Extract Single Tone.vi, except it will find more than one tone. It is also a diffent algorithm that the single tone extraction. The DC offset in your signal will appear in the "multiple tone info" output as a very low frequency tone (milli-Hz to micro-Hz). Even if you continue to use the Nonlinear Curve Fit.vi, this could give you a very good initial guess, particularly for the frequency.

You also mentioned using a numerical root finder to find the zero crossings. Given your model (A*sin(wx+p)+b) it seems that you should be able to solve explicitly for x.

a*Sin(wx+p)+b = 0

Sin(wx+p) = -b/a

wx+p = InvSin(-b/a)

x=(InvSin(-b/a)-p)/w

This will give one level crossing (level of zero), and adding full periods will give every other crossing, but the alternate crossings are not half-periods from the crossing x, unless the offset in the model is zero.

You could view the set of crossings as all x that satisfy:

a*Sin(wx+p+kPi) = 0 where k is an integer,

expanding in Sin and Cos:

a*[Sin(wx+p)*Cos(kPi) + Cos(wx+p)*Sin(kPi)] = 0

Sin(kPi)=0, so

aCos(kPi)Sin(wx+p)=0

let A=aCos(kPi)

solving for x as before gives:

x=(InvSin(-b/A)-p)/w

Using this approach and the Extract Multiple Tones.vi seems to give very good results for the zero crossings on some simple data I tried here (Sine + Gaussian Noise).

The use of local polynomial models will work but if you can involve the entire dataset in solving for a model then there is more "averaging" of the noise in the data and the results should be more robust. If your data does not match the model well, or the model changes over the course of the data (non-stationary), then Lynn's approach is better.

Hope this helps.

-Jim