Algorithm Search⌘K

Algorithmcore

Jakes fading simulator

Also called Jakes model, sum-of-sinusoids fading simulator.

Generates a fading waveform for Clarke's model as a fixed sum of M + 1 sinusoids. It is cheap and smooth, but deterministic and not stationary, and its correlation leaves J0 at large lags.

Time
O(M T) worst
Space
O(M) extra
Where
M = the number of oscillators minus one; T = the number of output samples
Properties
deterministicnot exact clarke statisticsnot wide sense stationary
Origin
William C. Jakes, 1974

The Jakes simulator is a deterministic generator of a complex fading gain h(t)h(t) that approximates Clarke's model: it adds M+1M + 1 sinusoids whose frequencies are the Doppler shifts fDcos⁡(2πn/N)f_D \cos(2\pi n/N) of N=4M+2N = 4M + 2 plane waves at equally spaced angles. Clarke's model is the target statistics, the autocorrelation ΩJ0(2πfDτ)\Omega J_0(2\pi f_D \tau) and the U-shaped Doppler spectrum; this page is about one way to produce a waveform with those statistics. The Zheng-Xiao simulator adds random angles and phases and gets the second-order statistics exactly, and the filtered Gaussian noise simulator shapes Gaussian noise with the spectrum instead of adding sinusoids. The Jakes simulator is a heuristic: it is smooth and cheap, but one run is a fixed function of time, not a random process with the statistics of Clarke's model.

In plain words

A receiver moving through a city gets the same signal along many paths. Each path arrives from its own direction, so the motion shifts its frequency by a different amount, and the paths add up to a gain that rises and falls in time. Jakes imagined a ring of equally spaced paths around the receiver. By symmetry, many of them have the same frequency shift, so only a few oscillators are needed. Each oscillator is a cosine at one Doppler shift, and fixed weights spread the oscillators over the real and imaginary parts of the gain. The sum fades in a way that looks like real fading over short times. But nothing in it is random: every run starts with the same high peak and gives the same waveform.

The problem

The input is the maximum Doppler shift fDf_D in Hz, the mean power Ω\Omega, the number of oscillators M+1M + 1, and a list of TT times tt. The output is the gain h(t)=hc(t)+jhs(t)h(t) = h_c(t) + j h_s(t) at each time. The goal is that the time-average power is Ω\Omega and that the time-average autocorrelation ⟨h(t+τ) h(t)‾⟩\langle h(t + \tau)\, \overline{h(t)} \rangle is close to ΩJ0(2πfDτ)\Omega J_0(2\pi f_D \tau), the autocorrelation of Clarke's model. The model is flat fading that varies in time (time-correlated fading); the simulator produces the channel only and says nothing about CSIR or CSIT.

The algorithm

  1. JAKES(M, f_D, Ω, t)
  2. 1N ← 4M + 2
  3. 2ν₀ ← 1; νₙ ← cos(2πn/N) for n = 1 .. M ▷ ωₙ = 2π f_D νₙ
  4. 3β₀ ← π/4; βₙ ← πn/M for n = 1 .. M
  5. 4a₀ ← √2 cos β₀, b₀ ← √2 sin β₀; aₙ ← 2 cos βₙ, bₙ ← 2 sin βₙ
  6. 5c ← Σ_{n=0}^{M} aₙ cos(ωₙ t)
  7. 6s ← Σ_{n=0}^{M} bₙ cos(ωₙ t)
  8. 7return √(2Ω/N) (c + j s)

Line L1 fixes the number of plane waves. The wave at angle 2πn/N2\pi n/N has the Doppler shift fDcos⁡(2πn/N)f_D \cos(2\pi n/N). Because N/2N/2 is odd, the waves at angles ±2πn/N\pm 2\pi n/N and π±2πn/N\pi \pm 2\pi n/N give the same cosine up to sign, so the NN waves fold into the MM oscillators of line L2 plus the oscillator at fDf_D itself. Lines L3 and L4 are the gains of Jakes, in the form of eqs. (6) and (7) of Zheng and Xiao (2003). The angles βn\beta_n are chosen so that the two quadratures cc and ss have equal power: ∑an2=∑bn2=N/2\sum a_n^2 = \sum b_n^2 = N/2 for M≥2M \ge 2. Lines L5 and L6 add the oscillators, and line L7 scales the sum so that the time-average power is Ω\Omega.

