forum.alglib.net
http://forum.alglib.net/

Help needed for sine wave fit
http://forum.alglib.net/viewtopic.php?f=2&t=593
Page 1 of 1

Author:  kwinslow [ Wed Jun 27, 2012 1:08 pm ]
Post subject:  Help needed for sine wave fit

In VB.net, I need to fit data to a sine wave and extract the phase. The x,y data is in an array. I've never done any fitting like this before, but I feel ALGLIB has the tools to do it. I have not found any examples of this problem, but I'm sure its fairly common. Any help would be greatly appreciated. Thanks.

Author:  Ray [ Thu Jun 28, 2012 8:33 am ]
Post subject:  Re: Help needed for sine wave fit

Hi, So I think you try to find the parameters A and phi of the sinefunction y=f(t)=A*sin(2pi*f*x+phi). In the manual you should look at examples with lsfitcreatef function or lsfitcreatefg function. There it is explained very good.
So you have to choose: x=x[0], A=c[0], phi=c[1].
Dim x(,) As Double = New Double(,){{-1},{-0.8},{-0.6},{-0.4},{-0.2},{0},{0.2},{0.4},{0.6},{0.8},{1.0}} here you have to insert your x-data.
Dim y() As Double = New Double(){0.223130,0.382893,0.582748,0.786628,0.941765,1.000000,0.941765,0.786628,0.582748,0.382893,0.223130} and here the y-data

Dim c() As Double = New Double(){1,1} here you have to insert the startvalue {A,phi}.Here you have to choose values that are near to the expected A, phi. So if A is 50, an phi is 120 try with New Double(){40,100}.

I recommend you to take a sinefunction with some parameters (for example A=2 and phi= 100°) and calculate 10 values (x,y). With these values you let the programm calculate your parameters A,phi and so you can compare them to what you expect.
ok?

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/