Lets say I want to double the number of points in an array f. I had the idea to do this:
F=fft(f);N=length(f);
FF=[F(1:N/2) zeros(1,N) F(N/2+1:N)];
f=ifft(FF);
But the result is not exactly correct. Why is this?
If N
is odd it's a bit simpler:
FF=2*[F(1:(N+1)/2),zeros(1,N),F((N+3)/2:N)];
ff=real(ifft(FF));
This is very close to what you had (apart from the scaling). Also note that due to numerical inaccuracies you have to take the real part of the IFFT operation. However, you should always check that the imaginary part (which you throw away) is very small (in the order of $10^{-16}$ when using double).
If N
is even, you need to split the value at Nyquist:
FF=2*[F(1:(N/2)),.5*F(N/2+1),zeros(1,N-1),.5*F(N/2+1),F((N/2+2):N)];
ff=real(ifft(FF));
Doing DFT based interpolation has to keep 3 principles:
By the way, the interpolation isn't by a Sinc Kernel, it is done with its discrete form - The Dirichlet Kernel.