Example

Take M=8M = 8, so N=34N = 34, and fD=1f_D = 1. The normalized frequencies νn\nu_n are 1, 0.983, 0.9325, 0.8502, 0.739, 0.6026, 0.4457, 0.2737 and 0.0923. The gains are a=(1,1.848,1.414,0.765,0,−0.765,−1.414,−1.848,−2)a = (1, 1.848, 1.414, 0.765, 0, -0.765, -1.414, -1.848, -2) and b=(1,0.765,1.414,1.848,2,1.848,1.414,0.765,0)b = (1, 0.765, 1.414, 1.848, 2, 1.848, 1.414, 0.765, 0).

The time-average autocorrelation of the output, divided by Ω\Omega, is

R(τ)=2N[cos⁡x+2∑n=1Mcos⁡(xνn)],x=2πfDτ.R(\tau) = \frac{2}{N}\Big[\cos x + 2\sum_{n=1}^{M} \cos(x \nu_n)\Big], \qquad x = 2\pi f_D \tau .
fDτf_D \tau 0.1 0.25 0.5 1 2 3 5 10
J0(2πfDτ)J_0(2\pi f_D\tau) 0.90371 0.47200 -0.30424 0.22028 0.15751 0.12906 0.10025 0.07103
Jakes, R(τ)R(\tau) 0.90371 0.47200 -0.30424 0.22028 0.15751 0.12906 -0.00301 -0.04948

Up to fDτ=3f_D\tau = 3 the two agree to five digits. The first lag where they differ by more than 0.01 is fDτ=4.4f_D \tau = 4.4, and at fDτ=5f_D\tau = 5 the simulator has lost the correlation completely. With M=4M = 4 the same error appears at fDτ=2.04f_D \tau = 2.04, and with M=16M = 16 at 9.289.28.

The quadratures are worse. At fDτ=0.38274f_D\tau = 0.38274, the first zero of J0J_0, each of hch_c and hsh_s should have zero correlation with itself and with the other. The simulator gives 0.173 for hch_c, -0.173 for hsh_s and -0.346 between them. Even at τ=0\tau = 0 the quadratures are correlated, with coefficient 2/N=0.0592/N = 0.059.

At t=0t = 0 every cosine equals 1, so ∣h(0)∣2/Ω=(2/N)[(∑an)2+(∑bn)2]|h(0)|^2/\Omega = (2/N)[(\sum a_n)^2 + (\sum b_n)^2]. Here ∑an=−1\sum a_n = -1 and ∑bn=1+2cot⁡(π/16)=11.055\sum b_n = 1 + 2\cot(\pi/16) = 11.055, so ∣h(0)∣2=7.25 Ω|h(0)|^2 = 7.25\,\Omega, a peak that a Rayleigh gain reaches with probability e−7.25=7⋅10−4e^{-7.25} = 7 \cdot 10^{-4}. Every run starts with it.

Correctness

Claim. The time-average power of the output is Ω\Omega, and its time-average autocorrelation is R(τ)R(\tau) above. RR is the NN-point trapezoid rule for J0J_0, and R(τ)=J0(x)+2∑m≥1(−1)mJmN(x)R(\tau) = J_0(x) + 2\sum_{m \ge 1} (-1)^m J_{mN}(x) exactly. So the error is small while x=2πfDτx = 2\pi f_D \tau is well below NN.

Key step. For distinct frequencies the time average of cos⁡(ωnt)cos⁡(ωk(t+τ))\cos(\omega_n t)\cos(\omega_k (t + \tau)) is 12cos⁡(ωnτ)\frac12 \cos(\omega_n \tau) if n=kn = k and 0 otherwise, and an2+bn2a_n^2 + b_n^2 is 2 for n=0n = 0 and 4 otherwise. By the Jacobi-Anger expansion, cos⁡(xcos⁡θ)\cos(x \cos\theta) is J0(x)J_0(x) plus harmonics cos⁡(2kθ)\cos(2k\theta) with weights 2(−1)kJ2k(x)2(-1)^k J_{2k}(x). The average over NN equally spaced angles keeps only the harmonics that are multiples of NN, and the folding of line L2 turns that average into RR. The full proof is in the proofs folder. It also shows why the simulator is not wide-sense stationary: nothing in it is random, so the only "expectation" of h(t+τ)h(t)‾h(t+\tau)\overline{h(t)} is the product itself, and that product depends on tt.

