---
title: Wave packet lab
heading: Spreading, oscillating and tunneling packets, computed with the FFT and the split-step method
eyebrow: B10 · Lesson 13 · Wave packet lab
xp: 50
---

::: hook
Lessons 8 to 12 solved for stationary states and plane waves. Real electrons arrive as packets, localized in space, with a spread of momenta, and moving. A computer can follow a packet directly: in momentum space a free particle's evolution is just a phase factor, and the **split-step Fourier method** alternates between position space, where the potential acts, and momentum space, where the kinetic energy acts, using the FFT. In this lab you'll write that solver and use it to watch a packet spread, oscillate in a well and split at a barrier, checking each against the formulas you already know. Units are those where ħ = m = 1.
:::

::: play
- A free Gaussian packet's width against time, $\sigma(t) = \sigma_0\sqrt{1 + \left(\frac{t}{2\sigma_0^2}\right)^2}$ in units with ħ = m = 1.
- A narrow packet spreads quickly; a wide one barely changes. The readout gives the time for the width to double, $2\sqrt3\sigma_0^2$.
- Your FFT propagator in step 2 must reproduce this curve exactly, since free evolution in momentum space is exact.
:::

```sim plot
view: graph
x: t = 0..50
y: s = 0..20
slider: s0 = 0.5..6 step 0.1 = 2
plot: s0*sqrt(1 + (t/(2*s0^2))^2) | label: packet width | samples: 400
readout: doubling time = 2*sqrt(3)*s0^2 | digits: 4
```

::: predict
## A packet aims at a barrier whose plane-wave transmission at the packet's central energy is exactly 50%. What fraction of the packet gets through?

- [ ] Exactly 50%
- [x] Close to 50%, but not exactly: the packet averages the transmission over its spread of energies
- [ ] 0%: a packet can't tunnel
- [ ] 100%: the faster parts carry it through

::: reveal
Close to 50%, but not exactly. A packet is a superposition of plane waves with a spread of momenta, and each component tunnels with its own probability; the packet's transmission is their weighted average. Because transmission bends with energy, the average differs from the value at the center unless the packet is very wide.
:::
:::

::: nameit
## Free evolution in momentum space

Transform ψ(x) with the FFT to get its momentum amplitudes; each one evolves by $e^{-ik^2t/2}$ (in units ħ = m = 1); transform back. This is exact for a free particle, at any time, with no time steps at all.

## The split-step method

With a potential V(x), the time-step operator $e^{-i(T + V)\Delta t}$ is approximated by

$$e^{-iV\Delta t/2}\,e^{-iT\Delta t}\,e^{-iV\Delta t/2},$$

applying the potential's half-steps in position space and the kinetic step in momentum space. Each factor is a pure phase, so the method conserves probability exactly, and its error per step goes as $\Delta t^3$.

## What to check

- A free packet's width follows $\sigma_0\sqrt{1 + (t/2\sigma_0^2)^2}$ and its center moves at $k_0$.
- A coherent state in a harmonic well (ω = 1) swings to the opposite side in half a period, π, keeping its shape.
- A packet hitting a barrier splits; the transmitted probability is the plane-wave transmission averaged over the packet's momentum distribution, $|\phi(k)|^2 \propto e^{-2\sigma^2(k - k_0)^2}$.

## Probability current

$j = \text{Im}\left(\psi^*\frac{d\psi}{dx}\right)$ (with ħ = m = 1) is the flow of probability; for a plane wave $\frac{e^{ikx}}{\sqrt L}$ it's $\frac kL$, the density times the velocity.
:::

::: example
## A packet with $\sigma_0$ = 2 and $k_0$ = 1 moves freely. Where is it, and how wide, at t = 10?

::: solution
1. **Position.** Its center has moved $k_0t = 10$.
2. **Width.**
   $$\begin{aligned} \sigma &= 2\sqrt{1 + (10/8)^2} \\ &= 3.20 \end{aligned}$$
3. **Compare with the simulation.** The FFT propagator gives 3.2016, matching to every digit shown, because the evolution in momentum space is exact.
4. **What it means.** The width grew by 60% in the time the packet moved five widths: a packet of electrons in a device spreads noticeably over the distances it travels.

**Answer:** its center has moved 10 from where it started, and the packet is 3.20 wide.
:::
:::

