Find trigonometric polynomial coefficients fitting sample points

215 Views Asked by At

I have $N$ uniformly spaced real sample points, representing samples of the radial component of a simple closed curve in polar coordinates (so the samples correspond to a periodic function, and the period is $2 \pi$). I want to fit a real trigonometric polynomial to these points. That is, I want to find the coefficients $a_k, b_k \in \mathbb{R}$ such that the curve

$$ a_0 + \sum_{k=1}^K a_k \cos(k x) + \sum_{k=1}^K b_k \sin(k x)$$

fits the samples ($K$ here is either $N$ or something close to it, I think).

Intuitively I think this can be done efficiently with a fast fourier transform, but I've been having trouble figuring out how to map the list of complex numbers a FFT routine gives to the real coefficients I need. For instance, in Python:

>>> np.fft.fft([1, 2, 3, 4])
array([10.+0.j, -2.2+2.j, -2.+0.j, -2.-2.j])

I'm not sure how to transform these complex coefficients to the real coefficients I need.