Proof: The Jakes simulator has time-average power Omega, and its time-average autocorrelation is the N-point trapezoid rule for J0full

Let N=4M+2N = 4M + 2, ν0=1\nu_0 = 1, νn=cos⁡(2πn/N)\nu_n = \cos(2\pi n/N) and ωn=2πfDνn\omega_n = 2\pi f_D \nu_n for n=1,…,Mn = 1, \ldots, M, with the gains an,bna_n, b_n of line L4. The output is

h(t)=2Ω/N ∑n=0M(an+jbn)cos⁡(ωnt).h(t) = \sqrt{2\Omega/N}\, \sum_{n=0}^{M} (a_n + j b_n) \cos(\omega_n t).

For a function gg, write ⟨g⟩=lim⁡T→∞12T∫−TTg(t) dt\langle g \rangle = \lim_{T \to \infty} \frac{1}{2T} \int_{-T}^{T} g(t)\, dt for the time average.

Lemma 1 (distinct frequencies). For fD>0f_D > 0 the frequencies ω0,…,ωM\omega_0, \ldots, \omega_M are distinct and positive.

Proof. The angles 2πn/N2\pi n/N for n=0,…,Mn = 0, \ldots, M lie in [0,π/2)[0, \pi/2), because 2πM/(4M+2)<π/22\pi M/(4M + 2) < \pi/2. The cosine is strictly decreasing and positive there. □\square

Lemma 2 (time averages of products). For ω,ω′>0\omega, \omega' > 0, ⟨cos⁡(ω(t+τ))cos⁡(ω′t)⟩\langle \cos(\omega (t + \tau)) \cos(\omega' t) \rangle is 12cos⁡(ωτ)\frac12 \cos(\omega \tau) if ω=ω′\omega = \omega' and 00 otherwise.

Proof. The product is 12[cos⁡(ωτ+(ω+ω′)t)+cos⁡(ωτ+(ω−ω′)t)]\frac12 [\cos(\omega \tau + (\omega + \omega') t) + \cos(\omega\tau + (\omega - \omega') t)]. The time average of cos⁡(c+dt)\cos(c + d t) is 00 for d≠0d \ne 0, because its integral over [−T,T][-T, T] is bounded by 2/∣d∣2/|d|, and it is cos⁡c\cos c for d=0d = 0. □\square

Lemma 3 (the gains). a02+b02=2a_0^2 + b_0^2 = 2, an2+bn2=4a_n^2 + b_n^2 = 4 for n≥1n \ge 1, and ∑nan2=∑nbn2=N/2\sum_n a_n^2 = \sum_n b_n^2 = N/2.

Proof. The first two follow from cos⁡2+sin⁡2=1\cos^2 + \sin^2 = 1. Next, a02=2cos⁡2(π/4)=1a_0^2 = 2\cos^2(\pi/4) = 1, and ∑n=1M4cos⁡2(πn/M)=2M+2∑n=1Mcos⁡(2πn/M)\sum_{n=1}^{M} 4\cos^2(\pi n/M) = 2M + 2\sum_{n=1}^{M} \cos(2\pi n/M). The last sum is 00 for M≥2M \ge 2, because it is the real part of the sum of all MM-th roots of unity, so ∑an2=1+2M=N/2\sum a_n^2 = 1 + 2M = N/2. For M=1M = 1 the sum is cos⁡2π=1\cos 2\pi = 1, and a=(1,−2)a = (1, -2) gives 5≠N/2=35 \ne N/2 = 3; so the equal power holds for M≥2M \ge 2, and the same computation with sines gives ∑bn2=N/2\sum b_n^2 = N/2 for M≥2M \ge 2. □\square

