Using FFT to calculate derivatives I know that there are several posts about FFT and derivatives, but i dont get it.
The formula is:
$$
f(t) \to \hat{f}(\xi), f'(t) \to  2\pi i \xi\hat{f}(\xi)
$$
First, i dont understand what is the $\xi$, when i learned FFT as much as i poorly understand it, we compute it at different complex roots.
Let's take an example, i want to calculate the derivative of the polynomial:
$$
P(x) = -1 + 2x + 5x^2 - 4x^3
$$
The analytic solution will be:
$$
P'(x) = 0 + 2 + 10x - 12x^2
$$
Now, i take the FFT of $P(x)$ and get:

What should i multiply this by in order to get the values that by using FFT$^{-1}$  will get me to $P'(x)$?
 A: Suppose you have an arbitrary function $f\equiv \hat{f}$. The function can be represented in physical space as $f(x)$ or in frequency space as $\hat{f}(\xi)$. Here $\xi$ is the frequency or mode. You can derive the spectral derivative in three steps:

*

*Apply the Fourier transform on $f(x)$ to derive $\hat{f}(\xi)=\mathcal{F}(f(x))$.

*Multiply the $k$-th mode with $i \xi$ where $\xi=0,1,2,3,...$ to derive $\frac{\partial \hat{f}(\xi)}{\partial \xi}= i \xi \hat{f}(\xi)$.

*Apply the inverse Fourier transform on $\frac{\partial \hat{f}(\xi)}{\partial \xi}$ to derive $\frac{\partial f(x)}{\partial x} = \mathcal{F}^{-1}(\frac{\partial \hat{f}(\xi)}{\partial \xi})$.

Note that here $\omega= \frac{2\pi}{L} = 1$ or $L=2 \pi$. Otherwise you have to scale the $i$-th mode with $\omega$.
Summarizing:
$\frac{\partial f(x)}{\partial x} = \mathcal{F}^{-1}(\frac{\partial \hat{f}(\xi)}{\partial \xi})=\mathcal{F}^{-1}( i \xi \mathcal{F}(f(x))$.
Matlab code for even $N$:
N=64;
L=2*pi;
dx=L/N;
x=linspace(0,L-dx,N);
f=sin(x);
k(1:N/2)=1i*(0:N/2-1);
k(N/2+2:N)=1i*(-N/2+1:-1);
% Consider the Nyquist mode my young Padawan
k(N/2+1)=0;
fhat=fft(f);
fhatx=k.*fhat;
fx=ifft(fhatx);

