---
title: "Wave optics lab: lens systems, diffraction, polarization and the Airy disk"
heading: Reducing any train of lenses and gaps to one ray-transfer matrix with its focal length and focal points, computing a slit's far field by discrete Fourier transform, chaining Jones matrices, and finding the Airy disk's zero and encircled energy from Bessel functions
eyebrow: S13 · Lesson 14 · Wave optics lab
xp: 60
---

::: hook
Lessons 1 to 13 gave closed forms: the two-lens focal length, sinc² for a slit's far field, Jones matrices for polarizers and plates, 1.22λ/D for the Airy disk. Each is the special case of a computation that's just as easy to write in general. In this lab you'll write those computations and check them against the formulas: the focal length and focal points of any lens train, the far field of any aperture, any chain of polarization elements, and the Airy pattern's energy, computed from its Bessel functions.
:::

::: play
- The curve is the fraction of an Airy pattern's power inside radius r, against r in units of $\lambda f/D$: $1 - J_0^2(\pi r) - J_1^2(\pi r)$, with the first dark ring at r = 1.22.
- 83.8% of the power lies inside the first dark ring and 91% inside the second.
- Ringing in the curve's slope marks the bright rings, each carrying less than the last.
:::

```sim plot
view: graph
x: r = 0..4
y: E = 0..1
plot: 1 - J0(pi*r)^2 - J1(pi*r)^2 | label: encircled energy
plot: 0.838*step(r - 1.2197)*step(1.2297 - r) | dashed | label: first dark ring
```

::: predict
## A 100 mm lens and a 50 mm lens are 30 mm apart. Where does a collimated beam entering the first come to a focus?