Theorem 1 (power and autocorrelation). For fD>0f_D > 0, ⟨∣h∣2⟩=Ω\langle |h|^2 \rangle = \Omega, and

1Ω⟨h(t+τ) h(t)‾⟩=R(τ)=2N[cos⁡x+2∑n=1Mcos⁡(xνn)],x=2πfDτ.\frac{1}{\Omega} \langle h(t + \tau)\, \overline{h(t)} \rangle = R(\tau) = \frac{2}{N}\Big[\cos x + 2 \sum_{n=1}^{M} \cos(x \nu_n)\Big], \qquad x = 2\pi f_D \tau.

Proof. Expand the product into the double sum over n,kn, k of (an+jbn)(ak−jbk)cos⁡(ωn(t+τ))cos⁡(ωkt)(a_n + j b_n)(a_k - j b_k) \cos(\omega_n (t+\tau)) \cos(\omega_k t). By Lemmas 1 and 2, only n=kn = k survives the time average, and it gives 12(an2+bn2)cos⁡(ωnτ)\frac12 (a_n^2 + b_n^2) \cos(\omega_n \tau). With Lemma 3 and the factor 2Ω/N2\Omega/N this is 2ΩN[cos⁡(ω0τ)+2∑n≥1cos⁡(ωnτ)]\frac{2\Omega}{N}[\cos(\omega_0 \tau) + 2\sum_{n \ge 1} \cos(\omega_n \tau)], which is ΩR(τ)\Omega R(\tau). At τ=0\tau = 0, R(0)=(2/N)(1+2M)=1R(0) = (2/N)(1 + 2M) = 1. □\square

Lemma 4 (folding). R(τ)=1N∑k=0N−1cos⁡(xcos⁡(2πk/N))R(\tau) = \frac{1}{N} \sum_{k=0}^{N-1} \cos(x \cos(2\pi k/N)).

Proof. The term k=0k = 0 gives cos⁡x\cos x, and so does k=N/2=2M+1k = N/2 = 2M + 1, because cos⁡π=−1\cos \pi = -1 and the cosine is even. The terms kk and N−kN - k are equal. For 1≤k≤M1 \le k \le M, the term k′=2M+1−kk' = 2M + 1 - k has cos⁡(2πk′/N)=cos⁡(π−2πk/N)=−cos⁡(2πk/N)\cos(2\pi k'/N) = \cos(\pi - 2\pi k/N) = -\cos(2\pi k/N), so it is equal to the term kk. So the indices 1,…,N−11, \ldots, N-1 other than N/2N/2 form MM groups of four equal terms, and the sum is 2cos⁡x+4∑k=1Mcos⁡(xνk)2\cos x + 4\sum_{k=1}^{M} \cos(x \nu_k). Divide by NN. □\square

Theorem 2 (the error). R(τ)=J0(x)+2∑m≥1(−1)mJmN(x)R(\tau) = J_0(x) + 2 \sum_{m \ge 1} (-1)^m J_{mN}(x).

Proof. The Jacobi-Anger expansion gives cos⁡(xcos⁡θ)=J0(x)+2∑k≥1(−1)kJ2k(x)cos⁡(2kθ)\cos(x\cos\theta) = J_0(x) + 2\sum_{k \ge 1} (-1)^k J_{2k}(x) \cos(2k\theta), and the series converges absolutely and uniformly in θ\theta. Average it over θj=2πj/N\theta_j = 2\pi j/N, j=0,…,N−1j = 0, \ldots, N-1. The average of cos⁡(2kθj)\cos(2k\theta_j) is 1 if NN divides 2k2k and 0 otherwise. Since NN is even, N∣2kN \mid 2k means 2k=mN2k = mN with k=m(2M+1)k = m(2M + 1), and (−1)k=(−1)m(-1)^k = (-1)^m because 2M+12M + 1 is odd. By Lemma 4 the average is R(τ)R(\tau). □\square

Since ∣Jn(x)∣≤(x/2)n/n!|J_n(x)| \le (x/2)^n / n!, the error term is tiny while xx is well below NN: for M=8M = 8, the difference from J0J_0 stays below 10−510^{-5} up to fDτ=3f_D\tau = 3. When xx approaches NN, JN(x)J_N(x) is no longer small, and the error is of the size of J0J_0 itself.

