python光的菲涅尔衍射
时间: 2023-11-17 14:04:15 浏览: 166
光的衍射
以下是使用S-FFT算法实现Python光的菲涅尔衍射的示例代码:
```python
import numpy as np
import matplotlib.pyplot as plt
def fresnel_propagate(u0, z, dx, lam):
N = u0.shape[0]
k = 2 * np.pi / lam
fx = np.linspace(-1 / (2 * dx), 1 / (2 * dx) - 1 / (N * dx), N)
fx, fy = np.meshgrid(fx, fx)
H = np.exp(-1j * np.pi * lam * z * (fx ** 2 + fy ** 2))
U1 = np.fft.ifft2(np.fft.fft2(u0) * H)
return U1
def circ_aperture(N, r):
x = np.linspace(-1, 1, N)
X, Y = np.meshgrid(x, x)
R = np.sqrt(X ** 2 + Y ** 2)
aperture = np.zeros((N, N))
aperture[R <= r] = 1
return aperture
N = 512
L = 1e-2
dx = L / N
lam = 632.8e-9
k = 2 * np.pi / lam
z = 1
r = 0.5 * L
x = np.linspace(-L / 2, L / 2 - dx, N)
X, Y = np.meshgrid(x, x)
u0 = circ_aperture(N, r)
U1 = fresnel_propagate(u0, z, dx, lam)
I1 = np.abs(U1) ** 2
plt.figure(figsize=(10, 5))
plt.subplot(121)
plt.imshow(u0, cmap='gray')
plt.title('Aperture')
plt.axis('off')
plt.subplot(122)
plt.imshow(I1, cmap='gray')
plt.title('Fresnel Propagation')
plt.axis('off')
plt.show()
```
该程序利用S-FFT算法实现菲涅尔衍射的计算,并图示给出衍射光斑的比较。程序中默认衍射屏为圆孔,其他形状可自行修改。
阅读全文