I'd really appreciate some advice.
Short Version
I'm trying to calculate the following $$ \psi(X,Y,z=d)=\underset{aperature}{\iint}\psi(x,y,z=0)e^{-i\frac{k}{d}\left(xX+yY\right)}dxdy\\\psi(x,y,z=0)={\sum}\left[\delta\left(x-x_{i}\right)\delta\left(y-y_{i}\right)e^{ih_{i}k}\right]\otimes circ(\sqrt{x_{i}^{2}+y_{i}^{2}}) $$
Long version
For an optics project, i'm trying to use Mathematica to perform a 2D Fourier Transform of 4 discs where each disc has a complex exponent representing its constant, relative phase (discs = functions who are 1*e^(i*phase) if inside the disc and 0 else). Disc centers are at different points in the plane, and the discs are disjoint.
I'm very new to Mathematica and not finding a better way around, have been trying to use NIntegrate to numerically asses and plot (using Plot3D) the FT of the discs, having expressed them in Cartesian coordinates.
Besides being a nightmare to write, I can't get the code to finish running since the integrals are very oscillatory and Mathematica keep sending me these notifications:
"Numerical integration converging too slowly; suspect one of the \ following: singularity, value of the integration is 0, highly \ oscillatory integrand, or WorkingPrecision too small."
I know there are no singularities since when I calculate each integral separately from the rest with smaller phase (so it won't oscillate allot) I do manage to get a correct 3D plot. However, when all of the integrals are calculated together, the calculation takes forever (I quit the kernel after about half an hour of running).
It'd really help if someone could advise me on how to write this code or suggest a simpler way to do this (there must be one). As I mentioned, I'm very new to Mathematica and so thorough explanations would help allot and be very much appreciated.
I'm attaching my code so far for reference.
My code:
\*discs radius*\
ρ = 1;
\*constants that determine phase*\
k = (2 π)/(0.5 10^-6);
d = 2;
Subscript[h, 1] = 0.001;
Subscript[h, 2] = 0.002;
Subscript[h, 3] = 0.003;
Subscript[x, 1] = 0;
Subscript[y, 1] = 0.03;
Subscript[x, 2] = 0.035;
Subscript[y, 2] = 0.01;
Subscript[x, 3] = 0.025;
Subscript[y, 3] = 0.02;
Plot3D[(Abs[ -((I k )/d) π ρ^2 ((
2 BesselJ[1, k/d ρ Sqrt[u^2 + v^2]])/(
k/d ρ Sqrt[u^2 + v^2])) - (2 I)/
v ( E^(I k/d (Subscript[h, 1] - v Subscript[y, 1])) (
NIntegrate[
E^(-I u x k/
d) (E^(-I v k/
d (ρ^2 - ( x - Subscript[x, 1])^2)^0.5) - 1), {x,
Subscript[x, 1], Subscript[x, 1] + ρ},
MaxRecursion -> 5000] +
NIntegrate[
E^(-I u x k/
d) (E^(-I v k/
d (ρ^2 - ( x - Subscript[x, 1])^2)^0.5) - 1), {x,
Subscript[x, 1] - ρ, Subscript[x, 1]},
MaxRecursion -> 5000] +
NIntegrate[
E^(-I u x k/
d) (1 - E^(
I v k/d (ρ^2 - ( x - Subscript[x, 1])^2)^0.5)), {x,
Subscript[x, 1] -ρ, Subscript[x, 1]},
MaxRecursion -> 5000] +
NIntegrate[
E^(-I u x k/
d) (1 - E^(
I v k/d (ρ^2 - ( x - Subscript[x, 1])^2)^0.5)), {x,
Subscript[x, 1], Subscript[x, 1] + ρ},
MaxRecursion -> 5000]) +
E^(I k/d (Subscript[h, 2] - v Subscript[y, 2])) (
NIntegrate[
E^(-I u x k/
d) (E^(-I v k/
d (ρ^2 - ( x - Subscript[x, 2])^2)^0.5) - 1), {x,
Subscript[x, 2], Subscript[x, 2] + ρ},
MaxRecursion -> 5000] +
NIntegrate[
E^(-I u x k/
d) (E^(-I v k/
d (ρ^2 - ( x - Subscript[x, 2])^2)^0.5) - 1), {x,
Subscript[x, 2] - ρ, Subscript[x, 2]},
MaxRecursion -> 5000] +
NIntegrate[
E^(-I u x k/
d) (1 - E^(
I v k/d (ρ^2 - ( x - Subscript[x, 2])^2)^0.5)), {x,
Subscript[x, 2] -ρ, Subscript[x, 2]},
MaxRecursion -> 5000] +
NIntegrate[
E^(-I u x k/
d) (1 - E^(
I v k/d (ρ^2 - ( x - Subscript[x, 2])^2)^0.5)), {x,
Subscript[x, 2], Subscript[x, 2] + ρ},
MaxRecursion -> 5000]) +
E^(I k/d (Subscript[h, 3] - v Subscript[y, 3])) (
NIntegrate[
E^(-I u x k/
d) (E^(-I v k/
d (ρ^2 - ( x - Subscript[x, 3])^2)^0.5) - 1), {x,
Subscript[x, 3], Subscript[x, 3] + ρ},
MaxRecursion -> 5000] +
NIntegrate[
E^(-I u x k/
d) (E^(-I v k/
d (ρ^2 - ( x - Subscript[x, 3])^2)^0.5) - 1), {x,
Subscript[x, 3] - ρ, Subscript[x, 3]},
MaxRecursion -> 5000] +
NIntegrate[
E^(-I u x k/
d) (1 - E^(
I v k/d (ρ^2 - ( x - Subscript[x, 3])^2)^0.5)), {x,
Subscript[x, 3] -ρ, Subscript[x, 3]},
MaxRecursion -> 5000] +
NIntegrate[
E^(-I u x k/
d) (1 - E^(
I v k/d (ρ^2 - ( x - Subscript[x, 3])^2)^0.5)), {x,
Subscript[x, 3], Subscript[x, 3] + ρ},
MaxRecursion -> 5000]))])^2, {u, -0.001,
0.001}, {v, -0.001, 0.001}]


NIntegrateto calculate Fourier transforms is not a good idea, as it's very inefficient (a naive Riemann integration-based 2D Fourier transform is an $O(n^4)$ operation, where $n$ is the number of subdivisions per axis). It would be far more efficient to use 2D fast Fourier transforms, which are implemented usingFourier. For that, you will have to carefully look at the definition of Fourier to determine what your axes are showing you, but it will execute in milliseconds, rather than hours. – DumpsterDoofus Oct 13 '14 at 20:15