Remark (no stationarity). hh is a fixed function of tt. A wide-sense stationary process needs E[h(t+τ)h(t)‾]E[h(t + \tau)\overline{h(t)}] to be independent of tt, and here the only expectation is the value itself. For example, ∣h(0)∣2/Ω=(2/N)[(∑an)2+(∑bn)2]|h(0)|^2/\Omega = (2/N)[(\sum a_n)^2 + (\sum b_n)^2], with ∑an=1+2∑n=1Mcos⁡(πn/M)=−1\sum a_n = 1 + 2\sum_{n=1}^{M} \cos(\pi n/M) = -1 and ∑bn=1+2∑n=1Msin⁡(πn/M)=1+2cot⁡(π/(2M))\sum b_n = 1 + 2\sum_{n=1}^{M} \sin(\pi n /M) = 1 + 2\cot(\pi/(2M)), which is 7.257.25 for M=8M = 8, while ⟨∣h∣2⟩/Ω=1\langle |h|^2 \rangle / \Omega = 1. With independent uniform phases ϕn\phi_n added to the oscillators, E[cos⁡(ωn(t+τ)+ϕn)cos⁡(ωkt+ϕk)]E[\cos(\omega_n(t+\tau) + \phi_n)\cos(\omega_k t + \phi_k)] is 12cos⁡(ωnτ)\frac12 \cos(\omega_n\tau) for n=kn = k and 0 otherwise, so the same computation as in Theorem 1 gives the ensemble autocorrelation ΩR(τ)\Omega R(\tau) for every tt: this is the variant of Pop and Beaulieu.

Complexity

Lines L1 to L4 cost O(M)O(M) once. Each output sample costs M+1M + 1 cosines and 2(M+1)2(M + 1) multiplications, so TT samples cost O(MT)O(M T) in the real RAM, with O(M)O(M) extra space. In hardware, each oscillator is a phase accumulator and a table lookup, which is why the method was popular for fading hardware.

Properties

  • Not random. One run is a fixed function of time. Averages over a run converge to the values above, but there is no ensemble to average over, and the run is not wide-sense stationary (Pop and Beaulieu 2001).
  • Second-order statistics. The complex autocorrelation matches J0J_0 for small lags only. The quadrature autocorrelations and the cross-correlation do not match Clarke's model at any MM.
  • Higher-order statistics. The envelope is not exactly Rayleigh, and the level crossing rate and the fade durations are only close to those of Clarke's model for large MM.
  • Smooth output. Unlike a filtered noise generator, it can be evaluated at any real time, and the waveform has no edge effects or periodic wrap.
  • Equal power in each quadrature. The choice of βn\beta_n gives ∑an2=∑bn2\sum a_n^2 = \sum b_n^2, which is the purpose of line L3.

Variants and improvements

  • Random phases. Pop and Beaulieu add a random phase ϕn\phi_n to each oscillator. Over the random phases, the process is wide-sense stationary with the autocorrelation R(τ)R(\tau), but its higher-order statistics remain wrong.
  • Several uncorrelated waveforms. Jakes shifted the angles βn\beta_n for each waveform to get several fading gains from one set of oscillators, but these waveforms are not uncorrelated. Dent, Bottomley and Croft (1993) take the gains from the rows of a Walsh-Hadamard matrix, as in the Walsh-Hadamard transform, and change the arrival angles, so that the waveforms are uncorrelated.
  • Random angles. The Zheng-Xiao simulator draws the arrival angles and phases at random. Its second-order statistics equal those of Clarke's model exactly, for any MM.
  • Filtered noise. The filtered Gaussian noise simulator gives a Gaussian process with a spectrum close to Clarke's, at the cost of a block length fixed in advance.

When to use it

Use the Jakes simulator for a quick, smooth fading waveform, to look at fades or to drive hardware, when exact statistics are not important. Do not use it for Monte Carlo estimates of error rates or outage, which average over many independent channels: one run has no randomness, and runs that differ only in the start time are strongly dependent. For those, use the Zheng-Xiao simulator with a new draw per channel, or the filtered Gaussian noise simulator.

