Why FFT of a rectangular pulse has imaginary part while the sinc function is real? I have a rectangular pulse:

w = 20; pln = 10;
v =[zeros(1, pln), ones(1, w),zeros(1, pln)];
figure(); plot(v,'-o');


by perform fft and fftshift the pulse center to zero to get its frequency domain representation:

yf = fftshift(fft(v));
xf = [-0.5000   -0.4750   -0.4500   -0.4250   -0.4000   -0.3750   -0.3500   -0.3250...
-0.3000   -0.2750   -0.2500   -0.2250   -0.2000   -0.1750   -0.1500   -0.1250...
-0.1000   -0.0750   -0.0500   -0.0250         0    0.0250    0.0500    0.0750...
0.1000    0.1250    0.1500    0.1750    0.2000    0.2250    0.2500    0.2750...
0.3000    0.3250    0.3500    0.3750    0.4000    0.4250    0.4500    0.4750];
yf = yf.*exp(-2j*pi*xf*(pln+w/2)); % this shifts the time domain signal to zero


yf is close to the sinc function - the Fourier transform of a rectangular function - but not exactly the same, it has imaginary part while sinc is is purely real:

yf_sinc = w*sinc(w*xf);


Why is the difference and why ifft of samples taken from a sinc function will not produce an exact rectangular pulse but with ripples close to the edge while ifft(fft(v)) will exactly reproduce the original rectangular pulse:

% has ripples around the edges
figure(); plot(fftshift(ifft(fftshift(yf_sinc)))); 
% reproduces the exact rectangular pulse  
figure(); plot(fftshift(ifft(fftshift(yf)))); 


herer yf, if we assume it was directly sampled form a underlying function, that is ingoring the fact that it is produced by fft of a rectangular pulse (it's just some numbers anyway), what function would it be? Is it possible by sampling a function in the frequency domain (not need to be the sinc function) and take the ifft will produce an exact rectangular pulse?
The even part of a real signal transforms to the real part of the DFT.  The odd part of a real signal transforms to the imaginary part of the DFT.  For example, the DFT of cosine, an even function, is strictly real, while the DFT of a sine, an odd function, is strictly imaginary.