views:

530

answers:

4

Is there an algorithm that can be used to determine whether a sample of data taken at fixed time intervals approximates a sine wave?

A: 

Check the least squares method.

@CookieOfFortune: I agree, but the Fourier series fit is optimal in the least squares sense (as is said on the Wikipedia article).

If you want to play around first with own input data, check the Discrete Fourier Transformation (DFT) on Wolfram Alpha. As noted before, if you want a fast implementation you should check out one of several FFT-libraries.

jacob
The sine wave probably has a phase offset, which would make using the least squares method more difficult to implement.
CookieOfFortune
A: 

Shot into the blue: You could take advantage of the fact that the integral of a*sin(t) is a*cos(t). Keeping track of min/max of your data should allow you to know a.

pmf
∫(a·sin(k·t+m) + b) dt = (-a/k)·cos(k·t+m) + b·t + C
MizardX
I'm not sure this is a fruitful direction to go in. However, there might be use in noting that the 2nd derivative of a sine is proportional to, and negative, of the original. d2/dx2)sin(kx) = -k^2 sin(x). To reduce effects of noise and roundoff error, use a smoothing derivative - read up on Savitzky-Golay filtering.
DarenW
+14  A: 

Take the fourier transform which transforms the data into a frequency table (search for fft, fast fourier transformation, for an implementation. For example, FFTW). If it is a sinus or cosinus, the frequency table will contain one very high value corresponding to the frequency you're searching for and some noise at other frequencies.

Alternatively, match several sinussen at several frequencies and try to match them using cross correlation: the sum of squares of the differences between your signal and the sinus you're trying to fit. You would need to do this for sinussen at a range of frequencies of course. And you would need to do this while translating the sinus along the x-axis to find the phase.

Rutger Nijlunsing
Sinussen - sini?
Tom Anderson
Plural seems to be sinus also... That's the problem when not typing in your mothers tongue. Sinai then :) ?
Rutger Nijlunsing
A good estimate of the quality will be the height of the very high peak, divided by the sum of the heights of other peaks. Using this measure, 1 means a perfect fit, 0 means no fit at all.
Martijn
Martijn, that is called THD (http://en.wikipedia.org/wiki/Total_harmonic_distortion) or THD+N, depending on what you include.
endolith
+7  A: 

You can calculate the fourier transform and look for a single spike. That would tell you that the dataset approximates a sine curve at that frequency.

driis
that does unfortunatley only work if the sine-wave has exactly the same frequency as one fft-bin. If it's somewhere between the bins you get a completely different spectrum.
Nils Pipenbrinck
You will get a single prominent spike no matter what the frequency is. The question doesn't ask to determine the frequency; just to determine whether it's a sine or not.
endolith