Contents
- 0. Where the two files sit in 38.901
- 1. antenna.py: three-tier antenna modeling (§7.3)
- 1.1 Class hierarchy overview
- 1.2 AntennaElement (L18-183): element pattern and polarization
- 1.3 AntennaPanel (L186-290): panel geometry
- 1.4 PanelArray (L293-630): panel array and polarization types
- 1.5 Antenna and AntennaArray (L633-754)
- 2. channel_coefficients.py: topology and generator skeleton
- 2.1 Topology (L22-74): a “network snapshot” for synthesis
- 2.2 Constructor and pre-computed constants (L160-241)
- 2.3 __call__ main flow (L282-317)
- 3. The §7.1 coordinate and polarization rotation toolkit
- 3.1 Rotation matrix (eq. 7.1-4, L344-382)
- 3.2 GCS→LCS angles (eqs. 7.1-7/8, L411-443)
- 3.3 Polarization rotation angle ψ (eq. 7.1-15, L445-468)
- 3.4 LCS→GCS field components (eq. 7.1-11, L470-492)
- 3.5 Element positions d̄ (d̄_tx/d̄_rx of eq. 7.5-22, L494-542)
- 4. Step 10: four random initial phases (L544-577)
- 5. Step 11: the four factors of eq. 7.5-22
- 5.1 Polarization / phase / XPR matrix H_pol (L579-608)
- 5.2 Doppler matrix (L610-659, eq. 7.5-25)
- 5.3 Array phase offsets (L661-723, exponent of eq. 7.5-22)
- 5.4 Element-response matrix (L725-839, eqs. 7.1-11 + 7.3-4/5 combined)
- 6. Step 11 (NLoS): per-ray synthesis and sub-clustering
- 6.1 Per-ray full matrix (L841-876, eq. 7.5-28)
- 6.2 Ray summation and sub-clustering (L878-957, eq. 7.5-27 + Table 7.5-5)
- 7. Step 11 (LoS): the deterministic specular component (L959-1008, eq. 7.5-29)
- 8. Step 11 (combination): K-factor weighting and link selection (L1010-1062, eq. 7.5-30)
- 9. Tensor shape data-flow overview
- 10. Runnable numerical examples
- 11. FAQ
- 12. Further reading
Sionna Source Code Explained: antenna.py and channel_coefficients.py Function-by-Function Against 3GPP 38.901
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
| File | Lines | TR 38.901 clauses | Responsibility |
|---|---|---|---|
antenna.py | 755 | §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.py | 1062 | §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
| Class | Lines | Standard | One-line role |
|---|---|---|---|
AntennaElement | L18-183 | §7.3 eqs. 7.3-1/2/4/5, Table 7.3-1 | One element: pattern + slant angle γ → field components (f_θ, f_φ) |
AntennaPanel | L186-290 | §7.3 panel geometry | Positions of M×N elements within a panel (in wavelengths) |
PanelArray | L293-630 | §7.3 array | Assembles panels into a full array, converts positions to meters |
Antenna | L633-685 | — | PanelArray special case: 1×1 element, single panel |
AntennaArray | L688-754 | — | PanelArray special case: one panel of num_rows×num_cols elements |
1.2 AntennaElement (L18-183): element pattern and polarization
Member mapping table
| Member | Lines | Standard | What 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-86 | eqs. 7.3-4/5 | Returns field pattern (f_θ, f_φ) |
show() | L88-135 | — | Plots vertical/horizontal cuts and the 3D power pattern |
_radiation_pattern_omni | L137-143 | — | Omnidirectional: constant 1 |
_radiation_pattern_38901 | L145-160 | eqs. 7.3-1/2 + Table 7.3-1 | Returns the linear power pattern 10^(A'/10) |
_compute_gain() | L162-183 | §7.3 gain definition | Numerical 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):
The code maps line by line (L151-160):
| Code line | Variable | Table 7.3-1 value | Meaning |
|---|---|---|---|
| L151 | theta_3db = phi_3db = 65° | θ_3dB = φ_3dB = 65° | 3-dB beamwidth |
| L152 | a_max = sla_v = 30.0 | A_m = SLA_v = 30 dB | Side-lobe attenuation cap |
| L153 | g_e_max = 8.0 | G_Emax = 8 dBi | Max gain |
| L154-155 | a_v = -min(12((θ-π/2)/θ_3dB)², 30) | first term of 7.3-1 | vertical cut |
| L156-157 | a_h = -min(12(φ/φ_3dB)², 30) | second term of 7.3-1 | horizontal cut |
| L158-159 | a_db = -min(-(a_v+a_h), 30) + 8 | eq. 7.3-2 | combined, capped |
| L160 | return 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 γ:
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).
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):
| Axis | Orientation | Role in the formulas |
|---|---|---|
| x′ | panel normal, pointing at the boresight | main-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).
| Step | Lines | Content |
|---|---|---|
| polarization check | L213-214 | polarization ∈ {"single","dual"} |
| first polarization | L227-231 | ant_pos[i + j·num_rows] = [0, j·Δh, -i·Δv]: i is the row index (along −z), j the column index (along +y) |
| centering | L234-237 | shift by offset = [0, -(N-1)Δh/2, (M-1)Δv/2] so the panel is centered at the origin |
| second polarization copy | L240-241 | for 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.
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)
| Parameter | Default | Lines | Constraint |
|---|---|---|---|
element_vertical/horizontal_spacing | 0.5 λ0 | L377-380 | — |
panel_vertical_spacing | (M−1)·Δv + 0.5 | L382-384 | must exceed panel height (L393-395) |
panel_horizontal_spacing | (N−1)·Δh + 0.5 | L385-387 | must exceed panel width (L390-392) |
polarization_type → slant γ mapping (L422-436)
polarization | polarization_type | γ (pol1) | γ (pol2) | Code lines |
|---|---|---|---|---|
| single | V | 0 | — (_ant_pol2=None, L428) | L425 |
| single | H | π/2 | — | L425 |
| dual | VH | 0 | π/2 | L432, L435 |
| dual | cross | −π/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.
Fig. 3: polarization_type → slant angle γ and polarization vectors (eqs. 7.3-4/5).
Array assembly and unit conversion (L439-464)
- per-panel translation:
offset = [0, j·panel h-spacing, -i·panel v-spacing](L446-453); - whole array centered again (L456-459);
- L462:
ant_pos *= λ0— panel-internal units are wavelengths; the array output multiplies by the carrier wavelength to yield meters.channel_coefficients.pyconsumes these metric positions asd̄directly.
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)
| Class | Lines | Equivalent PanelArray arguments | num_ant |
|---|---|---|---|
Antenna | L633-685 | num_rows_per_panel=1, num_cols_per_panel=1, single panel | single:1; dual:2 |
AntennaArray | L688-754 | one 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:
| Field | shape | Meaning |
|---|---|---|
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] bool | whether 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)
| Member | Lines | Value | Purpose |
|---|---|---|---|
_lambda_0 | L172-174 | c/f_c | wavelength, enters every phase term |
_sub_cl_1/2/3_ind | L182-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_offsets | L191-193 | [0, 1.28, 2.56] | Table 7.5-5 sub-cluster relative-delay factors (×c_ds) |
_v2_const | L198-200 | [1, j, 0] | complex trick for φ′ (§3.2) |
_h_phase_los_const | L201-203 | [[1,0],[0,−1]] | deterministic LoS polarization matrix (eq. 7.5-29) |
_v1_const | L206-208 | [0, 0, 1] | projection vector for θ′ |
_gather_ind_tx/rx | L210-225 | one 0/1 per element | maps 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:
| Function | Lines | Standard formula | Input → output |
|---|---|---|---|
_unit_sphere_vector | L323-342 | eq. 7.1-6 | (θ,φ) → ρ̂=[sinθcosφ, sinθsinφ, cosθ]ᵀ |
_forward_rotation_matrix | L344-382 | eq. 7.1-4 | orient[…,3] → R[…,3,3] |
_rot_pos | L384-396 | — | R·pos (LCS→GCS position) |
_reverse_rotation_matrix | L398-409 | inverse of 7.1-4 | Rᵀ (orthogonal ⇒ transpose is inverse, L408 mT) |
_gcs_to_lcs | L411-443 | eqs. 7.1-7/8 | GCS angles (θ,φ) → LCS angles (θ′,φ′) |
_compute_psi | L445-468 | eq. 7.1-15 | LCS→GCS polarization rotation angle ψ |
_l2g_response | L470-492 | eq. 7.1-11 | f′ → f (field components LCS→GCS) |
_step_11_get_tx/rx_antenna_positions | L494-517 / L519-542 | d̄ in eq. 7.5-22 | element LCS positions → GCS positions |
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:
Two tricks in L436-439:
- θ′: dot with
v1=[0,0,1]to extract the z component,clamp(-1,1)beforeacos(L437-438, numerical safety); - φ′: dot with the complex vector
v2=[1,j,0]giving ρ̂′ₓ + j·ρ̂′ᵧ, sotorch.anglereturns 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:
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_psiand the matrix orientation in_l2g_responseare 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)
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):
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)
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)
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)
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):
- angles into the LCS (L757-776):
_gcs_to_lcsconverts (zod,aod) and (zoa,aoa) into each panel’s local angles(θ′,φ′); - 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 vectorsf[...,2,1]; - 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); - 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);
- single:
- 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 productf_rx·f_tx, thenpermutemoves 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:
argsortclusters by descending power (L903), take the two strongest (L909, L920);- 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); - all remaining weak clusters are summed whole (L938);
concatstrong and weak paths (L941-942): path groups go from N clusters to N+4;- everything is re-sorted by ascending delay (L949-955).
Unit trap: the
__call__docstring (L113) saysc_dsis in ns, but the callersystem_level_channel.pyL295 already converts withget_param("cDS") * 1e-9to seconds before passing it in, so it adds directly torays.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):
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).
8. Step 11 (combination): K-factor weighting and link selection (L1010-1062, eq. 7.5-30)
Line-by-line correspondence (L1047-1058):
| Lines | Code | Role |
|---|---|---|
| L1047 | h_los_los_comp *= sqrt(K/(K+1)) | weight the LoS component |
| L1048 | h_los_nlos_comp = h_nlos * sqrt(1/(K+1)) | weight the NLoS component on LoS links |
| L1051 | h_los_cl = h_los_los_comp + h_los_nlos_comp[:,:,:,0:1,...] | fold LoS into the zero-delay (first, after sorting) path group |
| L1054 | h_los = cat([h_los_cl, h_los_nlos_comp[:,:,:,1:,...]], 3) | reassemble the full path axis |
| L1057-1058 | h = 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
delaysis alwaysdelays_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:
| Variable | shape | produced by | consumed by |
|---|---|---|---|
rays.aoa/aod/zoa/zod | [B,TX,RX,C,M] | Rays | all of §5 |
rays.powers/delays | [B,TX,RX,C] | Rays | §6 |
phi (Step 10) | [B,TX,RX,C,M,4] | L544 | L579 |
h_phase | [B,TX,RX,C,M,2,2] | L579 | L725/L983 |
f_*_pol1/2 (GCS fields) | [B,TX,RX,C,M,2,1] | L780-800 | L803-830 |
h_field | [B,TX,RX,C,M,A_rx,A_tx] | L725 | L865 |
h_array | [B,TX,RX,C,M,A_rx,A_tx] | L661 | L865 |
h_doppler | [B,TX,RX,C,M,T] | L610 | L865 |
h_full (7.5-28) | [B,TX,RX,C,M,A_rx,A_tx,T] | L841 | L878 |
h_nlos (7.5-27) | [B,TX,RX,C′,A_rx,A_tx,T], C′=C+4 (subclustering) or C | L878 | L1048 |
h_los (7.5-29) | [B,TX,RX,1,A_rx,A_tx,T] | L959 | L1051 |
output h (7.5-30) | [B,TX,RX,P,A_rx,A_tx,T], P=C′ | L1010 | upper-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
- 38.901 §7.5 Twelve-Step Channel Generation: Complete Guide to Framework, Computation, and Sionna Source Code: the full twelve-step flow, the term-by-term derivation of eq. 7.5-22, the ψ / F_rx / F_tx deep dive and the ±45° comparison table.
- 3GPP TR 38.901 g10: §7.1 (coordinate and polarization conventions), §7.3 (antenna model), §7.5 (fast fading generation).
- Source:
src/sionna/phy/channel/tr38901/antenna.py,channel_coefficients.py.
Comments
Loading comments…
Want to leave a note? Sign in first — comments are open to every signed-in reader.