I have data I would like to plot, and more importantly, do a least squares regression on using cosines (instead of using polynomials): http://imgur.com/AkEaE.png
Any recommendations? Thanks.
I have data I would like to plot, and more importantly, do a least squares regression on using cosines (instead of using polynomials): http://imgur.com/AkEaE.png
Any recommendations? Thanks.
You might find this demo Least Squares & Data Fitting helpful since it solves a few of your problems.
Just a bit of cautionary advice. Using a Fourier series makes sense if you think your underlying function has a cosine series as a basis; however, if you are using it as a basis for an arbitrary function (with unknown shape), you may do better trying to guess at a more specific underlying function type (polynomial, exponential, etc).
I did some constrained optimization on such a series, and the function wiggled around so much it was hard to say if my fit was meaningfull; my fit function had great number of local maxima.
Probably the following page solves the regression part of your aim:
http://www.teneighty.org/software/index.html?f=fft&c=e98b8