The cos fourier transform has no imaginary parts, but in this code it has imaginary parts that little big.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% figure(7);
fs=128;
t=-4*pi:1/fs:4*pi-1/fs;
x=1*cos(0.5*t);
X=fft(x);
N=length(x);
n=0:N-1;
f=n*fs/N;
phs=angle(fftshift(X));
subplot(2,1,1); plot(f,abs(fftshift(X))/N,'LineWidth',1.5);
title('FFT'); ylabel('Magnitude'); xlabel('Frequency(Hz)');
subplot(2,1,2); plot(f,phs*180/pi,'-o'); xlabel('Frequency(Hz)');
ylabel('Phase(Degree)');
figure(8);
Re=real(X); Im=imag(X);
subplot(2,1,1); stem(f,Re); ylabel('Re(G(f))'); xlabel('Frequency(Hz)');
subplot(2,1,2); stem(f,Im); ylabel('Im(G(f))'); xlabel('Frequency(Hz)'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
If I make time range a multiple of 0.5, the results of imaginary parts has very little value that is e-14~15.
Let me know why this problem happened...