2

I made an object g representing a plane wave through a circular aperture with a zero phase.

When I take the inverse Fourier transform of the Fourier transform of g, the result is different from g itself. The phase is very noisy.

Why? And how can I improve it?

import numpy as np

# object (circular aperture)
M, N = 256, 256 # resolution

D = M/2
Xo, Yo = np.ogrid[:M,:N]
r = np.sqrt( (Xo-M//2)**2 + (Yo-N//2)**2 )

amplitude = r <= D/2. # real part

g = amplitude * np.exp(1j * 0) # I set the phase at zero (imaginary part)

G = np.fft.fft2(g)

gi = np.fft.ifft2(G)

See attached plot:

amplitude and phase of object before and after transform

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
Arχeìon
  • 21
  • 2
  • 4
    This looks like numerical noise to me. – farenorth Sep 16 '22 at 19:46
  • 4
    I got ~1e-17 values which is very small for double-precision numbers regarding the input and the numerical method. Also note that `np.allclose(g, gi)` is `True`. See https://stackoverflow.com/questions/588004/is-floating-point-math-broken/588014#588014 . Besides, the phase should be pretty sensitive to the input (if not even chaotic in this case due to the specific input). – Jérôme Richard Sep 16 '22 at 19:56
  • 5
    You should not attempt to compute the phase of complex values that are very close to zero. It will be completely given by rounding errors in computations. – Cris Luengo Sep 16 '22 at 20:19
  • @JérômeRichard, gotcha. I get a value of False though for np.allclose(g, gi). I am using the spyder IDE, not sure if that has an impact of numerical level of accuracy. – Arχeìon Sep 16 '22 at 21:02
  • 1
    It is weird that `np.allclose(gi,g)` is `false` for you (not the case for me either). The reason the `np.angle` is so different is because the absolute value is so close to zero. If the absolute value of a number is very close to zero you can expect numerical error to make a big difference in the angle. If you simply offset by doing `g = g + 1` then the resulting angle plot I get has a magnitude of no more than `1e-16` – Simon Tartakovksy Sep 16 '22 at 21:25
  • @SimonTartakovksy, g + 1 gives indeed much more satisfying results. Thanks so much! – Arχeìon Sep 17 '22 at 18:30

0 Answers0