Algorithm Search⌘K

Algorithmadvanced

Zheng and Xiao fading simulator

Also called improved sum-of-sinusoids simulator.

A sum of M sinusoids with random arrival angles and phases. Its autocorrelation is exactly Omega J0(2 pi f_D tau) for any M; a phase per sinusoid also fixes the higher-order statistics.

Time
O(M T) worst
Space
O(M) extra
Where
M = the number of sinusoids; T = the number of output samples
Properties
exact second order statisticsgaussian only as m growsrandomizedwide sense stationary
Origin
Yahong Rosa Zheng, Chengshan Xiao, 2002

The Zheng-Xiao simulator is a random generator of a fading gain h(t)h(t) for Clarke's model: it adds MM sinusoids whose arrival angles, gains and phases are drawn at random, once per channel. Clarke's model is the target, the autocorrelation ΩJ0(2πfDτ)\Omega J_0(2\pi f_D\tau); the Jakes simulator approximates it with fixed angles and is deterministic, while this simulator matches the second-order statistics of Clarke's model exactly, for any MM, as an average over its random parameters. The filtered Gaussian noise simulator is the other common generator, a Gaussian process by construction. The 2003 form shares one phase among all sinusoids; Xiao, Zheng and Beaulieu (2006) showed that this form is not Gaussian over short times and use a phase per sinusoid, which is the form given here.

In plain words

Picture the receiver of Clarke's model, with waves arriving from all directions. The Jakes simulator puts a fixed ring of waves around the receiver. This simulator spins the ring by a random angle, gives each wave a random strength split between the real and imaginary parts, and starts each wave at a random point of its cycle. One draw of these random numbers gives one fading channel. A new draw gives a new, independent channel. Because the spin covers every angle, the average correlation over many channels is exactly the one Clarke's model asks for, even with only a few waves. With few waves, one channel still looks less random than real fading.

The problem

The input is the maximum Doppler shift fDf_D, the mean power Ω\Omega, the number of sinusoids MM, a source of random numbers, and TT times tt. The output is one random realization h(t)=2Ω/M (Xc(t)+jXs(t))h(t) = \sqrt{2\Omega/M}\,(X_c(t) + j X_s(t)) at the given times. The goal is a process whose ensemble statistics match Clarke's model: E∣h∣2=ΩE|h|^2 = \Omega, E[h(t+τ)h(t)‾]=ΩJ0(2πfDτ)E[h(t+\tau)\overline{h(t)}] = \Omega J_0(2\pi f_D \tau), quadratures with equal autocorrelation and zero cross-correlation, and a distribution close to circular complex Gaussian, so that the envelope is Rayleigh. The model is flat time-correlated fading; the simulator gives the channel only, and the receiver's CSIR or CSIT is set by the simulation that uses it.

The algorithm

  1. ZHENG-XIAO(M, f_D, Ω, t, rng)
  2. 1θ ← uniform on [-π, π)
  3. 2ψₙ ← uniform on [-π, π) for n = 1 .. M ▷ independent
  4. 3φₙ ← uniform on [-π, π) for n = 1 .. M ▷ one phase per sinusoid (2006)
  5. 4αₙ ← (2πn - π + θ) / (4M) for n = 1 .. M
  6. 5X_c ← Σₙ cos ψₙ cos(2π f_D t cos αₙ + φₙ); X_s ← Σₙ sin ψₙ cos(2π f_D t cos αₙ + φₙ)
  7. 6return √(2Ω/M) (X_c + j X_s)

Lines L1 to L4 are drawn once per channel and then kept for all times tt. Line L4 places the MM angles at equal steps π/(2M)\pi/(2M) inside [0,π/2][0, \pi/2], shifted together by the random θ\theta. Only a quarter circle is needed, because waves at α\alpha, −α-\alpha, π−α\pi - \alpha and π+α\pi + \alpha give the same Doppler frequency up to sign. Line L2 gives each sinusoid a random gain angle, which splits it between the two quadratures. Line L3 gives it a random Doppler phase. In eq. (14) of Zheng and Xiao (2003), line L3 is a single phase ϕ\phi shared by all nn; the per-sinusoid phases are the 2006 correction. Line L6 scales the sum so that E∣h∣2=ΩE|h|^2 = \Omega.

