I am trying to understand exactly how sampling the DTFT to get the DFT works. The signal I'm trying to analyze is $x(n)$ seen below.
$$x(n) = \delta(n\pm2) + 2\delta(n\pm1) + 3\delta(n)$$
Taking the DTFT, we have \begin{align} X(\omega)&= \sum\limits_{i=-\infty}^\infty x(n)e^{-j\omega}\\ &= \left(e^{j2ω} + e^{-j2ω}\right) + 2\left(e^{jω} + e^{-jω}\right) + 3\\ &= 2\cos(2ω) + 2(2\cosω) + 3\\ &= 3 + 4\cosω + 2\cos(2ω) \end{align}
I next implemented this in MATLAB:
x = [1 2 3 2 1];
N = size(x,2);
w = -pi:0.01:pi;
X_DTFT_computational = freqz(x,1,w);
X_DTFT_analytical = 3 + 4*cos(w) + 2*cos(2*w);
This results in the following graphs:
Next, I compute the DFT in two ways: 1. I apply an FFT to the original signal $x(n)$. 2. I sample the DTFT.
The code that achieves this is as follows:
% FFT of x
X_DFT_computational = fftshift(fft(x))
% DFT = Sampled DTFT
X_DFT_analytical(1) = 3 + 4*cos(-4*pi/N) + 2*cos(2*(-4*pi/N));
X_DFT_analytical(2) = 3 + 4*cos(-2*pi/N) + 2*cos(2*(-2*pi/N));
X_DFT_analytical(3) = 3 + 4*cos(0) + 2*cos(2*(0));
X_DFT_analytical(4) = 3 + 4*cos(2*pi/N) + 2*cos(2*(2*pi/N));
X_DFT_analytical(5) = 3 + 4*cos(4*pi/N) + 2*cos(2*(4*pi/N));
Plotting the DFT (while showing the DTFT for comparison), I have
The magnitude of the FFT does give me the correct result. But just plotting the FFT alone gives me a complex signal (the graph shows the real part).
Why is this signal giving a complex FFT when $x(n)$ is both real and symmetric?