This question already has an answer here:
I have two arrays contain $y$ and $k$,respectively. However, the exact function relationship is not clear. What I what to do is to fit $y(k)$ by Fourier series
$\qquad y=\sum_n c_n \cos(nk)$
up to $n>20$ terms and obtain their coefficients $c_n$. Can anyone help me? I would be very grateful for your kindness.