# Fitting a sine curve that isn't a perfect sine curve?

1. Mar 31, 2013

### Phystudent91

For my 3rd year project, I have a set of data which is the variation within an interference pattern.
The outcome has clear sine curve properties (Alternating peaks and troughs of intensity) but the positions aren't regular (i.e. the peak-to-peak distance between peak1 and peak2 is larger than the distance between peak2 and peak3).

I have tried using SciDAVis to plot this curve but it finds a best-fit/average kind of sine curve, not a fit that passes through all the available points. Is there a method or program that will help me?

I would preferably be able to make a note of the equation of the curve in order to plot it with other sine curves of the interference pattern from other varying distances from the sources.

2. Mar 31, 2013

### mikeph

I'm not sure what the program you're using is, but if your specified model function is a sine wave then it won't be able to account for the frequency variation you describe. Can you find any simple relationships between the peak-to-peak distances? The model function might take the form f(x) = a*sin(x*g(x)), where g(x) can be some linear function in x, say, g(x) = bx + c.

3. Apr 1, 2013

### JJacquelin

If your data extends over a number of periods, try Fast Fourier Transform (FFT).
If the data extends over only a narow range (a few periods or only a part of a period) and if the expected function patern is y=a*sin(w*x+b)+c, you may try a non-linear regression in order to compute w, a, b, c. This is a difficult problem. The methods are rarely reliable, depending a lot of the data (number, distribution, scatter). Generally, they use some iterative algorithm :
http://mathworld.wolfram.com/NonlinearLeastSquaresFitting.html
A especially non-iterative algorithm for the sinusoidal case is presented in pages 35, 36 of the paper " Régressions et équations intégrales" :
http://www.scribd.com/JJacquelin/documents

Last edited: Apr 1, 2013
4. Apr 1, 2013

What you are trying to fit is probably not enough of a sine wave to fit it like that. What you could do, if the fft doesn't work, is trying to extract the phase $\phi(t)$ and then fit a linear (polynomial) function through it for example. The most simple way to do it, is taking the average value of the function, define it as zero and find the zero crossings. These points represent a phase of $\pi,2\pi,3\pi,\dots$. You could also do this with the maxima and minima. It is a bit of a hack, but you might get some useful information.

5. Apr 5, 2013

### zunzun

You can try the "function finder" on my curve and surface fitting web site, http://zunzun.com - it is free and won't cost anything to give it a try. You can limit the function finder to trigonometric equations only. The direct link is:

http://zunzun.com/FunctionFinder/2/ [Broken]

If you need any help with the site, contact me directly:

James Phillips
Personal Info deleted

web: http://zunzun.com

James

Last edited by a moderator: May 6, 2017