I am trying to calculate inverse discrete fourier transform for an array of signals.
I am using the following formula:
$$ x[n] = \tfrac1N \sum\limits_{k=0}^{N-1} X[k] \, e^{j 2 \pi k n/N} $$
And my python code looks as follow.
def IFT(array):
array = np.asarray(array, dtype=float)
# array length
N = array.shape[0]
# new array of lenght N [0, N-1]
n = np.arange(N)
k = n.reshape((N, 1))
# Calculate the exponential of all elements in the input array.
M = np.exp(2j * np.pi * k * n / N)
return 1 / N * np.dot(M, array)
y = 2*np.sin(2*np.pi*f1*t+0.2) + 3*np.cos(2*np.pi*f2*t+0.3) + noise*5
IFT(sc.fft(y))
array([ 3.42732136e+00+0.00000000e+00j, 4.81582993e+00-4.10374772e-16j,
5.86456023e+00+3.88824673e-16j, 4.07942919e+00-1.48609552e-15j,
5.25077594e+00+6.70968395e-16j, 6.45823471e+00-1.22977116e-15j,
...
sc.ifft(sc.fft(y))
array([ 3.42732136-8.59756710e-16j, 5.34401724+4.97379915e-17j,
5.46939384-9.87654403e-16j, 3.31504852-4.17443857e-16j,
6.52888175+6.39488462e-16j, 6.90804001-3.10862447e-16j,
...
but if I compare array returned from Scipy.ifft
with the one returned from my own function IFT
, I get completely different array. Am I missing something?
n
andN
? $\endgroup$