Quickstart#

This notebook walks through the core DiffeRT workflow:

  1. Load a Scene: Import 3D meshes and configure transmitter/receiver positions.

  2. Trace Multi-Order Paths: Compute exact propagation ray paths including Line-of-Sight (LoS), specular reflections, and edge diffractions.

  3. Compute Fields & Power: Evaluate electromagnetic fields, Channel Impulse Response (CIR), and received power using TracedFields.

  4. Customize EM Solver: Adjust antenna radiation patterns, polarization, and wavefront curvature.

import differt.plotting as dplt
import jax.numpy as jnp
import matplotlib.pyplot as plt
from differt.em import (
    Diffraction,
    Dipole,
    InteractionType,
    SpecularReflection,
    compute_received_power,
)
from differt.geometry import (
    Scene,
    TracedPaths,
    download_sionna_scenes,
    get_sionna_scene,
)

A note on imports#

The rest of this notebook uses explicit, submodule-qualified imports (e.g., from differt.geometry import Scene), which is the recommended style for library code. For quick, interactive use, commonly used classes, functions, and interaction types are also re-exported directly from the top-level differt package (see the differt package reference for the full list of re-exported names):

download_sionna_scenes()  # Download Sionna sample scenes
dplt.set_backend("plotly")  # Use Plotly 3D backend

Loading a Scene#

We load a standard urban street canyon scene and set transmitter and receiver positions:

file = get_sionna_scene("simple_street_canyon")
mesh = Scene.load_xml(file).mesh.set_assume_quads(True)
scene = Scene(
    transmitters=jnp.array([[-33.0, 0.0, 32.0]]),
    receivers=jnp.array([[10.0, 0.0, 1.5]]),
    mesh=mesh,
)
scene.plot()

Tracing Multi-Order Ray Paths#

We use scene.trace_paths to compute all valid propagation paths from Line-of-Sight (order=0) up to second-order interactions (order=range(3)).

By specifying allowed_interactions=frozenset({SpecularReflection, Diffraction}), DiffeRT traces both specular reflections and edge diffractions in a single call. To limit computation time, we cap the number of edge diffractions along each path using max_diffractions=1:

# Trace paths up to 2nd order with reflections and edge diffractions
paths = scene.trace_paths(
    order=range(3),
    allowed_interactions=frozenset({SpecularReflection, Diffraction}),
    max_diffractions=1,
)

# Split paths into separate instances for each interaction order and type
paths_by_order = paths.split_by_order(masked=True)


def path_label(p: TracedPaths) -> str:
    """Return a descriptive label for a path group."""
    if p.order == 0:
        return "Direct (LoS)"
    types = " → ".join(
        InteractionType(int(it)).name.capitalize()
        for it in p.interaction_types[0]
    )
    return f"Order {p.order} ({types})"


for p in paths_by_order:
    print(f"{path_label(p)}: {p.num_valid_paths} valid paths")

with dplt.reuse(backend="plotly") as fig:
    scene.plot(opacity=0.3)
    paths.plot()
fig
Direct (LoS): 1 valid paths
Order 1 (Reflection): 3 valid paths
Order 1 (Diffraction): 24 valid paths
Order 2 (Reflection → Reflection): 2 valid paths
Order 2 (Reflection → Diffraction): 24 valid paths
Order 2 (Diffraction → Reflection): 36 valid paths

Computing Electromagnetic Fields & CIR#

We compute the received electromagnetic fields using paths.to_fields, which returns a TracedFields instance. For reflection paths, Fresnel reflection coefficients are evaluated with dielectric material properties; for diffraction paths, DiffeRT applies the Uniform Theory of Diffraction (UTD).

From TracedFields, we can directly extract:

  • Channel Impulse Response (CIR): fields.cir() gives (delay, field_gain) pairs.

  • Received Power: fields.power() in dBW (both per-path and combined coherently or non-coherently).

frequency = 3.5e9  # 3.5 GHz carrier frequency

# Compute fields for each interaction group using TracedFields
fields_by_order = [
    p.to_fields(scene.mesh, frequency=frequency) for p in paths_by_order
]