::: example
## A coherent state ($\sigma = \frac{1}{\sqrt2}$) starts at x = 5 in a harmonic well with ω = 1. Where is it after t = π?

::: solution
1. **Half a period.** With ω = 1, t = π is half a period, so it's at x = −5, the mirror point, with the same shape.
2. **Compare with the simulation.** The split-step solver with Δt = 0.01 puts the center at −4.99999 and keeps the total probability at 1 to thirteen digits.
3. **Why the method is used.** That it conserves probability exactly, whatever the step, is why it's the standard tool for laser pulses in fibers and wave packets in semiconductor structures.

**Answer:** at x = −5, the mirror point, with the same shape.
:::
:::

::: example
## A packet with $\sigma$ = 15 and $k_0$ = 1.2 (energy 0.72) meets a barrier of height 1 and width 1. How much gets through?

::: solution
1. **Plane-wave transmission.** At the central energy it's 0.545.
2. **Average over the packet.** Averaged over the packet's momentum spread it's 0.545 too, since the spread is small:
   $$\frac{1}{2\sigma} = 0.033$$
3. **The simulation.** A split-step simulation on a grid of spacing 0.0977, though, finds 0.500.
4. **The culprit is the grid.** 11 grid points fall inside the barrier, so the simulated barrier is effectively 1.074 wide, and the averaged transmission for that width is 0.503.
5. **A better-placed grid.** On a grid of spacing 0.1 placed so exactly 10 points fall inside, the simulation gives 0.544. Tunneling depends so steeply on width that how a grid samples a sharp barrier is the main source of error.

**Answer:** about 0.545 of the packet gets through; a simulation only finds this when its grid samples the barrier's width correctly.
:::
:::

::: check
kind: python

## Step 1. Write `gauss(x, s, k0, x0)` returning a normalized Gaussian packet $e^{-(x - x_0)^2/4s^2 + ik_0x}$ on the grid x, and `stats(x, psi)` returning its width and center from $|\psi|^2$.

```python starter
import numpy as np

def gauss(x, s, k0, x0):
    return np.exp(-(x - x0)**2)

def stats(x, psi):
    return 1.0, 0.0

x = np.linspace(-200, 200, 4096, endpoint=False)
print(stats(x, gauss(x, 2.0, 1.0, 5.0)))
```

```python solution
import numpy as np

def gauss(x, s, k0, x0):
    dx = x[1] - x[0]
    psi = np.exp(-(x - x0)**2 / (4 * s * s) + 1j * k0 * x)
    return psi / np.sqrt(np.sum(np.abs(psi)**2) * dx)

def stats(x, psi):
    dx = x[1] - x[0]
    P = np.abs(psi)**2 * dx
    m = np.sum(P * x)
    return float(np.sqrt(np.sum(P * x * x) - m * m)), float(m)

x = np.linspace(-200, 200, 4096, endpoint=False)
print(stats(x, gauss(x, 2.0, 1.0, 5.0)))
```

```python tests
import numpy as np
x = np.linspace(-200, 200, 4096, endpoint=False)
p = gauss(x, 2.0, 1.0, 5.0)
assert abs(np.sum(np.abs(p)**2) * (x[1] - x[0]) - 1) < 1e-12, "The packet must be normalized."
w, c = stats(x, p)
assert abs(w - 2.0) < 1e-9 and abs(c - 5.0) < 1e-9, f"Expect width 2 and center 5; got {w}, {c}."
```

::: right
Right. With the 4s² in the exponent, the s you pass is exactly the standard deviation of $|\psi|^2$.
:::
:::

::: check
kind: python

## Step 2. Write `free(x, psi, t)` that evolves a free packet by time t (ħ = m = 1) exactly, using the FFT: multiply each momentum component by $e^{-ik^2t/2}$, with k from `np.fft.fftfreq`. `gauss` and `stats` are included.

```python starter
import numpy as np

def gauss(x, s, k0, x0):
    dx = x[1] - x[0]
    psi = np.exp(-(x - x0)**2 / (4 * s * s) + 1j * k0 * x)
    return psi / np.sqrt(np.sum(np.abs(psi)**2) * dx)

def stats(x, psi):
    dx = x[1] - x[0]
    P = np.abs(psi)**2 * dx
    m = np.sum(P * x)
    return float(np.sqrt(np.sum(P * x * x) - m * m)), float(m)

def free(x, psi, t):
    return psi

x = np.linspace(-200, 200, 4096, endpoint=False)
print(stats(x, free(x, gauss(x, 2.0, 1.0, 0.0), 10.0)))
```