Pitfalls

  • Calling it Clarke's model. The name "Jakes model" is used both for this generator and for the spectrum of Clarke's model. The spectrum is exact physics under its assumptions; the generator is an approximation.
  • Averaging over runs. Running the simulator twice gives the same waveform. Shifting the start time gives different numbers, but not independent channels.
  • The peak at t=0t = 0. Every run starts with ∣h∣2=7.25 Ω|h|^2 = 7.25\,\Omega for M=8M = 8. Discard the start, or use random phases.
  • Long records. For 2πfDτ2\pi f_D \tau near NN the correlation is wrong, and the waveform is almost periodic. Long simulations need larger MM.
  • Quadrature statistics. Code that uses hch_c and hsh_s as two independent real Gaussian processes, for example for two branches of a diversity system, gets correlated branches.

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.

jakes_fading_simulator.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/jakes-fading-simulator/. The authors are listed in prov/43NN0S.jsonl.

"""The Jakes simulator: a deterministic sum of sinusoids for Rayleigh fading.

Clarke's model has the autocorrelation Omega J0(2 pi f_D tau). The Jakes
simulator approximates it with N = 4M + 2 plane waves at the equally spaced
angles 2 pi n / N. By symmetry only M + 1 oscillators are needed: the
frequencies w_0 = 2 pi f_D and w_n = 2 pi f_D cos(2 pi n / N), n = 1..M,
with the gains a_n = 2 cos(beta_n), b_n = 2 sin(beta_n), beta_n = pi n / M,
and a_0 = b_0 = 1 (sqrt(2) cos(pi / 4)). The form follows eqs. (6) and (7) of
Zheng and Xiao 2003. With the factor sqrt(2 Omega / N), the time-average
power is Omega.

The optional phases (one per oscillator) give the variant with random
phases of Pop and Beaulieu 2001, which is wide-sense stationary over the
ensemble of phases.
"""

import math


def jakes_coefficients(m: int) -> tuple[int, list[float], list[float], list[float]]:
    """N, the normalized frequencies cos(2 pi n / N) and the gains a_n, b_n for n = 0..M."""
    if m < 1:
        raise ValueError("need M >= 1")
    n = 4 * m + 2  # @line L1
    nu = [1.0] + [math.cos(2.0 * math.pi * k / n) for k in range(1, m + 1)]  # @line L2
    beta = [math.pi / 4.0] + [math.pi * k / m for k in range(1, m + 1)]  # @line L3
    a = [math.sqrt(2.0) * math.cos(beta[0])] + [2.0 * math.cos(x) for x in beta[1:]]  # @line L4
    b = [math.sqrt(2.0) * math.sin(beta[0])] + [2.0 * math.sin(x) for x in beta[1:]]
    return n, nu, a, b


def jakes(m: int, fd: float, times: list[float], omega: float = 1.0, phases: list[float] | None = None) -> list[complex]:
    """The fading gains h(t) of the Jakes simulator with M + 1 oscillators at the given times.

    fd is the maximum Doppler shift in Hz and times are in seconds. phases, if
    given, holds M + 1 oscillator phases (the variant of Pop and Beaulieu).
    """
    n, nu, a, b = jakes_coefficients(m)
    if phases is None:
        phases = [0.0] * (m + 1)
    if len(phases) != m + 1:
        raise ValueError("need M + 1 phases")
    w = [2.0 * math.pi * fd * v for v in nu]
    g = math.sqrt(2.0 * omega / n)
    out = []
    for t in times:
        osc = [math.cos(w[k] * t + phases[k]) for k in range(m + 1)]
        c = sum(a[k] * osc[k] for k in range(m + 1))  # @line L5
        s = sum(b[k] * osc[k] for k in range(m + 1))  # @line L6
        out.append(g * complex(c, s))  # @line L7
    return out


