How to fit one function into the form of another?

I have a slightly complicated periodic function of one variable t, say g[t].

I want to do a least squares fit of that function into the form A*Cos[Ω*t]+B*Cos[2Ω*t], and figure out the values of parameters A and B.

Is there a way to do this in Mathematica? Thanks in advance!

• Do you want numerical values for A and B or symbolic values? Numerical is very straightforward. Symbolic may end up with very large expressions. It would be nice if we had some code from you so that we could play with it. – Hugh Apr 30 at 15:58
• Numerical values will do! Thanks. – Houndbobsaw Apr 30 at 16:02
• This post shows how to use Fourier to calculate a spectrum of values for A and B. Do you really just want the first and second harmonic? Roman's answer below will work fine for calculating individual values. An example from you would clarify what you want. If you can, please edit your post and add an example. – Hugh Apr 30 at 16:06
• Thank you! I think I Roman's answer suffices. – Houndbobsaw Apr 30 at 20:41