Example

Take M=8M = 8 and fD=1f_D = 1. Line L4 gives eight angles spaced by π/16=11.25\pi/16 = 11.25 degrees; for θ=0\theta = 0 they are 5.6, 16.9, 28.1, 39.4, 50.6, 61.9, 73.1 and 84.4 degrees, and the Doppler frequencies are cos⁡αn\cos\alpha_n, from 0.995 down to 0.098.

The ensemble autocorrelation, averaged over θ\theta alone with the other parameters averaged out, is 1M∑nEθcos⁡(xcos⁡αn)\frac{1}{M}\sum_n E_\theta \cos(x\cos\alpha_n) with x=2πfDτx = 2\pi f_D\tau. A numerical integral over θ\theta matches J0(x)J_0(x) within 10−910^{-9} at fDτ=0.1f_D\tau = 0.1, 0.38274, 1, 3 and 10, for M=1M = 1, 2 and 8. Compare the Jakes simulator with M=8M = 8, whose time-average autocorrelation at fDτ=10f_D\tau = 10 is -0.049 instead of J0=0.071J_0 = 0.071.

The fourth moment shows the 2006 correction. A Rayleigh gain has E∣h∣4=2Ω2E|h|^4 = 2\Omega^2.

version E∣h(0)∣4/Ω2E\lvert h(0) \rvert^4/\Omega^2, formula M=8M = 8 mean of 12000 draws
a phase per sinusoid (2006) 2−1/(2M)2 - 1/(2M) 1.9375 1.939
one common phase (2003) 3−3/(2M)3 - 3/(2M) 2.8125 2.808

With one common phase, at t=0t = 0 every sinusoid has the same phase, so h(0)=cos⁡ϕ⋅2Ω/M∑nejψnh(0) = \cos\phi \cdot \sqrt{2\Omega/M}\sum_n e^{j\psi_n}, a Gaussian-like sum times a common random factor. Its distribution is far from Rayleigh for any MM; as tt grows the Doppler terms spread the phases apart, so the statistics depend on tt.

Correctness

Claim. For any M≥1M \ge 1, with independent uniform θ\theta and ψn\psi_n, and phases that are independent of θ\theta and ψ\psi (either one per sinusoid or shared): E[h(t+τ)h(t)‾]=ΩJ0(2πfDτ)E[h(t+\tau)\overline{h(t)}] = \Omega J_0(2\pi f_D\tau); the quadratures each have the autocorrelation Ω2J0(2πfDτ)\frac{\Omega}{2} J_0(2\pi f_D \tau); and their cross-correlation is 0. With a phase per sinusoid, the MM terms are independent given θ\theta, so h(t)h(t) tends to a circular complex Gaussian as MM grows, by the central limit theorem, and E∣h∣4/Ω2=2−1/(2M)E|h|^4/\Omega^2 = 2 - 1/(2M).

Key step. The random ψn\psi_n cancel all cross terms between different sinusoids and leave 1M∑nEcos⁡(xcos⁡αn)\frac{1}{M}\sum_n E \cos(x\cos\alpha_n). As θ\theta runs over [−π,π)[-\pi, \pi), αn\alpha_n runs over an interval of length π/(2M)\pi/(2M), and the MM intervals tile [0,π/2][0, \pi/2]. So the average is 2π∫0π/2cos⁡(xcos⁡α) dα=J0(x)\frac{2}{\pi}\int_0^{\pi/2} \cos(x\cos\alpha)\, d\alpha = J_0(x). The second-order part is Theorem 1 of Zheng and Xiao (2003). The proof file gives the full argument and derives both fourth moments.

Proof: The Zheng-Xiao simulator has the autocorrelation of Clarke's model for every M, and its fourth moment depends on how the phases are drawnfull

