I have Gaussian beam in 2D:
After doing fft2
and angle I get strange results:
def finite2D(x,y, N, M, a, hx):
f = np.array([[0.0]*N]*N)
for i in range(len(x)):
for k in range(len(y)):
f[i][k] = np.exp(-(x[i]*x[i] + y[k]*y[k]))
D1 = fftpack.fft2(f)
D2 = fftpack.fftshift(D1)
b = N*N/(4*a*M)
x = np.linspace(-b, b, N)
y = np.linspace(-b, b, N)
xx, yy = np.meshgrid(x, y)
plt.imshow(np.abs(D2))
plt.show()
plt.imshow(np.angle(D2))
plt.show(True)
return D2, phas
a = 5
N = 128
M = 256
b = N*N/(4*a*M)
hx = 2*a/N
x = np.linspace(-a, a, N)
y = np.linspace(-a, a, N)
finite2D(x,y, N, M, a, hx)
It should be phase 0 or close to 0. Why is this not the case, and how do I fix this?
///Updated:
def finite2D(x,y, N, M, a, hx):
f = np.array([[0.0]*N]*N)
for i in range(len(x)):
for k in range(len(y)):
f[i][k] = np.exp(-(x[i]*x[i] + y[k]*y[k]))
f = fftpack.ifftshift(f)
D1 = fftpack.fft2(f)
D2 = fftpack.fftshift(D1)
b = N*N/(4*a*M)
x = np.linspace(-b, b, N)
y = np.linspace(-b, b, N)
xx, yy = np.meshgrid(x, y)
plt.imshow(np.abs(D2))
plt.show()
plt.imshow(np.angle(D2))
plt.show(True)
return D2
a = 5
N = 128
M = 256
b = N*N/(4*a*M)
hx = 2*a/N
x = np.linspace(-a, a, N, endpoint=False)
y = np.linspace(-a, a, N, endpoint=False)
finite2D(x,y, N, M, a, hx)
Phase: