MATLAB Answers

0

Sine curve fit to data with an unknown dc offset

Asked by Jerry Yeung on 10 Jul 2019
Latest activity Commented on by Jerry Yeung on 11 Jul 2019
Hi. Apologies if this has been answered before, but I'd like to know if there's any way of fitting a sine curve to a sinusoidal function with unknown frequency and unknown DC offset? The function I'm trying to fit to is a standing wave and is most likely sinusoidal, but is less than half a period long.
Thanks in advance for the help.

  0 Comments

Sign in to comment.

Products


Release

R2019a

1 Answer

Answer by John D'Errico
on 10 Jul 2019
 Accepted Answer

Of course it is possible. Use the curve fitting toolbox.
ft = fittype('a + b*sin((x - c)/d)','indep','x');
mdl = fit(X(:),Y(:),ft,'startpoint',[1, 0.001, 1200, 1000])
I just picked off some very rough starting values from the plot.
Here, a is the DC offset. b is the amplitude of the wave, c is the shift in X, d/(2*pi) is the length of the period. You can transform that to give you frequency.

  1 Comment

Ah, so that's how you use the fittype function. Thanks for the help.

Sign in to comment.