Contents

Sionna Source Code Explained: antenna.py and channel_coefficients.py Function-by-Function Against 3GPP 38.901

Sionna Source Code
#Sionna#38.901#antenna-modeling#channel-modeling#source-code

This post is the companion to the 38.901 §7.5 Twelve-Step Channel Generation Guide. That post follows the formula derivation across the twelve steps; this post follows the source files, walking function by function through the two low-level files of the 3GPP 38.901 model:

  • src/sionna/phy/channel/tr38901/antenna.py (755 lines) — antenna modeling;
  • src/sionna/phy/channel/tr38901/channel_coefficients.py (1062 lines) — channel-coefficient generation.

All analysis is based on the local Sionna 1.x (PyTorch implementation); line numbers refer to that version. Both files are short enough to read side by side. Jump back to the companion post whenever a full derivation of a specific formula is needed.

0. Where the two files sit in 38.901

FileLinesTR 38.901 clausesResponsibility
antenna.py755§7.3 “Antenna model” (eqs. 7.3-1/2/4/5, Table 7.3-1); §7.1 polarization slant angle γDefines how one element radiates, how elements form a panel, and how panels form an array
channel_coefficients.py1062§7.1 coordinate transforms (eqs. 7.1-4/6/7/8/11/15); §7.5 Steps 10/11 (eqs. 7.5-21 to 7.5-30, Table 7.5-5)Synthesizes rays + topology into per-antenna-pair, per-time-sample channel coefficients h

The call chain of one full invocation (inside UMa/UMi/RMa/CDL):

CDL / UMa / UMi / RMa  (system_level_channel.py, cdl.py)
   │  produce Rays (angles/powers/delays/XPR) and Topology (velocities/orientations/LoS info)
   ▼
ChannelCoefficientsGenerator.__call__            channel_coefficients.py L282
   ├─ _step_10  L544   random initial phases φ ∈ R^{...×4}   ← §7.5 Step 10
   └─ _step_11  L1010  channel-matrix synthesis              ← §7.5 Step 11
        ├─ _step_11_nlos          L841   per-ray full matrix (7.5-28)
        │    ├─ _step_11_phase_matrix L579   polarization/phase/XPR matrix (7.5-22)
        │    ├─ _step_11_field_matrix L725   element-response dot product (7.1-11 + 7.3-4/5)
        │    ├─ _step_11_array_offsets L661  array phase offsets (7.5-22 exponent)
        │    └─ _step_11_doppler_matrix L610 Doppler phase (7.5-25)
        ├─ _step_11_reduce_nlos   L878   ray summation / sub-cluster split (7.5-27, Table 7.5-5)
        ├─ _step_11_los           L959   deterministic LoS matrix (7.5-29)
        └─ K-factor weighting and LoS/NLoS link selection L1047-1058 (7.5-30)

PanelArray (or its subclasses Antenna/AntennaArray) from antenna.py is passed to the generator constructor as tx_array/rx_array (channel_coefficients.py L163-164) and consumed in _step_11_field_matrix and _step_11_array_offsets.


1. antenna.py: three-tier antenna modeling (§7.3)

1.1 Class hierarchy overview

ClassLinesStandardOne-line role
AntennaElementL18-183§7.3 eqs. 7.3-1/2/4/5, Table 7.3-1One element: pattern + slant angle γ → field components (f_θ, f_φ)
AntennaPanelL186-290§7.3 panel geometryPositions of M×N elements within a panel (in wavelengths)
PanelArrayL293-630§7.3 arrayAssembles panels into a full array, converts positions to meters
AntennaL633-685—PanelArray special case: 1×1 element, single panel
AntennaArrayL688-754—PanelArray special case: one panel of num_rows×num_cols elements

1.2 AntennaElement (L18-183): element pattern and polarization

Member mapping table

