ARTICLE AD BOX
I am working on a code that calculates the 2D FFT of a function as a first step. I am testing it with the function exp(-r)/r, with r=sqrt(x²+y²) which has the analytical Hankel transform of 1/sqrt(r²+1). The zero order Hankel transform is related to the two-dimensional Fourier transform by a rescaling. However, I cannot recover this analytical solution. My transform is a much narrower function, with a non-vanishing imaginary part.
Minimum reproducible example:
import numpy as np import matplotlib.pyplot as pl def min_pot(x: np.ndarray, y: np.ndarray): xbig, ybig = np.meshgrid(x, y) r = np.sqrt(np.square(xbig) + np.square(ybig)) r0 = np.unravel_index(np.argmin(r, axis=None), r.shape) test = np.exp(-r)*np.reciprocal(r) test[r0] = 2*test[r0[0]+1, r0[0]] - test[r0[0]+2, r0[0]] #this suppresses the r=0 singularity return test x_min = np.linspace(-20, 20, num=1001) y_min = np.linspace(-20, 20, num=1001) real_a = min_pot(x_min, y_min) shift_a = np.fft.ifftshift(real_a) fourier_a = np.fft.fftshift(np.fft.fft2(np.fft.fftshift(real_a), norm="forward")) kx = np.fft.fftshift(np.fft.fftfreq(len(x_min), d=(x_min[1]-x_min[0]))) #we represent a cut in the x axis analytic = np.power(np.square(kx) + 1, -.5) max_real = np.amax(fourier_a[fourier_a.shape[0]//2, :].real # normalization to compare curve shapes better fig, ax = pl.subplots(1, 1) ax.plot(kx, fourier_a[fourier_a.shape[0]//2, :].real/max_real), label='Real fft') ax.plot(kx, fourier_a[fourier_a.shape[0]//2, :].imag/max_imag), label='Imag. fft') ax.plot(kx, analytic, label='Analytic') pl.legend() pl.show()The resulting figure is:
Does anybody know what am I doing wrong?
