EDIT
The code to obtain the 3d plot was:
m1 = A Sin[2 \[Pi] f t] + B Cos[2 \[Pi] f t];
m2 = A Cos[2 \[Pi] f t + B];
data = Block[{A = 43, B = 94, f = 1/8},
Table[{t, m1 + 5 RandomReal[II]}, {t, 0, 30, 0.1}]
];
gdata = ListLinePlot[data]
fit1a = NonlinearModelFit[data, m1, {A, B, f}, t, Method -> Automatic];
Show[gdata, Plot[fit1a[t], {t, 0, 30}, PlotStyle -> Red]]
fit1b = NonlinearModelFit[data, m1, {A, B, f}, t,
Method -> "NMinimize"
];
Show[gdata, Plot[fit1b[t], {t, 0, 30}, PlotStyle -> Red]]
{x,y} = Transpose[data];
My = Mean[y];
ClearAll[error];
error[model_, {AA_, BB_, ff_}] :=
Block[{A = AA, B = BB, f = ff},
Norm[y - model /. t -> x]/My
];
The error plot above comes from:
Plot3D[error[m2, {103.3, B, f}], {B, -\[Pi], \[Pi]}, {f, 0, 1},
PlotRange -> All, AxesLabel -> {"B", "f"},
ColorFunction -> "Rainbow", MaxRecursion -> 3
]
With respect to Fourier:
afy = Abs@Fourier[y];
Pick[Range[0, Length[afy] - 1], afy, Max[afy]] // N
{4,297}
Note that 30 is the sampling time of the signal:
m1f = A Sin[2 \[Pi] (4/30 + f) t] + B Cos[2 \[Pi] 4/30 + f) t]
fit1f = NonlinearModelFit[data, m1f, {A, B, {f, 0}}, t,
Method -> Automatic
];
Show[gdata, Plot[fit1f[t], {t, 0, MT}, PlotStyle -> Red]]
Now, even with the Automatic method, since the frequency is centered around a close-to-optimal value, the fit comes out correctly.