```python solution
import numpy as np

def gauss(x, s, k0, x0):
    dx = x[1] - x[0]
    psi = np.exp(-(x - x0)**2 / (4 * s * s) + 1j * k0 * x)
    return psi / np.sqrt(np.sum(np.abs(psi)**2) * dx)

def stats(x, psi):
    dx = x[1] - x[0]
    P = np.abs(psi)**2 * dx
    m = np.sum(P * x)
    return float(np.sqrt(np.sum(P * x * x) - m * m)), float(m)

def free(x, psi, t):
    k = 2 * np.pi * np.fft.fftfreq(len(x), x[1] - x[0])
    return np.fft.ifft(np.fft.fft(psi) * np.exp(-0.5j * k * k * t))

x = np.linspace(-200, 200, 4096, endpoint=False)
print(stats(x, free(x, gauss(x, 2.0, 1.0, 0.0), 10.0)))
```

```python tests
import numpy as np
x = np.linspace(-200, 200, 4096, endpoint=False)
w, c = stats(x, free(x, gauss(x, 2.0, 1.0, 0.0), 10.0))
assert abs(w - 2.0 * np.sqrt(1 + (10 / 8)**2)) < 1e-9, f"After t = 10 the width is 3.2016; got {w:.6f}."
assert abs(c - 10.0) < 1e-9, f"The center moves at k0: it should be at 10; got {c}."
w2, _ = stats(x, free(x, gauss(x, 0.5, 0.0, 0.0), 2 * np.sqrt(3) * 0.25))
assert abs(w2 - 1.0) < 1e-6, "A packet of width 0.5 doubles at t = 2√3 σ0²."
```

::: right
Right. Free evolution needs no time steps at all: the FFT makes it exact at any time.
:::
:::

::: check
kind: python

## Step 3. Write `ssfm(x, psi, V, dt, n)` that takes n split-step Fourier steps: half a potential step, a full kinetic step in momentum space, and another half potential step. `gauss` and `stats` are included.

```python starter
import numpy as np

def gauss(x, s, k0, x0):
    dx = x[1] - x[0]
    psi = np.exp(-(x - x0)**2 / (4 * s * s) + 1j * k0 * x)
    return psi / np.sqrt(np.sum(np.abs(psi)**2) * dx)

def stats(x, psi):
    dx = x[1] - x[0]
    P = np.abs(psi)**2 * dx
    m = np.sum(P * x)
    return float(np.sqrt(np.sum(P * x * x) - m * m)), float(m)

def ssfm(x, psi, V, dt, n):
    return psi * np.exp(-1j * V * dt * n)

x = np.linspace(-200, 200, 4096, endpoint=False)
q = ssfm(x, gauss(x, 1 / np.sqrt(2), 0.0, 5.0), 0.5 * x * x, 0.01, 314)
print(stats(x, q))
```

```python solution
import numpy as np

def gauss(x, s, k0, x0):
    dx = x[1] - x[0]
    psi = np.exp(-(x - x0)**2 / (4 * s * s) + 1j * k0 * x)
    return psi / np.sqrt(np.sum(np.abs(psi)**2) * dx)

def stats(x, psi):
    dx = x[1] - x[0]
    P = np.abs(psi)**2 * dx
    m = np.sum(P * x)
    return float(np.sqrt(np.sum(P * x * x) - m * m)), float(m)

def ssfm(x, psi, V, dt, n):
    k = 2 * np.pi * np.fft.fftfreq(len(x), x[1] - x[0])
    half = np.exp(-0.5j * V * dt)
    kin = np.exp(-0.5j * k * k * dt)
    for _ in range(n):
        psi = half * np.fft.ifft(kin * np.fft.fft(half * psi))
    return psi

x = np.linspace(-200, 200, 4096, endpoint=False)
q = ssfm(x, gauss(x, 1 / np.sqrt(2), 0.0, 5.0), 0.5 * x * x, 0.01, 314)
print(stats(x, q))
```

