If I start off with a signal which has only real values, performing an fft and ifft returns the exact signal back with no complex entries as expected. But if I pad the fft with zeros to obtain interpolated values in the time domain, the inverse fft always turns out to be a complex double. I have taken care to perform the fftshift() and then pad on both sides, so that the symmetry is not broken. Following is an example code, that shows this behaviour. Am I looking at this the wrong way, or is the computational error after zero padding a bit too much? How do I overcome this?
Code:
%%%%%%%%%
x=linspace(0,2*pi,200);
y = sin(x)+sin(2*x);
Y = fftshift(fft(y));
n=400;
x1 = linspace(0,2*pi,n);
Y1 = zeros(1,n);
Y1((n-200)/2+1:end-(n-200)/2) = Y;
y2 = ifft(fftshift(2*Y1));
plot(x,y);
hold on;
plot(x1,y2(1:end),'x-');
isreal(y)==isreal(y2)
%%