- [ ] 50 mm after the second lens
- [ ] 33.3 mm after the second lens (the lenses' combined power, ignoring the gap)
- [x] 29.2 mm after the second lens
- [ ] 41.7 mm after the second lens

::: reveal
The system matrix is $\begin{bmatrix}0.7 & 30 \\ -0.024 & 0.4\end{bmatrix}$, so the effective focal length is $-1/C$ = 41.7 mm, but measured from the second lens the focus lies $-A/C$ = 29.2 mm away: the back focal distance. The gap reduces the combination's power below the 1/100 + 1/50 of touching lenses, and the focal length and focal distance differ because the principal plane isn't at either lens.
:::
:::

::: nameit
## What the lab computes

- **Lens systems**: the system matrix is the product of the elements' matrices, last element on the left; its effective focal length is $-1/C$, the back focal distance (from the last element) $-A/C$, the front focal distance (before the first) $-D/C$.
- **Far field by DFT**: sampling an aperture's field and taking its discrete Fourier transform gives its Fraunhofer pattern, with frequency index k corresponding to $\nu_x = k/(N\Delta x)$ and screen position $x = \lambda d\nu_x$.
- **Jones calculus**: a cascade's matrix is the product of its elements' matrices, last element on the left; an element rotated by θ is $R(\theta)TR(-\theta)$.
- **The Airy pattern**: intensity $\propto [2J_1(v)/v]^2$ with $v = \pi Dr/\lambda f$; first zero at v = 3.8317 (r = 1.22λf/D); encircled energy $1 - J_0^2(v) - J_1^2(v)$. Bessel functions follow from $J_n(x) = \frac1\pi\int_0^\pi\cos(n\tau - x\sin\tau)\,d\tau$.
:::

::: check
kind: python

## Write `system_matrix(elements)`: the 2 × 2 ray-transfer matrix of a list of ("space", d) and ("lens", f) elements in the order light meets them, and `focal_data(elements)` returning (effective focal length, back focal distance, front focal distance).

```python starter
def system_matrix(elements):
    return [[1.0, 0.0], [0.0, 1.0]]

def focal_data(elements):
    return 0.0, 0.0, 0.0
```

```python solution
def system_matrix(elements):
    m = [[1.0, 0.0], [0.0, 1.0]]
    for kind, v in elements:
        e = [[1.0, v], [0.0, 1.0]] if kind == "space" else [[1.0, 0.0], [-1.0 / v, 1.0]]
        m = [[e[0][0] * m[0][0] + e[0][1] * m[1][0], e[0][0] * m[0][1] + e[0][1] * m[1][1]],
             [e[1][0] * m[0][0] + e[1][1] * m[1][0], e[1][0] * m[0][1] + e[1][1] * m[1][1]]]
    return m

def focal_data(elements):
    (A, B), (C, D) = system_matrix(elements)
    return -1 / C, -A / C, -D / C
```

```python tests
m = system_matrix([("lens", 100), ("space", 30), ("lens", 50)])
assert abs(m[0][0] - 0.7) < 1e-12 and abs(m[1][0] + 0.024) < 1e-12 and abs(m[0][0] * m[1][1] - m[0][1] * m[1][0] - 1) < 1e-12, "Lesson 1's pair: A = 0.7, C = −0.024, determinant 1."
f, bfd, ffd = focal_data([("lens", 100), ("space", 30), ("lens", 50)])
assert abs(f - 41.667) < 1e-3 and abs(bfd - 29.167) < 1e-3, "f = 41.7 mm, back focal distance 29.2 mm."
f2, b2, _ = focal_data([("lens", 50), ("space", 50), ("lens", 50)])
assert abs(f2 - 50) < 1e-9 and abs(b2) < 1e-9, "Two 50 mm lenses one focal length apart: f = 50 mm, focus at the second lens."
```

::: right
Right. Any train of thin lenses and gaps reduces to one matrix, whose C element is the system's power.
:::
:::

::: check
kind: python

## Write `far_field(aperture)`: the normalized intensity pattern of a sampled 1D aperture by DFT (|X_k|² over |X_0|², for k from 0 to N/2), and `first_zero_index(aperture)`: the first k where it falls below 10⁻⁶.

```python starter
def far_field(aperture):
    return [1.0]

def first_zero_index(aperture):
    return 0
```

```python solution
import cmath, math

def far_field(aperture):
    N = len(aperture)
    X = [sum(aperture[n] * cmath.exp(-2j * math.pi * k * n / N) for n in range(N)) for k in range(N // 2 + 1)]
    return [abs(x) ** 2 / abs(X[0]) ** 2 for x in X]

def first_zero_index(aperture):
    for k, v in enumerate(far_field(aperture)):
        if v < 1e-6:
            return k
    return None
```

```python tests
import math
N, M = 512, 32
slit = [1.0 if n < M else 0.0 for n in range(N)]
assert first_zero_index(slit) == N // M, "A slit M samples wide has its first zero at k = N/M: λd/D."
I = far_field(slit)
k = 5
assert abs(I[k] - (math.sin(math.pi * k * M / N) / (M * math.sin(math.pi * k / N))) ** 2) < 1e-9, "It matches the sampled sinc²."
```

::: right
Right. On a screen at distance d, index k sits at $x = \lambda dk/(N\Delta x)$, so the first zero is at $\lambda d/D$.
:::
:::

::: check
kind: python

## Write `jones_chain(elements, v)`: apply a list of elements to a Jones vector v (a pair of complex numbers), where each element is ("pol", θ), ("wave", Γ, θ) for a retarder of retardance Γ with fast axis at θ, all angles in degrees; return the output vector and its intensity.

```python starter
def jones_chain(elements, v):
    return v, abs(v[0]) ** 2 + abs(v[1]) ** 2
```

```python solution
import cmath, math

def rot(t):
    c, s = math.cos(t), math.sin(t)
    return [[c, -s], [s, c]]

def mul(a, b):
    return [[sum(a[i][k] * b[k][j] for k in range(2)) for j in range(2)] for i in range(2)]

def element(e):
    t = math.radians(e[-1])
    if e[0] == "pol":
        T = [[1, 0], [0, 0]]
    else:
        T = [[1, 0], [0, cmath.exp(-1j * e[1])]]
    return mul(mul(rot(t), T), rot(-t))

def jones_chain(elements, v):
    for e in elements:
        M = element(e)
        v = (M[0][0] * v[0] + M[0][1] * v[1], M[1][0] * v[0] + M[1][1] * v[1])
    return v, abs(v[0]) ** 2 + abs(v[1]) ** 2
```

```python tests
import math
_, I = jones_chain([("wave", math.pi, 20), ("pol", 0)], (1, 0))
assert abs(I - math.cos(math.radians(40)) ** 2) < 1e-12, "Lesson 10's half-wave plate at 20°: 0.587."
_, I3 = jones_chain([("pol", 30), ("pol", 90)], (1, 0))
assert abs(I3 - math.cos(math.radians(30)) ** 2 * math.sin(math.radians(30)) ** 2) < 1e-12, "Three polarizers: Malus twice."
v, _ = jones_chain([("wave", math.pi / 2, 0)], (math.cos(math.pi / 4), math.sin(math.pi / 4)))
assert abs(abs(v[0]) - abs(v[1])) < 1e-12 and abs(abs((v[1] / v[0]).imag) - 1) < 1e-12, "A quarter-wave plate makes 45° light circular."
```

::: right
Right. Any passive polarization system reduces to a product of 2 × 2 matrices.
:::
:::

::: check
kind: python

## Write `bessel(n, x)` by the midpoint rule on Bessel's integral with 2000 points, `airy_zero()`: the first zero of $J_1$ above 3 by bisection, and `encircled(v)`: $1 - J_0^2(v) - J_1^2(v)$.

```python starter
def bessel(n, x):
    return 0.0

def airy_zero():
    return 3.0

def encircled(v):
    return 0.0
```

```python solution
import math

def bessel(n, x):
    N = 2000
    return sum(math.cos(n * (k + 0.5) * math.pi / N - x * math.sin((k + 0.5) * math.pi / N)) for k in range(N)) / N

def airy_zero():
    lo, hi = 3.0, 4.5
    for _ in range(60):
        m = (lo + hi) / 2
        if bessel(1, lo) * bessel(1, m) <= 0:
            hi = m
        else:
            lo = m
    return (lo + hi) / 2

def encircled(v):
    return 1 - bessel(0, v) ** 2 - bessel(1, v) ** 2
```

```python tests
import math
z = airy_zero()
assert abs(z - 3.8317) < 1e-4, "J1's first zero: 3.8317."
assert abs(z / math.pi - 1.2197) < 1e-4, "That's r = 1.22λf/D."
assert abs(encircled(z) - 0.8378) < 1e-4, "83.8% of the power lies inside the first dark ring."
```

::: right
Right. The first dark ring holds 83.8% of the light, which is why it's the usual definition of a diffraction-limited spot.
:::
:::

::: explain
## Why does the far field of an aperture equal its Fourier transform?

::: model
Each point of the aperture sends a spherical wave to the distant screen. Far enough away, the path from an aperture point to a screen point differs from the path from the aperture's center by an amount that grows linearly with the aperture coordinate and with the screen point's angle, and the quadratic terms in the path difference become negligible: that is the Fraunhofer condition, a small Fresnel number. The field at each screen point is then the sum of the aperture's field weighted by a phase linear in position, which is exactly a Fourier transform evaluated at a spatial frequency set by the screen angle. A lens does the same thing at its focal plane, bringing the far field to a finite distance.
:::
:::