```python tests
import numpy as np
x = np.linspace(-200, 200, 4096, endpoint=False)
q = ssfm(x, gauss(x, 1 / np.sqrt(2), 0.0, 5.0), 0.5 * x * x, np.pi / 314, 314)
w, c = stats(x, q)
assert abs(c + 5) < 1e-4, f"After half a period the coherent state should sit at x = -5; got {c:.6f}."
assert abs(w - 1 / np.sqrt(2)) < 1e-4, f"It keeps its width, 0.7071; got {w:.6f}."
assert abs(np.sum(np.abs(q)**2) * (x[1] - x[0]) - 1) < 1e-10, "Every factor is a phase, so the norm must stay 1."
```

::: right
Right. The coherent state swings to the mirror point without spreading, as lesson 8 promised.
:::
:::

::: check
kind: python

## Step 4. Write `transmitted(s, k0, V0, d)` that sends a packet of width s and wavenumber k0 from x = −80 at a barrier of height V0 and width d centered at 0, on the grid $x_i = -400 + (i + \frac12)\times 0.1$ for i = 0 to 7999 (so a width-1 barrier covers exactly 10 points), runs the split-step solver (Δt = 0.05) until t = 240/k0, and returns the probability beyond the barrier. Then write `average_T(s, k0, V0, d)`, the plane-wave transmission averaged over the packet's momentum distribution. `gauss` and `ssfm` are included.

```python starter
import numpy as np
import math

def gauss(x, s, k0, x0):
    dx = x[1] - x[0]
    psi = np.exp(-(x - x0)**2 / (4 * s * s) + 1j * k0 * x)
    return psi / np.sqrt(np.sum(np.abs(psi)**2) * dx)

def ssfm(x, psi, V, dt, n):
    k = 2 * np.pi * np.fft.fftfreq(len(x), x[1] - x[0])
    half = np.exp(-0.5j * V * dt)
    kin = np.exp(-0.5j * k * k * dt)
    for _ in range(n):
        psi = half * np.fft.ifft(kin * np.fft.fft(half * psi))
    return psi

def transmitted(s, k0, V0, d):
    return 0.5

def average_T(s, k0, V0, d):
    return 0.5

print(transmitted(15.0, 1.2, 1.0, 1.0), average_T(15.0, 1.2, 1.0, 1.0))
```

```python solution
import numpy as np
import math

def gauss(x, s, k0, x0):
    dx = x[1] - x[0]
    psi = np.exp(-(x - x0)**2 / (4 * s * s) + 1j * k0 * x)
    return psi / np.sqrt(np.sum(np.abs(psi)**2) * dx)

def ssfm(x, psi, V, dt, n):
    k = 2 * np.pi * np.fft.fftfreq(len(x), x[1] - x[0])
    half = np.exp(-0.5j * V * dt)
    kin = np.exp(-0.5j * k * k * dt)
    for _ in range(n):
        psi = half * np.fft.ifft(kin * np.fft.fft(half * psi))
    return psi

def T_plane(E, V0, d):
    if E < V0:
        kap = math.sqrt(2 * (V0 - E))
        return 1 / (1 + V0**2 * math.sinh(kap * d)**2 / (4 * E * (V0 - E)))
    kk = math.sqrt(2 * (E - V0))
    return 1 / (1 + V0**2 * math.sin(kk * d)**2 / (4 * E * (E - V0) + 1e-300))

def transmitted(s, k0, V0, d):
    x = -400 + (np.arange(8000) + 0.5) * 0.1
    V = np.where(np.abs(x) < d / 2, V0, 0.0)
    q = ssfm(x, gauss(x, s, k0, -80.0), V, 0.05, int(240 / k0 / 0.05))
    return float(np.sum(np.abs(q[x > d / 2])**2) * (x[1] - x[0]))

def average_T(s, k0, V0, d):
    ks = np.linspace(k0 - 4 / s, k0 + 4 / s, 2001)
    w = np.exp(-2 * s * s * (ks - k0)**2)
    T = np.array([T_plane(k * k / 2, V0, d) for k in ks])
    return float(np.sum(w * T) / np.sum(w))

print(transmitted(15.0, 1.2, 1.0, 1.0), average_T(15.0, 1.2, 1.0, 1.0))
```

