Integration packages to calculate the first N Fourier coefficients

More infomation is needed.

Sampled data = experimental data? From a simulation? Noisy? Smooth function? If it is from a computer program, then can you evaluate it on demand for any desired x?

When you say “N Fourier coefficients” do you mean that the data is periodic and you want a Fourier series? If it’s not periodic, then what do you mean?

If you have equally-spaced samples of a periodic function, then a Riemann sum actually converges exponentially fast (with the number of samples) for smooth functions.

(However, adaptive methods like QuadGK can still be advantageous for functions with localized features like sharp peaks.)

And, of course, a Riemann sum of equally-spaced samples is exactly equivalent (with suitable scaling) to a discrete Fourier transform (DFT), so you can compute it very efficiently with FFT algorithms.

QuadGK and similar methods assume that you can evaluate f(x) at any requested x in the integration domain. It doesn’t require you to have an analytical formula for f(x), but you need a way to compute it on demand (e.g. via a computer program).

2 Likes