Fitting a sinusoidal curve to a set of data points

41 ビュー (過去 30 日間)
Maryam
Maryam 2015 年 2 月 15 日
コメント済み: Image Analyst 2015 年 2 月 16 日
I have a few sets of data points that I need to fit a sine curve of the form A*sin(B*X+C)+D on each data set. I don't know A, B, C and D (which defer for each data set) but I have access to cftool. I wrote a function (by generating the code from cftool) which doesn't work well for some data sets and I believe it's because of the wrong "start point". I wonder how to determine the startpoint for each fitting?! and if this is not possible, is there any other advice to fit the sine curve and get the coefficients (or generated data)?!
Thanking in advance,
Maryam
  5 件のコメント
John D'Errico
John D'Errico 2015 年 2 月 16 日
There is a tool on the FEX, called fminspleas . It does all of the hard work for you.
All you will need to do is define the function to be used. Here they would be something like...
funslist = {1, @(coef,xdata) cos(coef*xdata), @(coef,xdata) sin(coef*xdata)};
Fminspleas will return 4 coefficients, in two different return variables. Here, Bstart is the starting value for B. It is the ONLY one you need to provide.
[B,ILP] = fminspleas(funslist,Bstart,x,y);
D = ILP(1);
C = atan2(ILP(2),ILP(3));
A = ILP(2)/sin( C );
(I think I got those back-transformations right, but I wrote them down quickly, so worth checking.)
Image Analyst
Image Analyst 2015 年 2 月 16 日
Maryam's "Flag" moved here to be a comment:
Thanks for the detailed answer!

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2015 年 2 月 15 日
The easiest way to get ‘B*X’ is to use the fft function. You know ‘X’, so calculate to estimate ‘B’. (I leave the details of that to you.)
Find the mean of the curve to estimate ‘D’, and find the maximum of the absolute value of the function after subtracting the mean to estimate ‘A’.
This leaves ‘C’ without an initial estimate, but with three relatively close initial estimates for the others, ‘C’ should be relatively straightforward to estimate in your regression.
Good luck!
  1 件のコメント
Star Strider
Star Strider 2015 年 2 月 16 日
@Maryam —
With respect to ‘C’, since it is a phase term and likely between 0 and 2*pi, an initial parameter estimate with any number in that range, for instance 1 as you suggested, would probably work.
As for an example, an initial parameter estimates vector, ‘B0’ here, would be (in ABCD order) and denoting your data as ‘y’:
B0 = [max(abs(y-mean(y))), |B|, 1, mean(y)];
I left ‘B’ as is because you would get that estimate from the fft of your data.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by