@Yvon is absolutely right with his comments on symmetry. Your input signal looks symmetrical, but not because the symmetry is related to start 0. Using linspace in Matlab to build signals is in most cases a bad choice. Trying to restore results using fftshift is also a bad idea.
Use instead:
k = 2*(0:N-1)/N - 1;
and you get the expected result. However, the imaginary part of the converted values will not be completely zero. There is some numerical noise.
>> max(abs(imag(Vf5))) ans = 2.5535e-15
The answer to Yvon’s question:
Why? → N = 1 + 2 ^ 4 N = 17 → x = linspace (-1,1, N) x = -1.0000 -0.8750 -0.7500 -0.6250 -0.5000 -0.3750 - 0.2500 -0.1250 0 0.1250 0.2500 0.3750 0.5000 0.6250 0.750 0.8750 1.0000 → y = 2 * (0: N-1) / N-1 y = -1 , 0000 -0.8824 -0.7647 -0.6471 -0.5294 -0.4118 -0.2941 -0.1765 -0.0588 0.0588 0.1765 0.291 0.4118 0.5294 0.641 0, 7647 0.824 - Yvon 1
Your example is not a symmetric (even) function, but an antisymmetric (odd) function. However, this does not matter.
For an antisymmetric function of length N, the following statement holds:
f[i] == -f[-i] == -f[Ni]
Index I works from 0 to N-1.
Let's see what happened with i = 2. Remember that count starts at 0 and ends at 16.
x[2] = -0.75 -x[N-2] == -x[17-2] == -x[15] = (-1) 0.875 = -0.875 x[2] != -x[N-2] y[2] = -0.7647 -y[N-2] == -y[15] = (-1) 0.7647 y[2] == y[N-2]
The problem is that the start of the Matlab vectors starts at 1. Modular (periodic) vectors start at the beginning 0. This difference leads to many misunderstandings.
Another way to explain why linspace (-1, + 1, N) is incorrect:
Imagine that you have a vector that contains one period of a periodic function, for example, the Cosine function. This single period is one of an infinite number of periods. The first value of your Cosinus vector must not be the same as the last value of your vector. However, this is exactly what linspace (-1, + 1, N) does. This leads to a sequence in which the last value of period 1 is the same value as the first pattern of the next period 2. This is not what you want. To avoid this error, use t = 2 * (0: N-1) / N - 1. The distance t [i + 1] -t [i] is 2 / N, and the last value should be t [N-1] = 1 - 2 / N, not 1.
Reply to Yvon's second comment
Whatever you insert the DFT / FFT into the input vector, in theory it is interpreted as a periodic function. But that is not the point.
DFT integrates.
fft(m) = Sum_(k=0)^(N-1) (x(k) exp(-i 2 pi mk/N )
The first value x (k = 0) describes the amplitude of the first integration interval of length 1 / N. The second value x (k = 1) describes the amplitude of the second integration interval of length 1 / N. And so on.
The most recent integration interval of a symmetric function ends with the same value as the first sample. This means that the starting point of the last integration interval is k = N-1 = 1-1 / N. Your input vector contains the start points of the integration intervals.
Therefore, the last point of symmetry k = N is the point of the function, but it is not the starting point of the integration interval and therefore is not a member of the input vector.