Skip to content
This repository was archived by the owner on Jun 21, 2026. It is now read-only.

ultramagnus23/WaveSim-optics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ 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.


Interactive Wave Interference & Digital Holography Simulator

A computational optics simulator built in Python —


What This Is

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.


Physics Covered

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)

Project Structure

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

Quick Start

# 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.8

Demos & Outputs

Demo 1 — Young's Double-Slit Experiment

python 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.


Demo 2 — Digital Holography Pipeline

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.


Demo 3 — Fourier Optics & Aperture Diffraction

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.


Demo 4 — Gaussian Beam Propagation

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.


Demo 5 — Gerchberg-Saxton Phase Retrieval

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).


Demo 6 — Propagation Animation

python main.py --demo anim

Animated GIF: double-slit field propagating from z≈0 to z=40 cm. Shows intensity and phase evolving continuously.


Key Equations Reference

Complex wave field

E(x,y) = A(x,y) · exp(iφ(x,y))
I(x,y) = |E(x,y)|²

Fresnel transfer function (FFT form)

H(fx,fy,z) = exp(ikz) · exp(-iπλz(fx²+fy²))
U_prop = IFFT[ FFT(u) · H ]

Angular spectrum transfer function (exact)

H_AS(fx,fy,z) = exp(i·2π·z · √(1/λ² - fx² - fy²))

Fraunhofer / far-field

U(x,y,z) ∝ ℱ{u(x',y')} evaluated at fx = x/(λz), fy = y/(λz)

Off-axis hologram Fourier structure

ℱ{I_H} = ℱ{|O|²+|R|²}  +  Ô⊛R̂  +  Ô*⊛R̂*
           DC at origin       +1 order   -1 order (twin)

Gerchberg-Saxton iteration

field → FFT → enforce |amplitude| = target → IFFT → enforce source amplitude → repeat

Requirements

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

Extending the Project

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

Research Connections

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

References

  1. Goodman, J.W. (2005). Introduction to Fourier Optics (3rd ed.). Roberts & Company.
  2. Schnars, U. & Jüptner, W. (2005). Digital Holography. Springer.
  3. Saleh, B.E.A. & Teich, M.C. (2019). Fundamentals of Photonics (3rd ed.). Wiley.
  4. 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.
  5. Voelz, D.G. (2011). Computational Fourier Optics: A MATLAB Tutorial. SPIE Press.

Author

Chaitanya Tripathi

"Holography is not a trick. It is a way of seeing." — Dennis Gabor

About

Archived predecessor to HoloForge — wave-optics & digital-holography simulator (double-slit → Gerchberg-Saxton). Active work: github.com/ultramagnus23/HoloForge

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages