# Finding the second derivative using DFT

Suppose you have an even real-valued function f(x), which is periodic with T=2L. Introducing a grid $$x[n]=-L+ndx,\quad f(x[n])\equiv f_n,$$ $$dx=\frac{2L}{N},\quad n=0,\ldots N-1,$$ its DFT is defined via $$F_k=\sum_{n=0}^{N-1}f_n\cos\left(\frac{2\pi nk}{N}\right).$$ I've actually checked that its inverse transform returns the original signal: $$f_n=\frac{1}{N}\sum_{k=0}^{N-1}F_k\cos\left(\frac{2\pi nk}{N}\right).$$ As far as I understand, the approximation of the second derivative of such a function is given by $$f_n''=-\frac{1}{N}\sum_{k=0}^{N-1}\left(\frac{2\pi k}{N}\right)^2F_k\cos\left(\frac{2\pi nk}{N}\right).$$ However it doesn't match the value of second derivative of a function in any sense:

I've seen a similar topic, but I'm trying to figure it out without using built-in FFT. Any help is appreciated.

I've found the solution to this problem although I do not fully understand it. First of all, the mentioned derivative has factor $$1/(2L)^2$$ instead of $$1/N^2$$: $$f_n''=-\frac{1}{N}\sum\left(\frac{2\pi k}{2L}\right)^2F_k\cos\left(\frac{2\pi nk}{N}\right),$$ which can be clearly seen if taken the derivative correctly with respect to x, it was a strightforward mistake. However it doesn't solve the problem. I've tried to reorganize my sum as follows: $$f_n''=-\frac{1}{N}\sum_{k=-N/2}^{N/2-1}\left(\frac{2\pi k}{2L}\right)^2F_k\cos\left(\frac{2\pi nk}{N}\right)$$ and somehow it worked! It would be great to see the explanation for this.