def time_autocorrelation(m: int, x: float) -> float:
    """The time-average autocorrelation <h(t + tau) conj(h(t))> / Omega at x = 2 pi f_D tau.

    It is (2 / N) (cos x + 2 sum_{n=1}^{M} cos(x cos(2 pi n / N))), the N-point
    trapezoid rule for J0(x).
    """
    n, nu, _, _ = jakes_coefficients(m)
    return (2.0 / n) * (math.cos(x) + 2.0 * sum(math.cos(x * v) for v in nu[1:]))


def quadrature_correlations(m: int, x: float) -> tuple[float, float, float]:
    """The time-average correlations <c c>, <s s> and <c s> of the two quadratures, each normalized by the power of one quadrature."""
    n, nu, a, b = jakes_coefficients(m)
    rcc = (2.0 / n) * sum(a[k] ** 2 * math.cos(x * nu[k]) for k in range(m + 1))
    rss = (2.0 / n) * sum(b[k] ** 2 * math.cos(x * nu[k]) for k in range(m + 1))
    rcs = (2.0 / n) * sum(a[k] * b[k] * math.cos(x * nu[k]) for k in range(m + 1))
    return rcc, rss, rcs


def bessel_j(order: int, x: float, points: int = 2048) -> float:
    """J_n(x) = (1 / 2 pi) integral over [0, 2 pi) of cos(n t - x sin t) dt, by the trapezoid rule.

    The integrand is periodic and smooth, so the rule converges very fast when
    points is well above order + |x|.
    """
    h = 2.0 * math.pi / points
    return sum(math.cos(order * k * h - x * math.sin(k * h)) for k in range(points)) / points


def j0(x: float) -> float:
    """The Bessel function J0(x)."""
    return bessel_j(0, x)


def aliasing_series(m: int, x: float, terms: int = 4) -> float:
    """J0(x) + 2 sum_{k>=1} (-1)^k J_{kN}(x), the exact value of the Jakes autocorrelation."""
    n = 4 * m + 2
    return j0(x) + 2.0 * sum((-1) ** k * bessel_j(k * n, x) for k in range(1, terms + 1))


def power_at_zero(m: int) -> float:
    """|h(0)|^2 / Omega for zero phases: (2 / N) ((sum a)^2 + (sum b)^2)."""
    n, _, a, b = jakes_coefficients(m)
    return (2.0 / n) * (sum(a) ** 2 + sum(b) ** 2)
test_jakes_fading_simulator.py 122 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/jakes-fading-simulator/. The authors are listed in prov/43NN0S.jsonl.

import math
import random

from jakes_fading_simulator import (
    aliasing_series,
    bessel_j,
    j0,
    jakes,
    jakes_coefficients,
    power_at_zero,
    quadrature_correlations,
    time_autocorrelation,
)

M = 8
FD = 1.0
STEP = 0.05
RECORD = 2000.0


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 record():
    times = [k * STEP for k in range(int(RECORD / STEP))]
    return jakes(M, FD, times)


def test_coefficients() -> None:
    n, nu, a, b = jakes_coefficients(M)
    assert n == 34
    assert len(nu) == len(a) == len(b) == M + 1
    assert abs(a[0] - 1.0) < 1e-12 and abs(b[0] - 1.0) < 1e-12
    # time-average powers of the two quadratures are equal: sum a^2 = sum b^2 = N / 2
    assert abs(sum(v * v for v in a) - n / 2) < 1e-12
    assert abs(sum(v * v for v in b) - n / 2) < 1e-12


def test_bessel_against_series() -> None:
    for x in (0.0, 0.5, 1.0, 2.404825557695773, 5.0, 10.0):
        assert abs(j0(x) - j0_series(x)) < 1e-10
    assert abs(j0(2 * math.pi * 0.38274)) < 1e-4  # the first zero of J0 at f_D tau = 0.38274


def test_mean_power() -> None:
    h = record()
    p = sum(abs(v) ** 2 for v in h) / len(h)
    assert abs(p - 1.0) < 0.02


def test_sample_autocorrelation_matches_closed_form() -> None:
    h = record()
    for lag in (2, 5, 8, 20, 40):  # f_D tau = 0.1, 0.25, 0.4, 1, 2
        r = sum(h[k + lag] * h[k].conjugate() for k in range(len(h) - lag)) / (len(h) - lag)
        x = 2 * math.pi * FD * lag * STEP
        assert abs(r - time_autocorrelation(M, x)) < 0.02
        assert abs(r - j0(x)) < 0.02