Write w=2πfDw = 2\pi f_D, x=wτx = w\tau, αn=(2πn−π+θ)/(4M)\alpha_n = (2\pi n - \pi + \theta)/(4M) and Φn(t)=wtcos⁡αn+ϕn\Phi_n(t) = w t \cos\alpha_n + \phi_n, where θ\theta, ψ1,…,ψM\psi_1, \ldots, \psi_M and the phases are independent and uniform on [−π,π)[-\pi, \pi). In the per-sinusoid form the ϕn\phi_n are independent; in the common form ϕn=ϕ\phi_n = \phi for all nn. The output is

h(t)=2Ω/M S(t),S(t)=∑n=1Mejψncos⁡Φn(t),h(t) = \sqrt{2\Omega/M}\, S(t), \qquad S(t) = \sum_{n=1}^{M} e^{j\psi_n} \cos\Phi_n(t),

so that Xc=Re⁡SX_c = \operatorname{Re} S and Xs=Im⁡SX_s = \operatorname{Im} S.

Lemma 1 (phase averages). For a uniform ψ\psi, Eejψ=Ee2jψ=0E e^{j\psi} = E e^{2j\psi} = 0, Ecos⁡2ψ=Esin⁡2ψ=12E\cos^2\psi = E\sin^2\psi = \frac12 and Ecos⁡ψsin⁡ψ=0E \cos\psi \sin\psi = 0. For a uniform ϕ\phi and constants A,BA, B, E[cos⁡(A+ϕ)cos⁡(B+ϕ)]=12cos⁡(A−B)E[\cos(A + \phi)\cos(B + \phi)] = \frac12 \cos(A - B), Ecos⁡2ϕ=12E\cos^2\phi = \frac12 and Ecos⁡4ϕ=38E\cos^4\phi = \frac38.

Proof. Each is the average of a trigonometric polynomial over a full period: write cos⁡(A+ϕ)cos⁡(B+ϕ)=12[cos⁡(A−B)+cos⁡(A+B+2ϕ)]\cos(A+\phi)\cos(B+\phi) = \frac12[\cos(A - B) + \cos(A + B + 2\phi)] and cos⁡4ϕ=38+12cos⁡2ϕ+18cos⁡4ϕ\cos^4\phi = \frac38 + \frac12\cos 2\phi + \frac18 \cos 4\phi, and drop the terms with a nonzero multiple of the variable. □\square

Lemma 2 (the angle average). For every real xx, 1M∑n=1MEθcos⁡(xcos⁡αn)=J0(x)\frac1M\sum_{n=1}^{M} E_\theta \cos(x\cos\alpha_n) = J_0(x).

Proof. As θ\theta runs uniformly over [−π,π)[-\pi, \pi), αn\alpha_n runs uniformly over In=[(n−1)π/(2M),nπ/(2M))I_n = [(n-1)\pi/(2M), n\pi/(2M)) with density 2M/π2M/\pi. The intervals I1,…,IMI_1, \ldots, I_M are disjoint and their union is [0,π/2)[0, \pi/2). So the left side is 1M⋅2Mπ∫0π/2cos⁡(xcos⁡α) dα=2π∫0π/2cos⁡(xcos⁡α) dα\frac1M \cdot \frac{2M}{\pi} \int_0^{\pi/2} \cos(x\cos\alpha)\, d\alpha = \frac{2}{\pi}\int_0^{\pi/2}\cos(x\cos\alpha)\, d\alpha. Bessel's integral is J0(x)=1π∫0πcos⁡(xcos⁡α) dαJ_0(x) = \frac1\pi \int_0^\pi \cos(x\cos\alpha)\, d\alpha, and the substitution α→π−α\alpha \to \pi - \alpha shows that the halves [0,π/2][0, \pi/2] and [π/2,π][\pi/2, \pi] give equal parts. □\square

Theorem 1 (second order). In both forms, for all tt and τ\tau,

