---
title: Wave lab
heading: Fresnel reflection, Brewster's angle by search, group index and Gaussian pulse spreading, in Python
eyebrow: S5 · Lesson 16 · Wave lab
xp: 60
---

::: hook
Lessons 7 to 10 gave closed forms for reflection at a boundary, for the group index of a dispersive glass and for how far a pulse spreads in a fiber. This lab computes each from its definition: the Fresnel coefficients with complex angles so total internal reflection comes out by itself, Brewster's angle by searching for the zero of $r_p$ rather than by formula, the group index by numerically differentiating n(λ), and the broadening of a Gaussian pulse from the fiber's group-velocity dispersion. Each result is then compared with the formula it should reproduce.
:::

::: play
- The curve is the width of a Gaussian pulse after traveling L in a fiber, $\tau(L) = \tau_0\sqrt{1 + (L/L_D)^2}$, with the dispersion length $L_D = \tau_0^2/|\beta_2|$ and $\beta_2 = -D\lambda^2/(2\pi c)$.
- Short pulses have short dispersion lengths: a 10 ps pulse in standard fiber at 1550 nm doubles its width after about 8 km.
- Far beyond $L_D$ the width grows linearly with distance, as $\Delta\tau = |D|L\Delta\lambda$ predicts.
:::

```sim plot
view: graph
x: L = 0..100 km
y: w = 0..300 ps
slider: t = 2..50 = 10 ps
slider: D = 1..20 = 17
plot: t*sqrt(1 + (L*1e3/((t*1e-12)^2/(D*1e-6*(1550e-9)^2/(2*pi*299792458))))^2) | label: pulse width
```

::: predict
## A 10 ps Gaussian pulse at 1550 nm travels 100 km of fiber with D = 17 ps/(nm·km). Roughly how wide is it at the end?

- [ ] About 10 ps
- [ ] About 24 ps
- [x] About 220 ps
- [ ] About 17 ns

::: reveal
$\beta_2 = -D\lambda^2/(2\pi c) = -2.17 \times 10^{-26}$ s²/m, so $L_D = \tau_0^2/|\beta_2| = 4.6$ km, and 100 km is 21.7 dispersion lengths: $10\sqrt{1 + 21.7^2} = 217$ ps. A 10 Gb/s bit is 100 ps long, so without compensation this link scrambles its bits.
:::
:::

::: nameit
## The computations

- **Fresnel with complex angles:** $\cos\theta_t = \sqrt{1 - (n_1\sin\theta_i/n_2)^2}$ taken as a complex square root; beyond the critical angle it's imaginary and both reflectances come out exactly 1.
- **Brewster by search:** $r_p(\theta)$ changes sign at Brewster's angle; bisection on its sign finds it without the formula, and must agree with $\arctan(n_2/n_1)$.
- **Group index:** $n_g = n - \lambda\,dn/d\lambda$, with the derivative by a central difference.
- **Gaussian pulse broadening:** for a transform-limited Gaussian pulse of width $\tau_0$, $\tau(L) = \tau_0\sqrt{1 + (L/L_D)^2}$ with $L_D = \tau_0^2/|\beta_2|$ and $\beta_2 = -D\lambda^2/(2\pi c)$ (D in s/m², 1 ps/(nm·km) = 10⁻⁶ s/m²).
:::

::: check
kind: python

## Write `fresnel(n1, n2, theta)`: return (Rs, Rp) using a complex square root for $\cos\theta_t$, and `brewster(n1, n2)`: Brewster's angle in degrees, found by bisecting on the sign of $r_p$.

```python starter
def fresnel(n1, n2, theta):
    return (0.0, 0.0)

def brewster(n1, n2):
    return 45.0
```

```python solution
import cmath, math

def fresnel(n1, n2, theta):
    s = n1 * math.sin(theta) / n2
    ct = cmath.sqrt(1 - s * s)
    ci = math.cos(theta)
    rs = (n1 * ci - n2 * ct) / (n1 * ci + n2 * ct)
    rp = (n2 * ci - n1 * ct) / (n2 * ci + n1 * ct)
    return (abs(rs) ** 2, abs(rp) ** 2)

def brewster(n1, n2):
    def rp(th):
        s = n1 * math.sin(th) / n2
        ct = math.sqrt(max(0.0, 1 - s * s))
        ci = math.cos(th)
        return (n2 * ci - n1 * ct) / (n2 * ci + n1 * ct)
    lo, hi = 0.0, math.pi / 2 - 1e-9
    for _ in range(100):
        m = (lo + hi) / 2
        if rp(lo) * rp(m) <= 0:
            hi = m
        else:
            lo = m
    return math.degrees(m)
```