for p, fields in zip(paths_by_order, fields_by_order, strict=True):
    delays, _ = fields.cir()
    powers = fields.power()
    print(
        f"{path_label(p):<35}: "
        f"{len(powers):2d} paths | "
        f"delays {delays.min() * 1e9:5.1f} - {delays.max() * 1e9:5.1f} ns | "
        f"max power {powers.max():6.1f} dBW"
    )

total_coherent_power = compute_received_power(
    sum(f.fields.sum(axis=-1) for f in fields_by_order)
)
print(f"\nTotal coherent received power: {float(total_coherent_power):.1f} dBW")
Direct (LoS)                       :  1 paths | delays 175.9 - 175.9 ns | max power -103.5 dBW
Order 1 (Reflection)               :  3 paths | delays 181.9 - 187.1 ns | max power -106.2 dBW
Order 1 (Diffraction)              : 24 paths | delays 185.2 - 515.5 ns | max power -129.1 dBW
Order 2 (Reflection → Reflection)  :  2 paths | delays 190.8 - 192.8 ns | max power -122.5 dBW
Order 2 (Reflection → Diffraction) : 24 paths | delays 218.4 - 526.3 ns | max power -138.2 dBW
Order 2 (Diffraction → Reflection) : 36 paths | delays 191.0 - 517.6 ns | max power -145.1 dBW

Total coherent received power: -103.3 dBW

Plotting the Channel Impulse Response (CIR)#

We visualize the multipath CIR across all interaction types and orders:

plt.figure(figsize=(9, 4.5))
colors = ["#1f77b4", "#2ca02c", "#d62728", "#9467bd", "#ff7f0e", "#e377c2"]

for p, fields, color in zip(
    paths_by_order, fields_by_order, colors, strict=False
):
    delays, _ = fields.cir()
    powers = fields.power()
    markerline, stemlines, _ = plt.stem(
        delays * 1e9,
        powers,
        linefmt=color,
        markerfmt="o",
        basefmt="k-",
        label=path_label(p),
    )
    plt.setp(stemlines, linewidth=1.5, color=color)
    plt.setp(markerline, markersize=5, color=color)

plt.xlabel("Propagation Delay (ns)")
plt.ylabel("Received Power (dBW)")
plt.title("Channel Impulse Response (CIR) across Multipath Interactions")
plt.legend()
plt.grid(visible=True, alpha=0.3)
plt.show()
../_images/5e015c0e1a6e29b380dfc53c9620aff2ac9fd48be546e66a8e26d707df82b90f.png

Customizing the EM Computation#

Antenna Patterns & Polarization#

tx_polarization and rx_polarization default to "V" (vertical) but also accept "H", explicit Jones vectors, or an AbstractAntenna instance (such as Dipole):

# Select 1st-order reflections (the second group in paths_by_order)
refl_paths = paths_by_order[1]

dipole = Dipole(frequency=frequency, num_wavelengths=0.5)
fields_dipole = refl_paths.to_fields(
    scene.mesh, frequency, tx_polarization=dipole
)
print(
    "Dipole TX power (order 1 reflection):",
    float(fields_dipole.power(coherent=True, axis=-1)),
    "dBW",
)
Dipole TX power (order 1 reflection): -100.68312072753906 dBW

Wavefront Curvature#

By default, transmitter sources are assumed to have a planar wavefront at large distances. You can specify spherical or astigmatic wavefront curvatures via tx_wavefront_radii:

fields_curved = refl_paths.to_fields(
    scene.mesh, frequency, tx_wavefront_radii=5.0
)
print(
    "Planar source total power (order 1 reflection):",
    float(fields_by_order[1].power(coherent=True, axis=-1)),
    "dBW",
)
print(
    "Curved source total power (order 1 reflection):",
    float(fields_curved.power(coherent=True, axis=-1)),
    "dBW",
)
Planar source total power (order 1 reflection): -109.43496704101562 dBW
Curved source total power (order 1 reflection): -110.17989349365234 dBW

Where to Go Next#

  • For an in-depth mathematical exploration of individual interaction physics (specular reflection two-ray interference, UTD wedge diffraction shadow regions, dielectric slab wall transmission, and diffuse scattering), check out the dedicated tutorial EM Fields’ ABC.

  • For advanced path tracing and custom scene meshes, see Advanced Path Tracing.