Trying to understand what a fast fourier transform (np.fft) returns

25 Views Asked by At

Im trying to interpolate a periodic function with a trig polynomial:

$$ \forall k \in \{0, \dots, 7\}: y(x_k)=\frac{1}{8}\sum_{j=0}^{7}c_je^{ijx_k} $$

To my understanding I could get the $c_j$, for lets say: $y(x)= 2 + \exp(2ix)$ using:

f = lambda x: 2 + np.exp(2j*x)
x = np.linspace(0,2*np.pi,8)
y = f(x)
c = np.fft.fft(y)
plt.plot(x,y, "o") #As a comparison for later

But if I try to insert the $c_i$ into the formula above and plot the result:

def plotTrigInterpolation(c,t):
 y = np.zeros_like(t)
 for i, t_i in enumerate(t):
     for k, c_i in enumerate(c):
         y[i] = y[i] + 1/8*c_i*np.exp(1j*k*t_i)
 return y
 
 t = np.linspace(0,2*np.pi,200)
 plt.plot(t,f(t))
 plt.plot(t, plotTrigInterpolation(c,t))

I get: Plor And the function doesn't pass through the interpolation points. So what do I misunderstand about the output of the fast fourier transform?