10-08-2011 08:26 PM
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.
Solved! Go to Solution.
10-08-2011 09:01 PM
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
10-08-2011 09:45 PM - edited 10-08-2011 09:45 PM
@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. 😄
10-20-2011 10:00 PM
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.