Fitting a sinusoidal curve to a set of data points
41 ビュー (過去 30 日間)
古いコメントを表示
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
2015 年 2 月 16 日
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
2015 年 2 月 16 日
Maryam's "Flag" moved here to be a comment:
Thanks for the detailed answer!
採用された回答
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
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 Exchange で Interpolation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!