I can sample a continuous function that is the Fourier transform of an unknown function, and I want to use the sampled data points from that function to do an inverse discrete Fourier transform (DFT) to recover the unknown function. Then I met the problem that the reconstructed function has some strange shape on both ends (t=0 and t=t_max). I did an experiment with a function f(t)=exp(-t) for t>0, which has a FT, 1/(2*\pij\omega+1). With the python code below, you can see that the reconstructed signal with inverse DFT from sampled data points of the analytical Fourier transform diverges at the ends, however, the reconstructed signal with inverse DFT from the DFT of the sampled original signal gets back to the original signal with no artifacts. So what is going on here? Example of the reconstruction with inverse DFT
import numpy as np
import matplotlib.pyplot as plt
dt = 0.01
t = np.arange(0, 10, dt)
#Define function, discrete samples of the target function
f = np.exp(-t)
#Compute Fourier transform by numpy’s FFT function
f_w = np.fft.fft(f)
#Calculate DFT frequency
w = np.fft.fftfreq(f.size, dt)
#When using DFT to approximate FT, an additional term dt is needed
f_w *= dt
#Plot Result
plt.scatter(w,f_w.real, color=‘r’, label=‘DFT of the the signal’)
def exp_w(w):
“”"Analytical FT of exp(-t)“”"
return 1/(1 + 2*np.pi*1j*w)
f_w_analytical = np.array([exp_w(i) for i in w_range])
plt.scatter(w_range, f_w_analytical.real, color=‘c’, label=‘Analytical FT’)
plt.gca().set_xlim(-10,10)
plt.legend()
plt.show()
#Below, we plot the reconstructed function with inverse DFT
n=None
plt.scatter(t[:n],np.fft.ifft(f_w_analytical)[:n], label=‘from analytical FT’)
plt.scatter(t[:n],np.fft.ifft(f_w)[:n], label=‘from DFT’)
plt.legend()
plt.show()
#Below, plot the first/last reconstructed time step
n=10
plt.scatter(t[:n],np.fft.ifft(f_w_analytical)[:n], label=‘from analytical FT’)
plt.scatter(t[:n],np.fft.ifft(f_w)[:n], label=‘from DFT’)
plt.title(‘First 10 time step’)
plt.legend()
plt.show()
plt.scatter(t[-n:],np.fft.ifft(f_w_analytical)[-n:], label=‘from analytical FT’)
plt.scatter(t[-n:],np.fft.ifft(f_w)[-n:], label=‘from DFT’)
plt.title(‘Last 10 time step’)
plt.legend()
plt.show()