MemberLinesStandardWhat it does
__init__L44-63—Validates pattern ∈ {"omni","38.901"} (L52-53); registers slant_angle as a buffer (L57, CUDA-Graph friendly); dispatches the pattern function (L60-63)
field(theta, phi)L75-86eqs. 7.3-4/5Returns field pattern (f_θ, f_φ)
show()L88-135—Plots vertical/horizontal cuts and the 3D power pattern
_radiation_pattern_omniL137-143—Omnidirectional: constant 1
_radiation_pattern_38901L145-160eqs. 7.3-1/2 + Table 7.3-1Returns the linear power pattern 10^(A'/10)
_compute_gain()L162-183§7.3 gain definitionNumerical integration for gain and directivity (dBi)

Pattern formulas (eqs. 7.3-1/2, Table 7.3-1)

The standard’s generic BS/UMa element pattern (dB):

A(θ,ϕ)=−min⁡ ⁣[12(θ−90∘θ3dB)2,SLAv]−min⁡ ⁣[12(ϕϕ3dB)2,Am]A(\theta,\phi)=-\min\!\Big[12\Big(\tfrac{\theta-90^\circ}{\theta_{3\mathrm{dB}}}\Big)^2,\mathrm{SLA_v}\Big]-\min\!\Big[12\Big(\tfrac{\phi}{\phi_{3\mathrm{dB}}}\Big)^2,A_m\Big]

A′(θ,ϕ)=−min⁡[−A(θ,ϕ), Am]+GEmaxA'(\theta,\phi)=-\min\big[-A(\theta,\phi),\,A_m\big]+G_{\mathrm{Emax}}

The code maps line by line (L151-160):

Code lineVariableTable 7.3-1 valueMeaning
L151theta_3db = phi_3db = 65°θ_3dB = φ_3dB = 65°3-dB beamwidth
L152a_max = sla_v = 30.0A_m = SLA_v = 30 dBSide-lobe attenuation cap
L153g_e_max = 8.0G_Emax = 8 dBiMax gain
L154-155a_v = -min(12((θ-π/2)/θ_3dB)², 30)first term of 7.3-1vertical cut
L156-157a_h = -min(12(φ/φ_3dB)², 30)second term of 7.3-1horizontal cut
L158-159a_db = -min(-(a_v+a_h), 30) + 8eq. 7.3-2combined, capped
L160return 10 ** (a_db/10)—dB → linear power

Note that θ in the code is the zenith angle, so the “off-boresight angle” of 7.3-1 is written as (θ - π/2); at boresight (θ=90°, φ=0°) A’=G_Emax=8 dBi.

Field components and slant angle γ (eqs. 7.3-4/5)

field() (L75-86) turns the power pattern into a field amplitude and projects it onto the two basis polarizations via slant angle γ:

a(θ,ϕ)=10A′(θ,ϕ)/10,fθ=acos⁡γ,fϕ=asin⁡γa(\theta,\phi)=\sqrt{10^{A'(\theta,\phi)/10}},\qquad f_\theta=a\cos\gamma,\qquad f_\phi=a\sin\gamma

Code L83-85: a = torch.sqrt(pattern), f_theta = a*cos(γ), f_phi = a*sin(γ). γ is in radians: γ=0 is pure vertical (V), γ=π/2 pure horizontal (H), γ=±π/4 the ±45° slant polarizations. The only difference between the two ±45° antennas is the sign of γ: pol1 takes −π/4 and pol2 takes +π/2−π/4=+π/4 (see the §1.4 mapping table), hence f_θ(−45°)=f_φ(+45°) and f_φ(−45°)=−f_θ(+45°). The spherical-basis meaning of F_rx/F_tx and the full ±45° derivation inside 7.5-22 are covered in the companion post’s deep-dive sections.

Numerical example: boresight with cross polarization

import torch
from sionna.phy.channel.tr38901 import AntennaElement

ant = AntennaElement("38.901", slant_angle=-torch.pi / 4)   # -45° slant
f_t, f_p = ant.field(torch.tensor([torch.pi / 2]), torch.tensor([0.0]))

By hand: at θ=90°, φ=0°, a_v=0 and a_h=0, so A’=8 dBi, linear power 10^0.8≈6.310, amplitude a=√6.310≈2.512; therefore f_θ=2.512·cos(−45°)≈1.776, f_φ=2.512·sin(−45°)≈−1.776. Steering to φ=30°: a_h=−12(30/65)²≈−2.556, A’≈5.44 dBi, linear ≈3.50, a≈1.871 — the pattern roll-off shows up directly in the field components.

1.3 AntennaPanel (L186-290): panel geometry

AntennaPanel does one thing: compute each element position in the panel’s local coordinate system (LCS) on the y–z plane (in units of λ0).

Antenna array vs LCS axis definitions: x′ = panel normal = boresight direction (θ=90°, φ=0); y′ along columns (j increasing); z′ the vertical reference axis (rows i run along −z′, θ′ measured from z′); the panel lies in the y′–z′ plane (x′=0) with origin O at the array center; spherical angles θ′/φ′ of the ray ρ̂′ follow eqs. 7.1-7/8

Fig. 1: Antenna array and the local coordinate system (LCS) — axis definitions and spherical angles.

Full axis definitions (the 38.901 §7.1/§7.3 convention):

AxisOrientationRole in the formulas
x′panel normal, pointing at the boresightmain-lobe direction of the element pattern: max gain at θ=π/2, φ=0 (symmetry axis of A_h in eq. 7.3-1); reference axis of φ′
y′horizontal in the panel plane, columns j grow toward +y′horizontal component of element positions [0, j·Δh, −i·Δv] (L227-231); enters φ′ as the imaginary part of arg
z′vertical in the panel plane, rows i run downward along −z′polar axis of θ′: θ′ = arccos(ẑ′·ρ̂′) (eq. 7.1-7, _v1_const=[0,0,1])

Note the pattern formula a_v ∝ (θ − π/2)² (L154): θ is measured from z′, so the main lobe sits at θ=π/2 — on the x′ axis. This is the direct consequence of the “panel in the y′–z′ plane, normal = x′” convention. The LCS orientation relative to the GCS is set by the bearing α → downtilt β → slant γ rotations (eq. 7.1-4; see Fig. 5).

StepLinesContent
polarization checkL213-214polarization ∈ {"single","dual"}
first polarizationL227-231ant_pos[i + j·num_rows] = [0, j·Δh, -i·Δv]: i is the row index (along −z), j the column index (along +y)
centeringL234-237shift by offset = [0, -(N-1)Δh/2, (M-1)Δv/2] so the panel is centered at the origin
second polarization copyL240-241for dual, the first M·N positions are copied verbatim to the next M·N — the two polarizations are co-located

So a dual M×N panel holds 2MN elements stored as all MN pol1 positions first, then all MN pol2 positions (blocked, not interleaved). This storage convention directly determines the polarization indexing in §1.4.

AntennaPanel M×N layout on the y–z plane: filled red dots = polarization 1, blue rings = polarization 2 (co-located copy); Δh/Δv are element spacings, panel centered at the origin

Fig. 2: AntennaPanel element layout (LCS y–z plane, units of λ0).

1.4 PanelArray (L293-630): panel array and polarization types

Default spacing rules (L377-395)

ParameterDefaultLinesConstraint
element_vertical/horizontal_spacing0.5 λ0L377-380—
panel_vertical_spacing(M−1)·Δv + 0.5L382-384must exceed panel height (L393-395)
panel_horizontal_spacing(N−1)·Δh + 0.5L385-387must exceed panel width (L390-392)

polarization_type → slant γ mapping (L422-436)

polarizationpolarization_typeγ (pol1)γ (pol2)Code lines
singleV0— (_ant_pol2=None, L428)L425
singleHπ/2—L425
dualVH0π/2L432, L435
dualcross−π/4+π/4 (=γ+π/2)L432, L435

Each polarization creates exactly one AntennaElement instance (L426-436); all elements share the same field model — the standard’s “identical elements” assumption.

Polarization unit vectors cosγ·θ̂+sinγ·φ̂ for the four polarization types: single V/H has one direction; dual VH is vertical+horizontal; dual cross is ±45°

Fig. 3: polarization_type → slant angle γ and polarization vectors (eqs. 7.3-4/5).

Array assembly and unit conversion (L439-464)

  1. per-panel translation: offset = [0, j·panel h-spacing, -i·panel v-spacing] (L446-453);
  2. whole array centered again (L456-459);
  3. L462: ant_pos *= λ0 — panel-internal units are wavelengths; the array output multiplies by the carrier wavelength to yield meters. channel_coefficients.py consumes these metric positions as d̄ directly.

PanelArray assembled from 2×2 panels (each 2×2 dual-pol elements) tiled in the y–z plane: dashed boxes are panels, Δh_p/Δv_p are panel spacings, polarization indices are panel-blocked

Fig. 4: PanelArray assembly and panel-blocked polarization indices (L446-470).

Polarization indices (L466-479)

ind = np.arange(0, num_ant).reshape(num_panels * p, -1)   # each row = one panel, one polarization block
ant_ind_pol1 = ind[::p].ravel()       # even rows = pol1 of every panel
ant_ind_pol2 = ind[1::2].ravel()      # odd rows  = pol2 of every panel

Example: 2 panels × (2×2 elements, dual), num_ant=16, reshaped to [4,4]:

ind = [[0,1,2,3], [4,5,6,7], [8,9,10,11], [12,13,14,15]]
ant_ind_pol1 = [0,1,2,3, 8,9,10,11]     # panel0-pol1 + panel1-pol1
ant_ind_pol2 = [4,5,6,7, 12,13,14,15]   # panel0-pol2 + panel1-pol2

Properties ant_pos_pol1/ant_pos_pol2 (L478-479) gather per-polarization positions for show() and external plotting. L481-592 are plain read-only properties (num_ant, ant_pol1/2, ant_pos, …) with no logic.

1.5 Antenna and AntennaArray (L633-754)

ClassLinesEquivalent PanelArray argumentsnum_ant
AntennaL633-685num_rows_per_panel=1, num_cols_per_panel=1, single panelsingle:1; dual:2
AntennaArrayL688-754one panel of num_rows×num_cols (no panel-level params)rows·cols·p

Both are pure __init__ forwarders (L676-685, L743-754) with no new logic. AntennaArray(num_rows=4, num_cols=4, polarization="dual") is the classic 32-element BS array.


2. channel_coefficients.py: topology and generator skeleton

2.1 Topology (L22-74): a “network snapshot” for synthesis

Topology is a plain data container (constructor L52-74) recording per-link geometry and motion:

FieldshapeMeaning
velocities[B, num_UT, 3]moving-end velocity vector v̄ [m/s]
moving_end“tx”/“rx”which end moves (selects the Doppler broadcast axis, §5.2)
los_aoa/los_aod/los_zoa/los_zod[B, num_BS, num_UT]the four specular angles of the LoS path (for 7.5-29)
los[B, num_BS, num_UT] boolwhether each link is LoS (for the final torch.where)
distance_3d[B, num_BS, num_UT]3-D distance d [m] (LoS propagation phase 2πd/λ0)
tx_orientations / rx_orientations[B, num_TX, 3] / [B, num_RX, 3]panel orientations (α,β,γ)=(bearing, downtilt, slant), feeding eq. 7.1-4

2.2 Constructor and pre-computed constants (L160-241)

MemberLinesValuePurpose
_lambda_0L172-174c/f_cwavelength, enters every phase term
_sub_cl_1/2/3_indL182-190[0-7,18,19]/[8-11,16,17]/[12-15]Table 7.5-5: 0-based ray indices of the three sub-clusters (the standard’s 1-based rays are 1-8,19,20 / 9-12,17,18 / 13-16)
_sub_cl_delay_offsetsL191-193[0, 1.28, 2.56]Table 7.5-5 sub-cluster relative-delay factors (×c_ds)
_v2_constL198-200[1, j, 0]complex trick for φ′ (§3.2)
_h_phase_los_constL201-203[[1,0],[0,−1]]deterministic LoS polarization matrix (eq. 7.5-29)
_v1_constL206-208[0, 0, 1]projection vector for θ′
_gather_ind_tx/rxL210-225one 0/1 per elementmaps each element to its pol1/pol2 response under dual polarization (static gather, CUDA-Graph friendly)

L227-241 are CUDA-Graph pre-allocation bookkeeping (used by allocate_for_batch_size L243-281 and the buffer reuse in _step_10); they carry no physics and can be skipped.

2.3 __call__ main flow (L282-317)

sample_times = torch.arange(num_time_samples) / sampling_frequency   # L296-305
phi = self._step_10(rays.aoa.shape, batch_size)                      # L308  Step 10
h, delays = self._step_11(phi, topology, k_factor, rays, sample_times, c_ds)  # L311  Step 11

With debug=True, phi and sample_times are returned as well (L314-315). The output h has shape [B, num_TX, num_RX, num_paths, num_RX_ant, num_TX_ant, num_samples] (docstring L125).


3. The §7.1 coordinate and polarization rotation toolkit

These utilities (L323-542) implement every coordinate transform of §7.1 and form the “mathematical substrate” of _step_11_field_matrix and _step_11_array_offsets:

FunctionLinesStandard formulaInput → output
_unit_sphere_vectorL323-342eq. 7.1-6(θ,φ) → ρ̂=[sinθcosφ, sinθsinφ, cosθ]ᵀ
_forward_rotation_matrixL344-382eq. 7.1-4orient[…,3] → R[…,3,3]
_rot_posL384-396—R·pos (LCS→GCS position)
_reverse_rotation_matrixL398-409inverse of 7.1-4Rᵀ (orthogonal ⇒ transpose is inverse, L408 mT)
_gcs_to_lcsL411-443eqs. 7.1-7/8GCS angles (θ,φ) → LCS angles (θ′,φ′)
_compute_psiL445-468eq. 7.1-15LCS→GCS polarization rotation angle ψ
_l2g_responseL470-492eq. 7.1-11f′ → f (field components LCS→GCS)
_step_11_get_tx/rx_antenna_positionsL494-517 / L519-542d̄ in eq. 7.5-22element LCS positions → GCS positions

GCS vs LCS: black = global coordinate system; purple = local frame after bearing α → downtilt β → slant γ rotations (panel parallel to the y′–z′ plane); red = ray direction ρ̂(θ,φ); orange/teal arcs = GCS spherical angles

Fig. 5: GCS ↔ LCS rotation and spherical angles (eqs. 7.1-4/6/7/8).

3.1 Rotation matrix (eq. 7.1-4, L344-382)

orientations = [α, β, γ] are three successive rotations: bearing (about z), downtilt (about the new y), slant (about the new x). L352-381 write out all nine entries of R(α,β,γ) explicitly, e.g. row_3 = [-sinβ, cosβ·sinγ, cosβ·cosγ], matching eq. 7.1-4 exactly.

3.2 GCS→LCS angles (eqs. 7.1-7/8, L411-443)

Build ρ̂ via 7.1-6, rotate ρ̂′ = Rᵀ·ρ̂ (L428-430), then:

θ′=arccos⁡(v1⋅ρ^′),ϕ′=arg⁡(v2⋅ρ^′)\theta'=\arccos(\mathbf{v}_1\cdot\hat{\rho}'),\qquad \phi'=\arg(\mathbf{v}_2\cdot\hat{\rho}')

Two tricks in L436-439:

  • θ′: dot with v1=[0,0,1] to extract the z component, clamp(-1,1) before acos (L437-438, numerical safety);
  • φ′: dot with the complex vector v2=[1,j,0] giving ρ̂′ₓ + j·ρ̂′ᵧ, so torch.angle returns atan2(ρ̂′ᵧ, ρ̂′ₓ) in one line — a single complex inner product replacing the quadrant-discussion formulas of 7.1-8.

3.3 Polarization rotation angle ψ (eq. 7.1-15, L445-468)

ψ is the angle between the LCS basis (θ̂′,φ̂′) and the GCS basis (θ̂,φ̂) in the common tangent plane. L462-467 compute psi = angle(real + j·imag) with:

Re=sin⁡γcos⁡θsin⁡(ϕ−α)+cos⁡γ(cos⁡βsin⁡θ−sin⁡βcos⁡θcos⁡(ϕ−α))\mathrm{Re}= \sin\gamma\cos\theta\sin(\phi-\alpha)+\cos\gamma\big(\cos\beta\sin\theta-\sin\beta\cos\theta\cos(\phi-\alpha)\big)

Im=sin⁡γcos⁡(ϕ−α)+sin⁡βcos⁡γsin⁡(ϕ−α)\mathrm{Im}= \sin\gamma\cos(\phi-\alpha)+\sin\beta\cos\gamma\sin(\phi-\alpha)

Sign-convention note: Sionna’s definition differs from the standard’s original expansion of e^{jψ} (g10 eq. 7.1-15) by an overall sign flip, but _compute_psi and the matrix orientation in _l2g_response are mutually consistent, so the resulting GCS field components match the standard. Full derivation in the companion post’s deep-dive group A.

3.4 LCS→GCS field components (eq. 7.1-11, L470-492)

[fθfϕ]=[cos⁡ψ−sin⁡ψsin⁡ψcos⁡ψ][fθ′fϕ′]\begin{bmatrix}f_\theta\\ f_\phi\end{bmatrix}=\begin{bmatrix}\cos\psi & -\sin\psi\\ \sin\psi & \cos\psi\end{bmatrix}\begin{bmatrix}f_{\theta'}\\ f_{\phi'}\end{bmatrix}

L487-491 implement it literally: build the 2×2 rotation from ψ and multiply f_prime.unsqueeze(-1), output shape [...,2,1].

3.5 Element positions d̄ (d̄_tx/d̄_rx of eq. 7.5-22, L494-542)

_step_11_get_tx/rx_antenna_positions simply computes d̄ = R(orient)·d_LCS (L505-513 / L530-538): rotating PanelArray.ant_pos (meters, LCS) into the GCS per TX/RX, output [B, num_TX, num_TX_ant, 3]. These are exactly the vectors needed for the r̂_tx·d̄_tx and r̂_rx·d̄_rx inner products in 7.5-22.


4. Step 10: four random initial phases (L544-577)

The standard draws, per ray n, four independent phases φ_{n,θθ}, φ_{n,θH}, φ_{n,Hθ}, φ_{n,HH} ∼ U(0, 2π).

The code (L560-575) uses phi = rand(*shape, 4) * 2π − π, i.e. U(−π, π) — equivalent modulo 2π since every phase only enters through exp(jφ). The last dimension is ordered [θθ, θH, Hθ, HH], matching the matrix positions in §5.1. L555-562 is the CUDA-Graph buffer-reuse branch (in-place uniform_()), mathematically the same draw.


5. Step 11: the four factors of eq. 7.5-22

The standard writes the per-ray NLoS channel matrix (compact form of 7.5-22/28):

h~n,m(t)=PnM  (f⃗rx ∗⋅Hpol f⃗tx)⋅ej2πλ0(r^rx⋅dˉrx+r^tx⋅dˉtx)⋅ej2πλ0 r^rx⋅vˉ t\tilde{h}_{n,m}(t)=\sqrt{\tfrac{P_n}{M}}\;\big(\vec{f}_{\mathrm{rx}}^{\,*}\cdot \mathbf{H}_{\mathrm{pol}}\,\vec{f}_{\mathrm{tx}}\big)\cdot e^{\mathrm{j}\frac{2\pi}{\lambda_0}(\hat{r}_{\mathrm{rx}}\cdot\bar{d}_{\mathrm{rx}}+\hat{r}_{\mathrm{tx}}\cdot\bar{d}_{\mathrm{tx}})}\cdot e^{\mathrm{j}\frac{2\pi}{\lambda_0}\,\hat{r}_{\mathrm{rx}}\cdot\bar{v}\,t}

Sionna computes the four factors in separate functions and multiplies them inside _step_11_nlos.

5.1 Polarization / phase / XPR matrix H_pol (L579-608)

Hpol=[ejϕθθ1XPRejϕθH1XPRejϕHθejϕHH]\mathbf{H}_{\mathrm{pol}}=\begin{bmatrix} e^{\mathrm{j}\phi_{\theta\theta}} & \tfrac{1}{\sqrt{\mathrm{XPR}}}e^{\mathrm{j}\phi_{\theta H}}\\[2pt] \tfrac{1}{\sqrt{\mathrm{XPR}}}e^{\mathrm{j}\phi_{H\theta}} & e^{\mathrm{j}\phi_{HH}} \end{bmatrix}

L594-606: xpr_scaling = sqrt(1/xpr) (rays.xpr is the linear power ratio, 10 dB → 10); e0/e3 are co-pol terms (unscaled), e1/e2 cross-pol terms; stack([e0,e1,e2,e3]).reshape(...,2,2) lays [θθ,θH,Hθ,HH] out in row-major 2×2 order. Output shape [...,num_clusters, num_rays, 2, 2].

5.2 Doppler matrix (L610-659, eq. 7.5-25)

hdoppler[n,m,t]=ej2πλ0(r^rx(n,m)⋅vˉ) th_{\mathrm{doppler}}[n,m,t]=e^{\mathrm{j}\frac{2\pi}{\lambda_0}(\hat{r}_{\mathrm{rx}}(n,m)\cdot\bar{v})\,t}

L651-656: r̂_rx = _unit_sphere_vector(zoa, aoa), inner product with v̄, times 2π/λ0·t. moving_end handling at L640-645: if rx moves, v̄ broadcasts along the TX axis (unsqueeze(1)); if tx moves, along the RX axis (unsqueeze(2)), so the velocity attaches only to the moving end’s dimension. Note that only arrival angles enter the Doppler — TX-side motion is folded into r̂_rx through the “which end moves” topology convention.

5.3 Array phase offsets (L661-723, exponent of eq. 7.5-22)

harray[n,m,r,s]=ej2πλ0r^rx⋅dˉrx,s⋅ej2πλ0r^tx⋅dˉtx,rh_{\mathrm{array}}[n,m,r,s]=e^{\mathrm{j}\frac{2\pi}{\lambda_0}\hat{r}_{\mathrm{rx}}\cdot\bar{d}_{\mathrm{rx},s}}\cdot e^{\mathrm{j}\frac{2\pi}{\lambda_0}\hat{r}_{\mathrm{tx}}\cdot\bar{d}_{\mathrm{tx},r}}

L687-690 gathers the four quantities: r̂_rx, r̂_tx (sphere vectors) and d̄_rx, d̄_tx (§3.5 GCS positions). L692-719 align the ray and antenna axes with a chain of unsqueezes into [B, TX, RX, clusters, rays, rx_ant, tx_ant, 1]-style broadcasting, then exp_rx * exp_tx (L721) forms the array factor. This step is the entire source of “MIMO array directivity”: the phase differences between antenna pairs for the same ray.

5.4 Element-response matrix (L725-839, eqs. 7.1-11 + 7.3-4/5 combined)

Computation chain (the f_rx*·H_pol·f_tx part of 7.5-22):

  1. angles into the LCS (L757-776): _gcs_to_lcs converts (zod,aod) and (zoa,aoa) into each panel’s local angles (θ′,φ′);
  2. element field + rotate back to GCS (L780-800): call AntennaElement.field(θ′,φ′) (7.3-4/5) for pol1 (and pol2 if dual), then _l2g_response (7.1-11) to get GCS field vectors f[...,2,1];
  3. multiply by H_pol (L803-809): pol_tx = h_phase @ f_tx (2×2 × 2×1 → 2×1); the RX field vector is not multiplied by H_pol (it acts on the TX side; the RX side only takes the dot product);
  4. assign per-element polarization responses (L811-830):
    • single: expand(num_ant, ...) — all elements share the pol1 response (L814, L824);
    • dual: stack([pol1,pol2],0) then a single gather with _gather_ind_tx/rx; each element picks its own polarization’s response following the panel-blocked storage of §1.4 (L818-819, L829-830);
  5. dot product and transpose (L834-837): h_field = (f_rx_array.unsqueeze(1) * f_tx_array.unsqueeze(0)).sum(dim=(-2,-1)) sums over the (θ,φ) components = spherical-basis inner product f_rx·f_tx, then permute moves the antenna axes to the end, output [B, TX, RX, clusters, rays, rx_ant, tx_ant].

The companion post’s deep-dive groups B/C discuss F_rx/F_tx versus LCS/GCS and the sign differences of the ±45° antennas inside the dot product; the derivation is not repeated here.


6. Step 11 (NLoS): per-ray synthesis and sub-clustering

6.1 Per-ray full matrix (L841-876, eq. 7.5-28)

h_full = (h_field * h_array).unsqueeze(-1) * h_doppler.unsqueeze(-2).unsqueeze(-2)  # L865
power_scaling = sqrt(rays.powers / h_full.shape[4])                                  # L867-874
h_full = h_full * power_scaling

The four factors multiply; shape[4] is the ray count M: each ray gets power P_n/M, square-rooted into the amplitude — exactly the √(P_n/M) of 7.5-22/28. Output h_full: [B, TX, RX, clusters, rays, rx_ant, tx_ant, T].

6.2 Ray summation and sub-clustering (L878-957, eq. 7.5-27 + Table 7.5-5)

subclustering=False (CDL): plain h_full.sum(dim=4) (L945) — the M rays of a cluster add coherently; delays stay rays.delays.

subclustering=True (UMa/UMi/RMa): the standard’s split is executed:

  1. argsort clusters by descending power (L903), take the two strongest (L909, L920);
  2. each strong cluster’s 20 rays are split into 3 sub-clusters by the Table 7.5-5 indices: h_strong[..., _sub_cl_1_ind, ...].sum(dim=4) (L933-935); sub-cluster delay = original cluster delay + [0, 1.28, 2.56] × c_ds (L913-917);
  3. all remaining weak clusters are summed whole (L938);
  4. concat strong and weak paths (L941-942): path groups go from N clusters to N+4;
  5. everything is re-sorted by ascending delay (L949-955).

Unit trap: the __call__ docstring (L113) says c_ds is in ns, but the caller system_level_channel.py L295 already converts with get_param("cDS") * 1e-9 to seconds before passing it in, so it adds directly to rays.delays (seconds). Trust the caller, not the docstring.

Numeric example: strongest cluster delay 100 ns with c_ds=10 ns gives sub-cluster delays 100, 112.8, 125.6 ns.


7. Step 11 (LoS): the deterministic specular component (L959-1008, eq. 7.5-29)

The LoS component is non-random: angles come from topology.los_* (L971-980), the polarization matrix is the constant [[1,0],[0,−1]] (L983 — co-pol 1, cross-pol 0, HH carries a minus sign, per the deterministic matrix of 7.5-29), then §5.3/5.4/5.2 are reused for field, array and Doppler factors (L984-990), and the propagation phase is applied (L993-999):

hlos=(f⃗rx⋅Hlos f⃗tx)⋅ej2πλ0(r^rx⋅dˉrx+r^tx⋅dˉtx)⋅ej2πλ0r^rx⋅vˉt⋅ej2πλ0d3Dh_{\mathrm{los}} = \big(\vec{f}_{\mathrm{rx}}\cdot \mathbf{H}_{\mathrm{los}}\,\vec{f}_{\mathrm{tx}}\big)\cdot e^{\mathrm{j}\frac{2\pi}{\lambda_0}(\hat{r}_{\mathrm{rx}}\cdot\bar{d}_{\mathrm{rx}}+\hat{r}_{\mathrm{tx}}\cdot\bar{d}_{\mathrm{tx}})}\cdot e^{\mathrm{j}\frac{2\pi}{\lambda_0}\hat{r}_{\mathrm{rx}}\cdot\bar{v}t}\cdot e^{\mathrm{j}\frac{2\pi}{\lambda_0}d_{3D}}

The last factor exp(j2π·d3d/λ0) is the LoS-only absolute propagation phase (NLoS clusters carry their equivalent inside rays.delays; the LoS path’s delay is defined as 0, so it is added explicitly). The LoS matrix has no √(P/M) scaling — its power is allocated entirely by the K-factor in §8. Output shape [B, TX, RX, 1, rx_ant, tx_ant, T] (single path).


h(t)={KK+1 hlos(t)+1K+1 hnlos(t),LoS linkhnlos(t),NLoS linkh(t)=\begin{cases}\sqrt{\tfrac{K}{K+1}}\,h_{\mathrm{los}}(t)+\sqrt{\tfrac{1}{K+1}}\,h_{\mathrm{nlos}}(t), & \text{LoS link}\\[3pt] h_{\mathrm{nlos}}(t), & \text{NLoS link}\end{cases}

Line-by-line correspondence (L1047-1058):

LinesCodeRole
L1047h_los_los_comp *= sqrt(K/(K+1))weight the LoS component
L1048h_los_nlos_comp = h_nlos * sqrt(1/(K+1))weight the NLoS component on LoS links
L1051h_los_cl = h_los_los_comp + h_los_nlos_comp[:,:,:,0:1,...]fold LoS into the zero-delay (first, after sorting) path group
L1054h_los = cat([h_los_cl, h_los_nlos_comp[:,:,:,1:,...]], 3)reassemble the full path axis
L1057-1058h = torch.where(los_indicator, h_los, h_nlos)per-link selection

Two notes:

  • pure NLoS links output the unscaled h_nlos (as in the standard: the K-factor belongs only to LoS links);
  • the returned delays is always delays_nlos (L1060) — on a LoS link the first delay corresponds to the path group carrying the LoS component.

9. Tensor shape data-flow overview

With B=batch, C=clusters, M=rays per cluster, A_tx/A_rx=element counts, T=time samples:

Variableshapeproduced byconsumed by
rays.aoa/aod/zoa/zod[B,TX,RX,C,M]Raysall of §5
rays.powers/delays[B,TX,RX,C]Rays§6
phi (Step 10)[B,TX,RX,C,M,4]L544L579
h_phase[B,TX,RX,C,M,2,2]L579L725/L983
f_*_pol1/2 (GCS fields)[B,TX,RX,C,M,2,1]L780-800L803-830
h_field[B,TX,RX,C,M,A_rx,A_tx]L725L865
h_array[B,TX,RX,C,M,A_rx,A_tx]L661L865
h_doppler[B,TX,RX,C,M,T]L610L865
h_full (7.5-28)[B,TX,RX,C,M,A_rx,A_tx,T]L841L878
h_nlos (7.5-27)[B,TX,RX,C′,A_rx,A_tx,T], C′=C+4 (subclustering) or CL878L1048
h_los (7.5-29)[B,TX,RX,1,A_rx,A_tx,T]L959L1051
output h (7.5-30)[B,TX,RX,P,A_rx,A_tx,T], P=C′L1010upper-layer CIR assembly

10. Runnable numerical examples

import torch
from sionna.phy.channel.tr38901 import PanelArray, AntennaElement

# 1) 38.901 element, -45° slant, boresight field components
ant = AntennaElement("38.901", slant_angle=-torch.pi / 4)
f_t, f_p = ant.field(torch.tensor([torch.pi / 2]), torch.tensor([0.0]))
# A'=8 dBi -> linear 6.3096 -> a=2.5119
# f_t = 2.5119*cos(-45°) ≈ 1.7761,  f_p ≈ -1.7761

# 2) two-panel cross-polarized array: 16 elements, blocked polarization indices
arr = PanelArray(num_rows_per_panel=2, num_cols_per_panel=2,
                 polarization="dual", polarization_type="cross",
                 antenna_pattern="38.901", carrier_frequency=3.5e9,
                 num_cols=2, panel_horizontal_spacing=3.0)
print(arr.num_ant)           # 16
print(arr.ant_ind_pol1)      # tensor([0,1,2,3,8,9,10,11])
print(arr.ant_ind_pol2)      # tensor([4,5,6,7,12,13,14,15])
# positions are in meters: at 3.5 GHz λ0≈0.0857 m, so the 0.5λ element
# spacing is 0.0429 m in practice (conversion at L462)

# 3) Doppler phase rate: v=10 m/s radial, f_c=3.5 GHz
# 2π·v/λ0 = 2π·10/0.0857 ≈ 733.6 rad/s
# at a 1 MHz sampling frequency: ≈ 7.34e-4 rad per sample

11. FAQ

Q1: Why U(−π,π) instead of the standard’s U(0,2π)? Phases only enter as exp(jφ), so both distributions are statistically identical modulo 2π; mapping uniform_()’s [0,1) linearly onto (−π,π] is the natural implementation (L560-561).

Q2: Why divide by √M (M = ray count)? The standard spreads cluster power P_n evenly over M rays (the √(P_n/M) in 7.5-22), so that summing the rays restores exactly P_n. h_full.shape[4] is the ray axis (L868).

Q3: What problem do _gather_ind_tx/rx solve? In a dual array each element must select the pol1 or pol2 response. A per-element if would break CUDA Graph / torch.compile static graphs; a precomputed 0/1 index tensor lets one pol_tx[_gather_ind_tx] gather do it (L818-819), with indices built at construction time following the panel-blocked storage of §1.4 (L210-225).

Q4: What is v2=[1,j,0] for? Dotting the rotated sphere vector ρ̂′ with the complex vector yields ρ̂′ₓ + jρ̂′ᵧ, and angle() is the azimuth φ′ — one line replacing the quadrant-case analysis of eq. 7.1-8 (L434, L439).

Q5: Why is the LoS polarization matrix [[1,0],[0,−1]]? Eq. 7.5-29 prescribes no random initial phase and no cross-polarization leakage on the LoS path: co-pol coefficients 1 and −1 (HH flipped in sign relative to θθ), cross terms 0. The code registers it as a constant (L201-203) and reshapes it in _step_11_los (L983).

Q6: Is c_ds in ns or seconds? The docstring says ns (L113), but the caller converts to seconds with ×1e-9 before passing (system_level_channel.py L295), and _step_11_reduce_nlos adds it to the seconds-based rays.delays (L917) — units are consistent if you trust the caller.

Q7: How does the path count change after sub-clustering? UMa/UMi: 17 clusters per link → the 2 strongest each split into 3 sub-clusters (2×3=6) + the other 15 unchanged = 21 path groups; CDL does not split, so paths = clusters. Everything is output sorted by ascending delay (L949-955).


12. Further reading

Comments

Loading comments…

    ← Back to home