⚠️ Archived / superseded. This was my first wave-optics simulator. The active computational-holography work now lives in HoloForge (perception-driven degradation experiments + the in-progress preprint). Kept here for reference.
A computational optics simulator built in Python —
A modular wave-optics simulator that lets you interactively explore the physics of coherent light: from the textbook double-slit experiment all the way to digital hologram recording and phase retrieval algorithms used in real research labs.
| Concept | Implementation |
|---|---|
| Complex wave fields | WaveField phasor class with amplitude/phase/intensity |
| Plane waves | WaveField.plane_wave() — tilted reference beams |
| Spherical waves | WaveField.point_source() — Huygens wavelets |
| Gaussian beams | WaveField.gaussian_beam() — TEM₀₀ mode with Gouy phase |
| Wave superposition | WaveField.__add__() — linear interference |
| Intensity detection | I = |E|² — what cameras actually record |
| Apertures & diffraction | core/apertures.py — slit, circle, zone plate, grating |
| Fresnel propagation | FFT transfer-function method — paraxial near-field |
| Angular spectrum | Exact scalar propagation — any distance |
| Fraunhofer / FFT | Far-field ≡ spatial Fourier transform of aperture |
| Digital holography | Off-axis recording + numerical reconstruction |
| Phase retrieval | Gerchberg-Saxton algorithm (50–100 iterations) |
wavesim/
├── core/
│ ├── wave.py # WaveField: complex phasor, amplitude, phase, intensity
│ ├── propagation.py # Fresnel, Angular Spectrum, Fraunhofer — all FFT-based
│ └── apertures.py # Single/double slit, circular, zone plate, grating
├── simulations/
│ ├── diffraction.py # Double-slit, single-slit simulation drivers
│ └── hologram.py # DigitalHologram class + GS phase retrieval
├── visualizations/
│ └── plots.py # All matplotlib figures — dark research-lab aesthetic
├── utils/
│ └── constants.py # SI constants, wavelengths, colourmaps
├── outputs/ # All generated PNG/GIF outputs (auto-created)
├── main.py # CLI runner — all demos in one command
├── requirements.txt
└── README.md
# Clone and install
git clone https://github.com/yourname/wavesim
cd wavesim
pip install -r requirements.txt
# Run all demos (generates ~14 figures + 1 animation)
python main.py
# Run a specific demo
python main.py --demo double # Young's double-slit
python main.py --demo holo # Digital holography pipeline
python main.py --demo fourier # Fourier optics / aperture analysis
python main.py --demo gauss # Gaussian beam propagation
python main.py --demo phase # Gerchberg-Saxton phase retrieval
python main.py --demo anim # Animated propagation GIF
# Adjust parameters from CLI
python main.py --demo double --wavelength 633 --slit_sep 300 --z 0.8python main.py --demo double
Outputs: 01_double_slit.png, 01b_aperture_field.png
Shows: aperture mask → complex field → propagated intensity (log-scale 2D) → 1D profile compared to analytical cos²·sinc² prediction → Fourier spectrum.
Key physics: I(θ) ∝ cos²(πd sinθ/λ) · sinc²(πw sinθ/λ)
Interference fringes from the cos² term; single-slit envelope from sinc². Fringe spacing Δθ = λ/d — wider slit separation gives finer fringes.
python main.py --demo holo
Outputs: 02_holography_pipeline.png, 02b_hologram_spectrum.png
Full pipeline: complex object → propagate to sensor → add tilted reference beam → record intensity (with Poisson + read noise) → multiply by R* → back-propagate → recover amplitude AND phase.
Key physics: I_H = |O+R|² = |O|² + |R|² + O·R* + O*·R
The |R|²·O term is recovered by illuminating with R and propagating back.
Shows the Fourier spectrum of the hologram with separated DC, +1, and −1 orders — the basis of off-axis holography filtering.
python main.py --demo fourier
Three apertures compared: circular (Airy disk), zone plate (diffractive lens), Gaussian soft aperture (no sidelobes).
Each figure: spatial domain → power spectrum → spectral phase → spectral amplitude. Plus Fraunhofer far-field intensity for each.
python main.py --demo gauss
TEM₀₀ Gaussian mode at waist, at Rayleigh range z_R = πw₀²/λ, plus beam-width vs z and peak-intensity vs z curves.
Key physics: w(z) = w₀ √(1 + (z/z_R)²) — beam spreads hyperbolically.
At z = z_R the beam area doubles, intensity halves.
python main.py --demo phase
Outputs: 05_gs_phase_retrieval.png, 05b_gs_target_vs_achieved.png
Recovers a phase hologram whose far-field amplitude matches a target image (a smiley face pattern) using the iterative GS algorithm.
Key physics: Alternate projection between spatial and Fourier domains, enforcing amplitude constraints in each. Convergence curve shown.
This is the same algorithm used to design holograms for SLM-based holographic displays and in X-ray coherent diffractive imaging (CDI).
python main.py --demo anim
Animated GIF: double-slit field propagating from z≈0 to z=40 cm. Shows intensity and phase evolving continuously.
E(x,y) = A(x,y) · exp(iφ(x,y))
I(x,y) = |E(x,y)|²
H(fx,fy,z) = exp(ikz) · exp(-iπλz(fx²+fy²))
U_prop = IFFT[ FFT(u) · H ]
H_AS(fx,fy,z) = exp(i·2π·z · √(1/λ² - fx² - fy²))
U(x,y,z) ∝ ℱ{u(x',y')} evaluated at fx = x/(λz), fy = y/(λz)
ℱ{I_H} = ℱ{|O|²+|R|²} + Ô⊛R̂ + Ô*⊛R̂*
DC at origin +1 order -1 order (twin)
field → FFT → enforce |amplitude| = target → IFFT → enforce source amplitude → repeat
numpy >= 1.24
scipy >= 1.10
matplotlib >= 3.7
opencv-python >= 4.8
Optional (for GPU acceleration extensions):
torch >= 2.0 # PyTorch — GPU-accelerated FFT via torch.fft
cupy # CUDA NumPy-compatible arrays
Install:
pip install -r requirements.txt| Extension | Difficulty | Reference |
|---|---|---|
| Strehl ratio and wavefront aberrations | Goodman Ch. 6 | |
| 4-f spatial filtering system | Saleh & Teich §4.4 | |
| Speckle patterns from rough surfaces | Goodman "Speckle Phenomena" | |
| Optical coherence (partial coherence) | Mandel & Wolf | |
| Multi-wavelength / RGB holography | RGB channel superposition | |
| Volume holography (Kogelnik's theory) | Solymar & Cooke | |
| GPU-accelerated propagation (PyTorch) | torch.fft.fft2 drop-in |
|
| Real-time Streamlit dashboard | streamlit run app.py |
|
| PTYCHO — ptychographic reconstruction | Rodenburg 2008 |
This simulator implements the core numerical methods behind:
- Quantitative phase microscopy (QPM) — recover cell thickness maps without staining
- Digital holographic microscopy (DHM) — 3-D tracking of microorganisms
- Coherent diffractive imaging (CDI) — X-ray imaging below lens resolution limits
- Holographic displays — SLM phase pattern design via GS algorithm
- Adaptive optics — wavefront sensing and correction
- Optical tweezer beam shaping — Gaussian, Laguerre-Gaussian, Bessel beams
- Goodman, J.W. (2005). Introduction to Fourier Optics (3rd ed.). Roberts & Company.
- Schnars, U. & Jüptner, W. (2005). Digital Holography. Springer.
- Saleh, B.E.A. & Teich, M.C. (2019). Fundamentals of Photonics (3rd ed.). Wiley.
- Gerchberg, R.W. & Saxton, W.O. (1972). A practical algorithm for the determination of phase from image and diffraction plane pictures. Optik, 35, 237-246.
- Voelz, D.G. (2011). Computational Fourier Optics: A MATLAB Tutorial. SPIE Press.
Chaitanya Tripathi
"Holography is not a trick. It is a way of seeing." — Dennis Gabor