How to determine which Fouriers Series terms to use to approximate a signal? I have a signal (a time-series of air temperature values) that I can approximate quite well with a Fourier series. However, the number of terms in the series grows rapidly, to the point that 30 - 40 terms are needed for a good fitting.

So I was trying to understand how can I select only the Fourier series coefficients that convey the most information about the signal, and discard the others.

I could simply choose values of the series parameters a and b above a certain threshold value, but I do think this is not the right way to go.

I need to limit the number of terms because this approximate function will later be used for further elaborations, and the function must be input manually in the code (suggestions on how this task can be automated would be appreciated too).

I am not trying to predict future temperature or anything like that, I just need a function that can reproduce temperature oscillations with minimum period of ~12 hours.
Your inclination to choose the largest magnitude coeffecients is the correct one.  There is a Linear Algebra explanation for this having to do with orthogonaility.

However, your second question is more pertinent, I think.  If your sole motivation for reducing the coefficient count is to reduce data entry effort then you are much better off formatting the output of your DFT analysis as syntax for inputting into your code.  Then a simple copy and paste will do the job for you.  You also greatly reduce your exposure to data entry errors.  Depending on the volume, a custom programming solution which automates the copy and paste process might be economical.

Hope this helps.

Ced