E[Xc(t+τ)Xc(t)]=E[Xs(t+τ)Xs(t)]=M4J0(x),E[Xc(t+τ)Xs(t)]=0,E[X_c(t+\tau)X_c(t)] = E[X_s(t+\tau)X_s(t)] = \tfrac{M}{4} J_0(x), \qquad E[X_c(t+\tau)X_s(t)] = 0,

so E[h(t+τ)h(t)‾]=ΩJ0(x)E[h(t+\tau)\overline{h(t)}] = \Omega J_0(x), and each quadrature of hh has autocorrelation Ω2J0(x)\frac\Omega2 J_0(x).

Proof. E[Xc(t+τ)Xc(t)]=∑n,mE[cos⁡ψncos⁡ψm] E[cos⁡Φn(t+τ)cos⁡Φm(t)]E[X_c(t+\tau)X_c(t)] = \sum_{n,m} E[\cos\psi_n\cos\psi_m]\, E[\cos\Phi_n(t+\tau)\cos\Phi_m(t)], because the ψ\psi are independent of θ\theta and of the phases. For n≠mn \ne m, E[cos⁡ψncos⁡ψm]=(Ecos⁡ψ)2=0E[\cos\psi_n\cos\psi_m] = (E\cos\psi)^2 = 0. For n=mn = m, Lemma 1 gives 12\frac12 for the first factor, and, conditional on θ\theta, 12cos⁡(wτcos⁡αn)\frac12\cos(w\tau\cos\alpha_n) for the second one, in both forms, because only ϕn\phi_n enters it. So the sum is 14∑nEθcos⁡(xcos⁡αn)=M4J0(x)\frac14\sum_n E_\theta\cos(x\cos\alpha_n) = \frac M4 J_0(x) by Lemma 2. The same steps with sin⁡ψ\sin\psi give XsX_s, and with cos⁡ψnsin⁡ψn\cos\psi_n\sin\psi_n give the cross-correlation 00. Then E[S(t+τ)S(t)‾]=E[XcXc]+E[XsXs]+j(E[XsXc]−E[XcXs])=M2J0(x)E[S(t+\tau)\overline{S(t)}] = E[X_cX_c] + E[X_sX_s] + j(E[X_sX_c] - E[X_cX_s]) = \frac M2 J_0(x), and the factor 2Ω/M2\Omega/M gives ΩJ0(x)\Omega J_0(x). □\square

The result does not depend on tt, so both forms are wide-sense stationary, and it holds for every M≥1M \ge 1.

Theorem 2 (fourth moment, a phase per sinusoid). E∣h(t)∣4=Ω2(2−12M)E|h(t)|^4 = \Omega^2 (2 - \frac{1}{2M}) for every tt, and h(t)h(t) tends in distribution to a circular complex Gaussian with variance Ω\Omega as M→∞M \to \infty.

Proof. Condition on θ\theta. The terms Zn=ejψncos⁡Φn(t)Z_n = e^{j\psi_n}\cos\Phi_n(t) are then independent, with EZn=0E Z_n = 0, EZn2=0E Z_n^2 = 0 (by Ee2jψ=0E e^{2j\psi} = 0) and E∣Zn∣2=12E|Z_n|^2 = \frac12, E∣Zn∣4=38E|Z_n|^4 = \frac38 (by Lemma 1, since Φn(t)\Phi_n(t) is uniform modulo 2π2\pi). Expand E∣S∣4=∑a,b,c,dE[ZaZb‾ZcZd‾]E|S|^4 = \sum_{a,b,c,d} E[Z_a \overline{Z_b} Z_c \overline{Z_d}]. A term is nonzero only if no index appears once; the pairings a=b≠c=da = b \ne c = d and a=d≠b=ca = d \ne b = c each give E∣Za∣2E∣Zc∣2=14E|Z_a|^2E|Z_c|^2 = \frac14, the pairing a=c≠b=da = c \ne b = d gives EZa2 EZb2‾=0E Z_a^2\, \overline{E Z_b^2} = 0, and a=b=c=da = b = c = d gives 38\frac38. So E∣S∣4=38M+2⋅14M(M−1)=M22−M8E|S|^4 = \frac38 M + 2\cdot\frac14 M(M-1) = \frac{M^2}{2} - \frac{M}{8}, which does not depend on θ\theta. Multiply by (2Ω/M)2(2\Omega/M)^2. For the limit, given θ\theta the real and imaginary parts are sums of independent bounded terms with total covariance M4I\frac M4 I, so the Lyapunov form of the central limit theorem applies to S/MS/\sqrt M, and the limit does not depend on θ\theta. □\square