```python tests
t = transmitted(15.0, 1.2, 1.0, 1.0)
a = average_T(15.0, 1.2, 1.0, 1.0)
assert abs(a - 0.54505) < 1e-3, f"The averaged plane-wave transmission is 0.545; got {a:.5f}."
assert abs(t - a) < 0.005, f"With the barrier sampled exactly, the packet's transmission should match the average; got {t:.4f} and {a:.4f}."
```

::: right
Right. With the barrier sampled exactly, the simulation lands within 0.3% of the averaged transmission; on the misaligned grid of the example it was 8% low, from a barrier 7% too wide.
:::
:::

::: check
kind: python

## Step 5. Write `current(x, psi)` returning the probability current $\text{Im}\left(\psi^*\frac{d\psi}{dx}\right)$ on the grid, computing the derivative with the FFT (multiply by ik).

```python starter
import numpy as np

def current(x, psi):
    return np.zeros(len(x))

x = np.linspace(0, 100, 1000, endpoint=False)
print(current(x, np.exp(1j * 2 * np.pi * 10 / 100 * x) / np.sqrt(100))[:3])
```

```python solution
import numpy as np

def current(x, psi):
    k = 2 * np.pi * np.fft.fftfreq(len(x), x[1] - x[0])
    dpsi = np.fft.ifft(1j * k * np.fft.fft(psi))
    return np.imag(np.conj(psi) * dpsi)

x = np.linspace(0, 100, 1000, endpoint=False)
print(current(x, np.exp(1j * 2 * np.pi * 10 / 100 * x) / np.sqrt(100))[:3])
```

```python tests
import numpy as np
x = np.linspace(0, 100, 1000, endpoint=False)
kk = 2 * np.pi * 10 / 100
j = current(x, np.exp(1j * kk * x) / np.sqrt(100))
assert np.allclose(j, kk / 100), f"A plane wave carries current k/L = {kk / 100:.5f}; got {j[:3]}."
assert np.allclose(current(x, np.cos(kk * x) / np.sqrt(50)), 0, atol=1e-12), "A standing wave carries no current."
```

::: right
Right. A standing wave, equal parts left- and right-moving, carries no net current, though its density is far from uniform.
:::
:::

::: check
given: s = 0.5 | 1 | 3
answer: 2*sqrt(3)*s^2
tolerance: 0.5%

## In units where ħ = m = 1, how long does a free packet of initial width {s} take to double in width?

::: right
Right. $2\sqrt3\sigma_0^2$.
:::

::: misses
- [sqrt(3)*s^2] Set $\sqrt{1 + (t/2\sigma_0^2)^2} = 2$.
- [any] $1 + (t/2\sigma_0^2)^2 = 4$.
:::
:::

::: check
given: s = 5 | 15 | 40
answer: 1/(2*s)
tolerance: 0.5%

## A packet has width {s} (ħ = m = 1). What is its spread in wavenumber?

::: right
Right. $\sigma_k = \frac{1}{2\sigma_x}$ for a Gaussian.
:::

::: misses
- [1/s] The minimum product is ½.
- [any] $\sigma_x\sigma_k = \frac12$.
:::
:::

::: explain
## Why does the split-step method conserve probability exactly, no matter how large its time step?

::: model
Each step multiplies the wave function by pure phase factors: the potential's half steps by $e^{-iV\Delta t/2}$ at each point, and the kinetic step by $e^{-ik^2\Delta t/2}$ for each momentum component. A phase factor has magnitude 1, so it can't change $|\psi|^2$ at any point in position space, and the Fourier transforms between the two spaces preserve the total probability by Parseval's theorem. So the total probability is unchanged by every factor. The step size controls how accurately the method separates the kinetic and potential effects, which affects where the probability goes, but never how much there is.
:::
:::

::: practice

::: check
given: s = 1 | 4; t = 5 | 20
answer: s*sqrt(1 + (t/(2*s^2))^2)
tolerance: 0.5%

## Width of a free packet ($\sigma_0$ = {s}, ħ = m = 1) at t = {t}?

::: misses
- [any] $\sigma_0\sqrt{1 + (t/2\sigma_0^2)^2}$.
:::
:::

::: check
given: k = 0.5 | 2; t = 10 | 40
answer: k*t
tolerance: 0.5%

## How far does a packet with $k_0$ = {k} move in time {t} (ħ = m = 1)?

::: misses
- [any] Its center moves at $k_0$.
:::
:::
:::
