Examples¶
k-Wave-python examples are organized by topic. Each example uses the setup()/run() pattern and can be run directly:
uv run python examples/ivp_homogeneous_medium.py
No GPU required — all examples run on CPU with NumPy.
Start with the Your First k-Wave Simulation tutorial, then explore by topic:
Initial Value Problems (IVP)¶
Learn fundamental wave physics using initial pressure distributions.
Homogeneous medium — simplest 2D simulation
Heterogeneous medium — spatially varying sound speed and density
1D simulation — reflections at impedance boundaries
3D simulation — extending to three dimensions
Binary sensor mask — defining sensor regions
Recording particle velocity — velocity field output
Photoacoustic waveforms — 2D vs 3D wave spreading
Loading external image — image-based initial pressure
Time-Varying Pressure Sources (TVSP)¶
Transducer-driven simulations with time-varying sources.
Monopole source — single point source
Dipole source — dipole radiation pattern
Steering linear array — beam steering with delays
Snell’s law — refraction at material boundaries
Doppler effect — moving source frequency shift
3D simulation — time-varying source in 3D
Sensor Directivity (SD)¶
How sensor geometry affects measurements.
Directivity modelling 2D — finite sensor size effects
Directivity modelling 3D — 3D directivity
Focused detector 2D — directional sensitivity
Focused detector 3D — 3D focused sensors
Directional array elements — multi-element arrays
Photoacoustic Reconstruction (PR)¶
Image reconstruction from sensor data.
2D FFT line sensor — FFT-based reconstruction
3D FFT planar sensor — 3D FFT reconstruction
Numerical Analysis (NA)¶
Computational methods and optimization.
Controlling the PML — boundary absorption settings
Source smoothing — spatial filtering of sources
Filtering part 1 — grid-imposed frequency limits
Filtering part 2 — filtering source signals
Filtering part 3 — combined filtering
Modelling nonlinearity — nonlinear wave propagation
Optimising performance — speed and memory tips