A circular complex Gaussian hh with E∣h∣2=ΩE|h|^2 = \Omega has E∣h∣4=2Ω2E|h|^4 = 2\Omega^2, so the excess −Ω2/(2M)-\Omega^2/(2M) measures the distance from Rayleigh fading.

Theorem 3 (fourth moment, the common phase at t=0t = 0). E∣h(0)∣4=Ω2(3−32M)E|h(0)|^4 = \Omega^2(3 - \frac{3}{2M}).

Proof. At t=0t = 0, Φn(0)=ϕ\Phi_n(0) = \phi for all nn, so S(0)=cos⁡ϕ⋅US(0) = \cos\phi \cdot U with U=∑nejψnU = \sum_n e^{j\psi_n}, and ϕ\phi is independent of UU. By the same pairing count with E∣ejψ∣2=E∣ejψ∣4=1E|e^{j\psi}|^2 = E|e^{j\psi}|^4 = 1, E∣U∣4=M+2M(M−1)=2M2−ME|U|^4 = M + 2M(M-1) = 2M^2 - M. With Ecos⁡4ϕ=38E\cos^4\phi = \frac38, E∣S(0)∣4=38(2M2−M)E|S(0)|^4 = \frac38(2M^2 - M), and the factor (2Ω/M)2(2\Omega/M)^2 gives the claim. □\square

So the common form has E∣h(0)∣4→3Ω2E|h(0)|^4 \to 3\Omega^2, not 2Ω22\Omega^2, as M→∞M \to \infty: h(0)h(0) is a Gaussian-like variable times the independent factor 2cos⁡ϕ\sqrt 2\cos\phi, and is not Gaussian for any MM. For t≠0t \ne 0 the Doppler terms wtcos⁡αnwt\cos\alpha_n differ between sinusoids and spread the phases, so the fourth moment changes with tt. This is the defect that Xiao, Zheng and Beaulieu (2006) remove by using one phase per sinusoid. For M=8M = 8, Theorems 2 and 3 give 1.9375 and 2.8125.

Complexity

Lines L1 to L4 draw 2M+12M + 1 random numbers and compute MM cosines, O(M)O(M) per channel. Each output sample costs MM cosines and 2M2M multiplications, so TT samples cost O(MT)O(M T) in the real RAM, with O(M)O(M) extra space. A Monte Carlo study with many channels draws new parameters for each one.

Properties

  • Exact second order. The autocorrelations and the cross-correlation of Clarke's model hold exactly, for every MM, over the ensemble. This is a theorem, not an approximation in MM.
  • Wide-sense stationary. The ensemble autocorrelation does not depend on tt.
  • Not ergodic for small MM. One realization has the time-average autocorrelation 1M∑ncos⁡(xcos⁡αn)\frac{1}{M}\sum_n \cos(x\cos\alpha_n), a quadrature with MM points, which differs from J0J_0 at large lags. Statistics must be averaged over many draws, not over a long run of one draw.
  • Gaussian only in the limit. For finite MM the gain is a sum of MM bounded terms, so it is not exactly Gaussian, and ∣h∣|h| is bounded by 2ΩM\sqrt{2\Omega M}. The fourth moment is 2−1/(2M)2 - 1/(2M) instead of 2.
  • Higher-order statistics. With one phase per sinusoid, the envelope distribution, the level crossing rate and the average fade duration approach those of Clarke's model as MM grows; M=8M = 8 to 16 is common.

