I'm getting a lot closer...
I found this video, but it conveniently cut off right before the useful part. Its as if the math gods are laughing at me.
I then found this excel sheet
So it appears the basic approach to determining the Fourier coefficients from sampled data is to sum up the individual terms over one cycle. Then averageish the sum to get the coefficient.
What I don't fully understand in the spreadsheet is why they are summing every other sample (i.e. call D7 ---> =C6+4*C7+C8) and dividing by 3/180 (see the cells in row 3).
I'm also not clear on what X would be in time sampled data. In the spreadsheet it is an angle. In sampled data, would it just be the percentage of the total sample time scaled to 2PI (i.e. the x value of the middle sample would be PI... the sample 25% of the way through the time period would be PI/2... 75% would be 3PI/2, etc.)?
It's missing from the spreadsheet, but if you do a column with this formula:
=$D$3/2+$E$3*COS(B6)+$F$3*COS(2*B6)+$G$3*COS(3*B6)+$H$3*COS(4*B6)+$I$3*COS(5*B6)+$J$3*COS(6*B6)+$L$3*SIN(B6)+$M$3*SIN(2*B6)+$N$3*SIN(3*B6)+$O$3*SIN(4*B6)+$P$3*SIN(5*B6)+$Q$3*SIN(6*B6)
And then plot that column and column C, the function above fits the measured data. You could probably drop off the coefficients that are really small, but that is data dependent.
You have a comment # Make sure that input signal is a power of two!
but then you input a vector of length $500$. This seems like asking for trouble. If your algorithm requires the input to be in a certain form, it's a good idea to raise an exception when it isn't!
Best Answer
The frequency at 0 Hz is equal to the mean of the data.
So you can just discard that frequency if it does not interest you. Subtracting the mean before calculating the FFT has the same effect. If it doesn't then there is a calculation mistake.