def test_closed_form_close_to_clarke_for_small_lags() -> None:
    for k in range(0, 301):
        x = 2 * math.pi * k * 0.01  # f_D tau up to 3
        assert abs(time_autocorrelation(M, x) - j0(x)) < 1e-3


def test_bias_at_large_lags() -> None:
    # f_D tau = 5 and 10: the autocorrelation departs from J0
    for ft, target in ((5.0, -0.00301), (10.0, -0.04948)):
        x = 2 * math.pi * ft
        r = time_autocorrelation(M, x)
        assert abs(r - target) < 1e-4
        assert abs(r - j0(x)) > 0.05
        assert abs(r - aliasing_series(M, x)) < 1e-9


def test_quadratures_are_not_clarke() -> None:
    x = 2 * math.pi * 0.38274  # J0 is zero here
    rcc, rss, rcs = quadrature_correlations(M, x)
    assert abs(rcc - 0.17328) < 1e-4
    assert abs(rcs - (-0.3462)) < 1e-4
    assert abs(rcc + rss - 2 * time_autocorrelation(M, x)) < 1e-12
    rcc0, rss0, rcs0 = quadrature_correlations(M, 0.0)
    assert abs(rcc0 - 1) < 1e-12 and abs(rss0 - 1) < 1e-12
    assert abs(rcs0 - 2 / 34) < 1e-12  # the quadratures are correlated at lag 0


def test_peak_at_time_zero() -> None:
    h0 = jakes(M, FD, [0.0])[0]
    expect = (2 / 34) * (1 + (1 + 2 / math.tan(math.pi / 16)) ** 2)
    assert abs(abs(h0) ** 2 - expect) < 1e-9
    assert abs(power_at_zero(M) - expect) < 1e-9
    assert 7.2 < expect < 7.3


def test_random_phases_give_unit_ensemble_power() -> None:
    rng = random.Random(4301)
    trials = 4000
    acc0 = 0.0
    acc1 = 0j
    x = 2 * math.pi * 0.25
    for _ in range(trials):
        ph = [rng.uniform(-math.pi, math.pi) for _ in range(M + 1)]
        a, b = jakes(M, FD, [0.0, 0.25], phases=ph)
        acc0 += abs(a) ** 2
        acc1 += b * a.conjugate()
    assert abs(acc0 / trials - 1.0) < 0.06
    assert abs(acc1 / trials - time_autocorrelation(M, x)) < 0.06


def test_bessel_order() -> None:
    # J1(1) = 0.44005058574493355
    assert abs(bessel_j(1, 1.0) - 0.44005058574493355) < 1e-12

History

Jakes and his colleagues at Bell Labs built fading simulators from banks of oscillators in the early 1970s, and the 1974 book Microwave Mobile Communications, which Jakes edited, gave the design with N=4M+2N = 4M + 2 waves and M+1M + 1 oscillators. It became the standard way to simulate fading for two decades. Dent, Bottomley and Croft (1993) changed the gains to produce several uncorrelated waveforms. Pop and Beaulieu (2001) showed that the simulator and its variants are not wide-sense stationary and proposed random phases. Zheng and Xiao (2002, 2003) then gave statistical sum-of-sinusoids models with random angles, whose second-order statistics match Clarke's model.

References

  1. William C. Jakes (editor), Microwave Mobile Communications, Wiley, 1974; reissued by IEEE Press, 1994, Chapter 1 (the laboratory simulation of multipath fading with equally spaced oscillators)
  2. 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 proof that the Jakes simulator is not wide-sense stationary, and the variant with random oscillator phases
  3. 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, eqs. (6) and (7) (the Jakes simulator in the form used here) and its statistics against Clarke's model
  4. P. Dent, G. E. Bottomley and T. Croft, Jakes fading model revisited, Electronics Letters 29(13), 1993, pages 1162 to 1163, the variant with Walsh-Hadamard weights for several uncorrelated waveforms

Where this leads

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