Variants and improvements

  • The 2003 form with a common phase. It has the same second-order statistics, but it is not Gaussian over short times and the autocorrelation of its squared envelope depends on tt. The finding is credited to Sun, Ye and Choi and to Patel, Stuber and Pratt (2005); Xiao, Zheng and Beaulieu (2006) gave the correction.
  • The 2006 models. Xiao, Zheng and Beaulieu (2006) also give a model with a random offset per sinusoid, αn=(2πn+θn)/N\alpha_n = (2\pi n + \theta_n)/N, and a Rician model with a line-of-sight term; see Rician fading.
  • Several uncorrelated channels. Separate parameters for each channel make the channels independent, which Zheng and Xiao (2003) use for multiple uncorrelated waveforms. Deterministic models need special angle sets for this.
  • Deterministic sum of sinusoids. The Jakes simulator uses fixed angles. It is cheaper to set up, but its statistics are only approximate.

When to use it

Use it for Monte Carlo simulation of time-correlated Rayleigh fading when the channel must be evaluated at arbitrary times, for example with a Doppler that changes, or for channels in continuous time. Draw new parameters for each simulated channel and use the per-sinusoid phases. Use the filtered Gaussian noise simulator when an exactly Gaussian process on a fixed grid is needed, and an independent draw per block when the fading is block fading.

Pitfalls

  • One long run instead of many draws. The exact statistics are ensemble averages. One draw with small MM has the wrong time averages.
  • The common phase of 2003. Copying eq. (14) as printed gives a process whose squared envelope is not stationary. Use one phase per sinusoid.
  • Too few sinusoids for tail statistics. The envelope is bounded and its tails are lighter than Rayleigh. Deep fades, outage and error rates at high γˉ\bar\gamma need MM large enough, or a Gaussian generator.
  • Normalization. Each quadrature sum has variance M/4M/4. Papers and codes use different scale factors; the factor 2Ω/M\sqrt{2\Omega/M} here gives E∣h∣2=ΩE|h|^2 = \Omega. Check the scale before comparing γˉ\bar\gamma across simulators.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

zheng_xiao_fading_simulator.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/zheng-xiao-fading-simulator/. The authors are listed in prov/97VH88.jsonl.

"""The Zheng-Xiao statistical sum-of-sinusoids simulator for Rayleigh fading.

Eq. (14) of Zheng and Xiao 2003: with M sinusoids,
    X_c(t) = sum_n cos(psi_n) cos(w_d t cos(alpha_n) + phi_n),
    X_s(t) = sum_n sin(psi_n) cos(w_d t cos(alpha_n) + phi_n),
    alpha_n = (2 pi n - pi + theta) / (4 M), n = 1..M,
where psi_n, phi_n and theta are independent and uniform on [-pi, pi).
The fading gain is h = sqrt(2 Omega / M) (X_c + j X_s), so E|h|^2 = Omega.

The 2003 paper used one phase phi for all n. Xiao, Zheng and Beaulieu 2006
showed that this form is not Gaussian for short times and that its squared
envelope is not stationary; they use an independent phi_n for each n. The
default here is the corrected form; common_phase=True gives the 2003 form.
Both have the exact second-order statistics of Clarke's model.
"""

import math
import random


def draw_parameters(m: int, rng: random.Random, common_phase: bool = False) -> tuple[list[float], list[float], list[float]]:
    """One random draw of the angles alpha_n, the gain phases psi_n and the Doppler phases phi_n."""
    if m < 1:
        raise ValueError("need M >= 1")
    theta = rng.uniform(-math.pi, math.pi)  # @line L1
    psi = [rng.uniform(-math.pi, math.pi) for _ in range(m)]  # @line L2
    if common_phase:
        phi = [rng.uniform(-math.pi, math.pi)] * m
    else:
        phi = [rng.uniform(-math.pi, math.pi) for _ in range(m)]  # @line L3
    alpha = [(2.0 * math.pi * n - math.pi + theta) / (4.0 * m) for n in range(1, m + 1)]  # @line L4
    return alpha, psi, phi


