Unexpected imaginary part in the fft of a zero-padded cosine I simulated a cosine waveform $ y = \cos(\omega t) $ and I applied the FFT algorithm to it. As expected, I have a frequency peak at $\pm \omega$ only in the real part, and nothing in the imaginary part. As expected, if I zero-pad the array, the peak in the real part becomes a $\mathrm{sinc}(\omega D)$ (where D is the length of the window). However, in the imaginary part, a sort of anti-symmetric $\mathrm{sinc}$ appears. I don't understand why, because I was expecting the imaginary part to stay zero since the Fourier transform of the cosine is purely real.
Why is this happening?
Here a plot of the imaginary and real parts of the FFT of the described signal. In orange: FFT of the original signal. In blue: FFT of the zero-padded signal.

Here is my code, written in MATLAB language.
dt = 0.02;
fs = 1/dt;

start = 0; 
stop = 1; 
t = start:dt:stop-dt;

w = 2*pi*10;
y = cos(w*t);

N = 10000;
y_pad = [y zeros(1,N)];


Y_PAD = fftshift(fft(y_pad))./length(y);
df_pad = fs / length(y_pad);
f_pad = (0:(length(y_pad)-1))*df_pad;
f_pad(f_pad &gt;= fs/2) = f_pad(f_pad &gt;= fs/2) - fs;
f_pad = fftshift(f_pad);

Y = fftshift(fft(y))./length(y);
df = fs / length(y);
f = (0:(length(y)-1))*df;
f(f &gt;= fs/2) = f(f &gt;= fs/2) - fs;
f = fftshift(f);

figure;
subplot(2,1,1);

plot(f_pad, real(Y_PAD));
hold on
plot(f, real(Y));

ylabel('Re(fft)')
xlabel('f (Hz)')

subplot(2,1,2);

plot(f_pad, imag(Y_PAD));
hold on
plot(f, imag(Y));

ylabel('Im(fft)')
xlabel('f (Hz)')


Edit: By zero-padding only to the right of my signal I am breaking the even parity of the cosine and $y[N-n]=y[n]$ does not hold anymore (see Hilmar's answer). Therefore, I tried to zero pad both to the left and to the right, in order to preserve the parity
N = 10000;
y_pad = [zeros(1,N) y zeros(1,N)];

The result is the following and it looks weird: the imaginary part is still not zero and the real part oscillates between positive and negative values. Why this zero-padding does not work as expected?
A signal that's discrete in frequency is periodic in time. By using an FFT you inherently make this assumption and the FFT calculates the spectrum of a signal that's infinitely repeated in time.
The FFT is ONLY real valued if the time domain signal has even symmetry, i.e. $x(-t) = x(t)$. For a discrete periodic signal of period N this becomes $x[n] = x[N-n]$. That holds true for a pure cosine (at least for some frequencies), but not for the zero padded version.