LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sine Wave Fitting

Solved!
Go to solution

Hello all,

 

I am trying to fit a sine wave to a 2d array of X/Y data. I have searched into options like "Extract Single Tone Info.vi" and the Lev-Mar vi's, but it seems like they all require data points that are evenly sampled and unfoturnately mine are not.

 

I do happen to know the frequency which should help things.  Take a look at the attached picture to see what the data looks like. I can post a csv of the actual data if that would help clear things up.

 

Any help would be greatly appreciated. Thanks.

0 Kudos
Message 1 of 4
(7,996 Views)
Solution
Accepted by durkonion

Lev-Mar is probably your best choice.  In the Signal Processing >> Waveform Conditioning palette are several resampling VIs, including one which will accept a cluster of X and Y arrays of data and produce an output uniformly sampled witha specified dt.

 

Knowing the frequency helps a lot.  Lev-Mar is not very good at finding the frequency so a good initial guess is important.  With only one cycle FFT based VI like Extract Single Tone do not work well.  FFTs are much happier with at least 5-10 cycles and more is preferred.

 

If you know the frequency exactly you could generate a sine and cosine of that frequency and multiply the data set by those reference signals. Then average the products over one cycle. The DC component of the result will be the sine and cosine of the phase angle between the reference signals and the input signal.  Look at the trignometric expressions for the product of two sines.

 

Lynn

Message 2 of 4
(7,994 Views)

@durkonion wrote:

I am trying to fit a sine wave to a 2d array of X/Y data. I have searched into options like "Extract Single Tone Info.vi" and the Lev-Mar vi's, but it seems like they all require data points that are evenly sampled and unfoturnately mine are not.



Lynn already touched the critical points. The nonlinear fit tools accept an X array which does not need to evenly sampled or even sorted. They should work well for your kind of data (~1 cycle), especially if you have reasonable parameter estimates.

 

See how far you get. If you get stuck, show us what you have and attach some typical data. 😄

0 Kudos
Message 3 of 4
(7,988 Views)

Thanks guys. I did some more searching and played around with it some more and finally got it to work.  I'll post it up here for posterity. It's pretty simple actually.

 

What really threw me off was in the circle fit example they were wiring an array of 0's into the Y input on the Lev-Mar VI. Still not quite sure why they did that.

 

 

Download All
Message 4 of 4
(7,953 Views)