def gains(fd: float, times: list[float], alpha: list[float], psi: list[float], phi: list[float], omega: float = 1.0) -> list[complex]:
    """h(t) at the given times for one fixed draw of the parameters."""
    m = len(alpha)
    wd = 2.0 * math.pi * fd
    g = math.sqrt(2.0 * omega / m)
    cp = [math.cos(p) for p in psi]
    sp = [math.sin(p) for p in psi]
    nu = [math.cos(a) for a in alpha]
    out = []
    for t in times:
        osc = [math.cos(wd * t * nu[n] + phi[n]) for n in range(m)]
        xc = sum(cp[n] * osc[n] for n in range(m))  # @line L5
        xs = sum(sp[n] * osc[n] for n in range(m))
        out.append(g * complex(xc, xs))  # @line L6
    return out


def zheng_xiao(m: int, fd: float, times: list[float], rng: random.Random, omega: float = 1.0, common_phase: bool = False) -> list[complex]:
    """One realization of the Zheng-Xiao simulator with M sinusoids at the given times."""
    alpha, psi, phi = draw_parameters(m, rng, common_phase)
    return gains(fd, times, alpha, psi, phi, omega)


def theta_average(m: int, x: float, points: int = 2000) -> float:
    """E over theta of (1 / M) sum_n cos(x cos(alpha_n)), by Simpson's rule over theta in [-pi, pi].

    This is the normalized autocorrelation E[h(t + tau) conj(h(t))] / Omega at
    x = 2 pi f_D tau. The theorem of Zheng and Xiao says that it equals J0(x).
    """
    if points % 2:
        points += 1
    h = 2.0 * math.pi / points

    def f(theta):
        return sum(math.cos(x * math.cos((2.0 * math.pi * n - math.pi + theta) / (4.0 * m))) for n in range(1, m + 1)) / m

    s = f(-math.pi) + f(math.pi)
    for k in range(1, points):
        s += (4 if k % 2 else 2) * f(-math.pi + k * h)
    return s * h / 3.0 / (2.0 * math.pi)


def fourth_moment(m: int, common_phase: bool) -> float:
    """E|h(0)|^4 / Omega^2: 2 - 1 / (2M) with a phase per sinusoid, 3 - 3 / (2M) with one common phase."""
    return 3.0 - 1.5 / m if common_phase else 2.0 - 0.5 / m


def j0(x: float, points: int = 2048) -> float:
    """J0(x) = (1 / 2 pi) integral over [0, 2 pi) of cos(x sin t) dt, by the trapezoid rule."""
    h = 2.0 * math.pi / points
    return sum(math.cos(x * math.sin(k * h)) for k in range(points)) / points
test_zheng_xiao_fading_simulator.py 90 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/zheng-xiao-fading-simulator/. The authors are listed in prov/97VH88.jsonl.

import math
import random

from zheng_xiao_fading_simulator import (
    draw_parameters,
    fourth_moment,
    gains,
    j0,
    theta_average,
    zheng_xiao,
)

M = 8


def j0_series(x):
    """J0 by its power series, a second method for small x."""
    s, t, k = 0.0, 1.0, 0
    while abs(t) > 1e-18 or k < 5:
        s += t
        k += 1
        t *= -(x / 2.0) ** 2 / (k * k)
    return s


def test_angles_cover_a_quarter_circle() -> None:
    rng = random.Random(9701)
    for _ in range(100):
        alpha, psi, phi = draw_parameters(M, rng)
        assert len(alpha) == len(psi) == len(phi) == M
        assert all(0.0 <= a <= math.pi / 2 for a in alpha)
        steps = [alpha[n + 1] - alpha[n] for n in range(M - 1)]
        assert all(abs(s - 2 * math.pi / (4 * M)) < 1e-12 for s in steps)


def test_exact_autocorrelation_over_theta() -> None:
    # the theorem: the average over theta is J0(x) for any M, even M = 1
    for m in (1, 2, 8):
        for ft in (0.1, 0.38274, 1.0, 3.0, 10.0):
            x = 2 * math.pi * ft
            assert abs(theta_average(m, x) - j0(x)) < 1e-9
    for x in (0.5, 2.0, 5.0):
        assert abs(j0(x) - j0_series(x)) < 1e-10