```python tests
import math
assert all(abs(R - 0.04) < 1e-12 for R in fresnel(1, 1.5, 0)), "Normal incidence on glass: 4% for both."
Rs, Rp = fresnel(1, 1.5, math.radians(45))
assert abs(Rs - 0.0920) < 1e-4 and abs(Rp - 0.00847) < 1e-5, "At 45°: 9.2% and 0.85%."
assert all(abs(R - 1) < 1e-12 for R in fresnel(1.5, 1, math.radians(45))), "Past the critical angle: total reflection."
assert abs(brewster(1, 1.5) - math.degrees(math.atan(1.5))) < 1e-9, "Bisection finds arctan(1.5) = 56.3°."
```

::: right
Right. A complex square root makes total internal reflection fall out of the same formula with no special case.
:::
:::

::: check
kind: python

## Write `group_index(n, lam, h=1e-3)`: the group index of a function n(λ) at λ by a central difference, and check it against Cauchy's $A + 3B/\lambda^2$.

```python starter
def group_index(n, lam, h=1e-3):
    return n(lam)
```

```python solution
def group_index(n, lam, h=1e-3):
    return n(lam) - lam * (n(lam + h) - n(lam - h)) / (2 * h)
```

```python tests
cauchy = lambda l: 1.5046 + 4200 / l ** 2
assert abs(group_index(cauchy, 500) - (1.5046 + 3 * 4200 / 500 ** 2)) < 1e-8, "Cauchy's glass at 500 nm: 1.555."
sell = lambda l: (1 + 1.03961212 * (l / 1000) ** 2 / ((l / 1000) ** 2 - 0.00600069867)) ** 0.5
assert 1.43 < sell(550) < 1.44 and group_index(sell, 550) > sell(550), "A one-term Sellmeier glass: the group index exceeds the index in normal dispersion."
```

::: right
Right. Numerical differentiation handles any dispersion formula, Sellmeier's included, where the closed form would be messy.
:::
:::

::: check
kind: python

## Write `pulse_width(t0_ps, D, lam_nm, L_km)`: the width in ps of a Gaussian pulse of initial width t0 after L km of fiber with dispersion D ps/(nm·km), and `dispersion_length(t0_ps, D, lam_nm)` in km.

```python starter
def pulse_width(t0_ps, D, lam_nm, L_km):
    return t0_ps

def dispersion_length(t0_ps, D, lam_nm):
    return 1.0
```

```python solution
import math

def dispersion_length(t0_ps, D, lam_nm):
    lam = lam_nm * 1e-9
    b2 = D * 1e-6 * lam ** 2 / (2 * math.pi * 299792458)
    return (t0_ps * 1e-12) ** 2 / b2 / 1e3

def pulse_width(t0_ps, D, lam_nm, L_km):
    return t0_ps * math.sqrt(1 + (L_km / dispersion_length(t0_ps, D, lam_nm)) ** 2)
```

```python tests
assert abs(dispersion_length(10, 17, 1550) - 4.612) < 0.001, "10 ps at 1550 nm: 4.6 km."
assert abs(pulse_width(10, 17, 1550, 100) - 217.06) < 0.01, "The predict: 217 ps after 100 km."
w1, w2 = pulse_width(10, 17, 1550, 200), pulse_width(10, 17, 1550, 400)
assert abs(w2 / w1 - 2) < 0.01, "Far beyond L_D the width grows linearly."
```

::: right
Right. Shorter pulses have wider spectra and so spread faster: halving $\tau_0$ quarters $L_D$.
:::
:::

::: explain
## Why does a shorter optical pulse spread more quickly in a dispersive fiber?

::: model
A pulse's duration and its spectrum are a Fourier pair: making the pulse shorter spreads its energy over a wider range of frequencies. In a dispersive fiber different frequencies travel at different group velocities, so the spread in arrival times grows with the width of the spectrum and with the distance traveled. A short pulse starts narrow in time but contains many frequencies, so it soon spreads out; a long pulse has a narrow spectrum and travels much farther before broadening noticeably. The dispersion length, proportional to the square of the initial width, captures exactly this trade.
:::
:::
