2
I’m having a problem using the fft function of numpy. When rotating it, the answer is giving different from the Fourier transform that I implemented manually and by the tests I did the manual seems correct. I think I’m using fft the wrong way.
import numpy as np
import math as m
def transformada_direta(F,x,N):
c=[]
for k in range (N):
c.append(0)
for k in range (N):
soma=0
for j in range (N):
soma=soma+(F[j]*(np.exp((0-1j)*k*x[j])))
c[k]=soma/(N)
return c
def main():
N=4
T=(2*(np.pi))/N
x=np.linspace(0.0,T*(N-1),N)
F=[]
for j in range (N):
F.append(0)
F[0]=5
F[1]=-1
F[2]=3
F[3]=1
c=transformada_direta(F,x,N)
print(c)
yf=np.fft.fft(F)
print(yf)
main()
I’m not sure, but in function
transformada_direta()
, the sum divided byN
is not the transformation inverse? It shouldn’t just bec[k]=soma
? (instead ofc[k]=soma/(N)
)– Gomiero
Is not
x=np.linspace(0.0,T*(N-1),N)
that should bex=np.linspace(0.0, T*N, N)
? In the above form, each interval ofx
will be 2/3 pi, while in the suggested would be 1/2 pi.– Marcelo Shiniti Uchimura