def test_ensemble_power_and_autocorrelation() -> None:
    rng = random.Random(9702)
    trials = 4000
    fd = 1.0
    lags = [0.1, 0.25, 0.5, 1.0, 5.0]
    acc = [0j] * len(lags)
    cross = 0.0
    power = 0.0
    for _ in range(trials):
        h = zheng_xiao(M, fd, [3.0] + [3.0 + t for t in lags], rng)
        power += abs(h[0]) ** 2
        cross += h[1].real * h[0].imag
        for k in range(len(lags)):
            acc[k] += h[k + 1] * h[0].conjugate()
    assert abs(power / trials - 1.0) < 0.07
    assert abs(cross / trials) < 0.05  # the quadratures are uncorrelated at any lag
    for k, t in enumerate(lags):
        assert abs(acc[k] / trials - j0(2 * math.pi * fd * t)) < 0.07


def test_fourth_moment_shows_the_2006_correction() -> None:
    # E|h|^4 = 2 for Rayleigh fading. The phase per sinusoid gives 2 - 1/(2M) = 1.9375,
    # one common phase gives 3 - 3/(2M) = 2.8125 at t = 0.
    assert fourth_moment(M, False) == 1.9375 and fourth_moment(M, True) == 2.8125
    # 12000 draws: the standard error is about 0.04 per-path and 0.09 common, and the two means differ by 0.875.
    trials = 12000
    for common, tol, seed in ((False, 0.15, 9703), (True, 0.35, 9704)):
        rng = random.Random(seed)
        s = 0.0
        for _ in range(trials):
            alpha, psi, phi = draw_parameters(M, rng, common_phase=common)
            h = gains(1.0, [0.0], alpha, psi, phi)[0]
            s += abs(h) ** 4
        assert abs(s / trials - fourth_moment(M, common)) < tol


def test_omega_scales_power() -> None:
    rng = random.Random(9705)
    alpha, psi, phi = draw_parameters(M, rng)
    a = gains(2.0, [0.0, 0.1, 0.7], alpha, psi, phi, omega=1.0)
    b = gains(2.0, [0.0, 0.1, 0.7], alpha, psi, phi, omega=4.0)
    assert all(abs(q - 2 * p) < 1e-12 for p, q in zip(a, b))

History

Pop and Beaulieu (2001) showed that the Jakes simulator is not wide-sense stationary and that random phases alone do not fix its higher-order statistics. Xiao and Zheng (2002) proposed a sum of sinusoids with random angles, gains and phases at a conference, and in 2003 Zheng and Xiao proved that the second-order statistics of their model match Clarke's model exactly for any number of sinusoids. Later work found that the 2003 model, with one phase for all sinusoids, is not Gaussian over short times and has a squared envelope whose autocorrelation is not stationary; Xiao, Zheng and Beaulieu (2006) corrected it with independent phases and gave new models for Rayleigh and Rician fading.

References

  1. Y. R. Zheng and C. Xiao, Simulation models with correct statistical properties for Rayleigh fading channels, IEEE Transactions on Communications 51(6), 2003, pages 920 to 928, Section III, eqs. (14) and (15) (the model) and Theorem 1 (its autocorrelation and cross-correlation functions)
  2. C. Xiao, Y. R. Zheng and N. C. Beaulieu, Novel sum-of-sinusoids simulation models for Rayleigh and Rician fading channels, IEEE Transactions on Wireless Communications 5(12), 2006, pages 3667 to 3679, Section II (the remark that corrects eq. (14) of the 2003 paper with one phase per sinusoid, and Theorem 3) and Section III (the Rician model)
  3. M. F. Pop and N. C. Beaulieu, Limitations of sum-of-sinusoids fading channel simulators, IEEE Transactions on Communications 49(4), 2001, pages 699 to 708, the statistics of the Jakes simulator that the random model corrects

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example