From: Filoche on
Hi everyone.

I was using the cftool to fit a curve for the following general equation :

a1*sin(b1*x + c1)

The parameters estimated by the cftool were giving good results. However, since I have allot of series to fit, I was thinking to use the fit function.

The problem I have is to guess the starting values of my 3 parameters (a1,b1 and c1). I was wondering how the cftool was guessing them, since the results obtained with this tool are much better then what I can obtain with my own guess. I tryed to omit starting values (so they are randomly generated), but it don't work well either.

Best regards,
Phil
From: Tom Lane on
> I was using the cftool to fit a curve for the following general equation :
>
> a1*sin(b1*x + c1)
>
> The parameters estimated by the cftool were giving good results. However,
> since I have allot of series to fit, I was thinking to use the fit
> function.
>
> The problem I have is to guess the starting values of my 3 parameters
> (a1,b1 and c1). I was wondering how the cftool was guessing them, since
> the results obtained with this tool are much better then what I can obtain
> with my own guess. I tryed to omit starting values (so they are randomly
> generated), but it don't work well either.

Phil, you can look at the implementation of this guessing algorithm in the
file

toolbox/curvefit/curvefit/@fittype/private/sethandles.m

Basically, it uses fft to find a good guess for the frequency. Then it uses
plain linear regression to find the other parameters given the frequency,
making use of the trigonometric identity between a phase-adjusted sine and a
sum of sines and cosines.

-- Tom


From: Filoche on
Thank you Tom for your answer. I appreciate it.

Phil