Algorithm Search⌘K

Algorithmadvanced

Sato algorithm

Also called Sato blind equalizer.

The first blind equalizer (1975): an LMS update with the error z - gamma sgn(z), gamma = E a^2 / E|a|, for multilevel PAM. A per-axis form works for square QAM.

Time
O(K N) worst
Space
O(N) extra
Where
K = the number of samples; N = the number of equalizer taps
Properties
blinddeterministicnot global convergenceonlinenot phase independent
Origin
Yoichi Sato, 1975

The Sato algorithm is the first blind equalizer, published by Yoichi Sato in 1975 for multilevel PAM. It runs the LMS update of a linear equalizer, but with a made-up target: in place of the unknown symbol, it uses γ sgn(z)\gamma\, \mathrm{sgn}(z), where zz is the equalizer output and γ=Ea2/E∣a∣\gamma = E a^2 / E|a| is a constant of the alphabet. So the equalizer treats every symbol as if it were binary, with the level ±γ\pm\gamma. The error is large while the channel smears the symbols and has mean zero at a perfect equalizer. Like the constant modulus algorithm, it solves the blind equalization problem by a stochastic gradient step that costs O(N)O(N) per sample. The difference is the error. CMA looks only at ∣z∣|z|, so it ignores the carrier phase. Sato looks at the sign of each axis, so for QAM it also turns the output back to the axes of the grid, up to a multiple of 90 degrees. Sato is rarely used today. CMA usually converges more reliably, and the Tong-Xu-Kailath and subspace methods give batch estimates from second-order statistics.

In plain words

A receiver must undo the echoes of a channel without a training sequence. The Sato method pretends that each symbol is either a fixed positive value or the same negative value, chosen by the sign of the equalizer output. It then adjusts the equalizer as if this guess were the truth. The guess is wrong for most symbols of a multilevel signal, but the errors balance out on average when the equalizer is right, and they do not balance while echoes remain. So the equalizer drifts toward the setting that removes the echoes. The fixed value is chosen so that the output has the right size at that point. For a two-dimensional signal, the method does the same on each axis.

The problem

The input is the received sequence y[k]=∑lhl a[k−l]+w[k]y[k] = \sum_l h_l\, a[k-l] + w[k] at one sample per symbol, the number of taps NN and a step size μ>0\mu > 0. The channel hh is unknown. The symbols are independent and identically distributed with a symmetric distribution, for example MM-PAM. The equalizer output is z[k]=∑i=0N−1ci y[k−i]z[k] = \sum_{i=0}^{N-1} c_i\, y[k-i]. The goal is taps cc with z[k]≈±a[k−d]z[k] \approx \pm a[k - d] for some delay dd. For PAM the sign is the only ambiguity, because the cost below is even in zz.

The constant is

γ=Ea2E∣a∣.\gamma = \frac{E a^2}{E|a|}.

For 2-PAM, γ=1\gamma = 1. For the raw 4-PAM levels ±1,±3\pm 1, \pm 3, γ=5/2\gamma = 5/2; for unit-energy 4-PAM, γ=5/2=1.1180\gamma = \sqrt 5 / 2 = 1.1180. For the raw 8-PAM levels ±1,…,±7\pm 1, \ldots, \pm 7, γ=21/4=5.25\gamma = 21/4 = 5.25. For real signals, the algorithm is a stochastic gradient method on J(c)=E[z2/2−γ∣z∣]J(c) = E[z^2/2 - \gamma |z|].

The algorithm

  1. SATO(y, N, μ, γ)
  2. 1c ← (0, ..., 0); c[⌊N/2⌋] ← 1 ▷ the center spike
  3. 2for k ← N - 1 to K - 1 do
  4. 3u ← (y[k], y[k-1], ..., y[k-N+1])
  5. 4z[k] ← Σ_i c[i] u[i]
  6. 5e ← z[k] - γ csgn(z[k]) ▷ csgn(z) = sgn(Re z) + j sgn(Im z)
  7. 6c[i] ← c[i] - μ e conj(u[i]) for all i
  8. 7return c, z

Line L1 starts from a single tap in the middle, so that the equalizer can reach a delay near N/2N/2. Lines L3 and L4 are the filter. Line L5 is the Sato error. For PAM the imaginary parts are zero, csgn(z)=sgn(z)\mathrm{csgn}(z) = \mathrm{sgn}(z), and the error is z−γ sgn(z)z - \gamma\, \mathrm{sgn}(z), the derivative of z2/2−γ∣z∣z^2/2 - \gamma|z|. For square QAM, line L5 applies the PAM rule to each axis, with γ=E[(Re a)2]/E∣Re a∣\gamma = E[(\mathrm{Re}\, a)^2] / E|\mathrm{Re}\, a|. Line L6 is the LMS update with this error. Compared with decision-directed LMS, line L5 replaces the decision by γ\gamma times its sign. Compared with CMA, line L5 replaces z(∣z∣2−R2)z(|z|^2 - R_2).

Example

The constant. For unit-energy 4-PAM, the levels are ±1/5\pm 1/\sqrt 5 and ±3/5\pm 3/\sqrt 5. Then Ea2=1E a^2 = 1 and E∣a∣=2/5E|a| = 2/\sqrt 5, so γ=5/2=1.1180\gamma = \sqrt 5/2 = 1.1180. A symbol a=3/5=1.342a = 3/\sqrt 5 = 1.342 at a perfect equalizer gives the error 1.342−1.118=0.2241.342 - 1.118 = 0.224, and a=1/5=0.447a = 1/\sqrt 5 = 0.447 gives 0.447−1.118=−0.6710.447 - 1.118 = -0.671. The errors are not zero, but their mean times the symbol is 12(1.342×0.224+0.447×(−0.671))=0\frac12 (1.342 \times 0.224 + 0.447 \times (-0.671)) = 0.

4-PAM through h=(1,0.5)h = (1, 0.5). Use N=11N = 11, μ=0.002\mu = 0.002, no noise and seed 2. The residual ISI of the combined response g=c∗hg = c * h falls slowly:

samples 1000 2000 4000 8000
residual ISI 0.222 0.176 0.055 0.0066
largest tap g5g_5 0.888 0.900 0.922 0.973

At the end, the taps (…,0.974,−0.515,0.226,−0.136,…)(\ldots, 0.974, -0.515, 0.226, -0.136, \ldots) from tap 5 on approximate the inverse 1,−0.5,0.25,−0.1251, -0.5, 0.25, -0.125 of the channel, and the last 2000 decisions have no errors.

16-QAM with a carrier phase. Rotate the channel (1,0.3+0.2j)(1, 0.3 + 0.2j) by 25 degrees and run the QAM form with μ=0.0005\mu = 0.0005 for 12000 samples. The largest tap of gg ends at the phase 0.97 degrees: the per-axis sign has turned the output back to the grid. With a rotation of 70 degrees, it ends at 89.7 degrees, which is the grid turned by 90 degrees, a symmetry of square QAM. CMA, on the same input, would keep the rotation.

Correctness

Claim (the perfect equalizer is a fixed point). Let the symbols be independent with a symmetric distribution, with no noise, and let γ=Ea2/E∣a∣\gamma = E a^2 / E|a|. If the combined response is g=±edg = \pm e_d, then the mean update of line L6 is zero. If g=βedg = \beta e_d with β>0\beta > 0 and β≠1\beta \ne 1, it is not zero. This is a theorem, and the tests check it with exact fractions for 4-PAM.

Key step. The mean update is −μE[e uˉ]-\mu E[e\, \bar u], and uu is a linear function of the symbols, so it is enough that E[e a[k−j]]=0E[e\, a[k-j]] = 0 for every jj. With g=βedg = \beta e_d, z=βa[k−d]z = \beta a[k-d] and e=βa[k−d]−γ sgn(a[k−d])e = \beta a[k-d] - \gamma\, \mathrm{sgn}(a[k-d]). For j≠dj \ne d, a[k−j]a[k-j] is independent of ee and has mean zero. For j=dj = d, E[e a]=βEa2−γE∣a∣=(β−1)Ea2E[e\, a] = \beta E a^2 - \gamma E|a| = (\beta - 1) E a^2, which is zero only for β=1\beta = 1. So γ\gamma fixes the output scale. The proofs folder has the details and the gradient form of line L5.

What is not claimed. A fixed point is not always reached. Benveniste, Goursat and Ruget (1980) proved convergence for an equalizer of unbounded length under conditions on the input distribution. For a finite equalizer, convergence to a perfect equalizer is not guaranteed, and Sato, like CMA, can stop at a poor point. The convergence in the example is a measurement.

Proof: The Sato error is a stochastic gradient of a fixed cost, the perfect equalizer is a stationary point of the mean update, and the update is equivariant under a sign flip and under rotations by 90 degreesfull

The symbols a[n]a[n] are independent and identically distributed. For PAM they are real with a symmetric distribution, Ea=0E a = 0, and P(a=0)=0P(a = 0) = 0. There is no noise. The combined response is g=c∗hg = c * h, so the equalizer output is z[n]=∑kgk a[n−k]z[n] = \sum_k g_k\, a[n-k]. The constant is γ=Ea2/E∣a∣\gamma = E a^2 / E|a|. The regressor of line L3 is u=(y[k],…,y[k−N+1])u = (y[k], \ldots, y[k-N+1]), and line L6 adds −μe uˉi-\mu e\, \bar u_i to cic_i, with e=z−γ csgn(z)e = z - \gamma\, \mathrm{csgn}(z) from line L5.

Lemma 1 (the error is a gradient). Let ϕ(z)=∣z∣2/2−γ(∣Re z∣+∣Im z∣)\phi(z) = |z|^2 / 2 - \gamma (|\mathrm{Re}\, z| + |\mathrm{Im}\, z|). At every zz with Re z≠0\mathrm{Re}\, z \ne 0 and Im z≠0\mathrm{Im}\, z \ne 0, the Wirtinger derivative is ∂ϕ/∂zˉ=e/2\partial \phi / \partial \bar z = e / 2. For a fixed uu and z=∑iciuiz = \sum_i c_i u_i, the derivative of ϕ(z)\phi(z) with respect to cˉi\bar c_i is (e/2) uˉi(e/2)\, \bar u_i.

Proof. Write z=x+jyz = x + j y. Then ∂ϕ/∂x=x−γ sgn(x)\partial \phi / \partial x = x - \gamma\, \mathrm{sgn}(x) and ∂ϕ/∂y=y−γ sgn(y)\partial \phi / \partial y = y - \gamma\, \mathrm{sgn}(y). The Wirtinger derivative is 12(∂x+j∂y)ϕ=12(z−γ csgn(z))=e/2\frac12 (\partial_x + j \partial_y)\phi = \frac12 (z - \gamma\, \mathrm{csgn}(z)) = e/2. Since ∂z/∂cˉi=0\partial z / \partial \bar c_i = 0 and ∂zˉ/∂cˉi=uˉi\partial \bar z / \partial \bar c_i = \bar u_i, the chain rule gives (∂ϕ/∂zˉ) uˉi=(e/2) uˉi(\partial \phi / \partial \bar z)\, \bar u_i = (e/2)\, \bar u_i. □\square

So line L6 moves cc by −2μ-2\mu times the derivative of ϕ(z)\phi(z) with respect to cˉ\bar c. For real PAM, ϕ(z)=z2/2−γ∣z∣\phi(z) = z^2/2 - \gamma |z|, and the expected direction of the update is the negative gradient of J(c)=E[z2/2−γ∣z∣]J(c) = E[z^2/2 - \gamma |z|]. The set where zz lies on an axis has probability zero when the input has a continuous part, for example noise, and for discrete inputs line L5 uses sgn(0)=0\mathrm{sgn}(0) = 0 there.

Theorem 1 (the perfect equalizer is stationary). Let aa be real PAM, as above, and let g=βedg = \beta e_d with β≠0\beta \ne 0. Then E[e a[n−j]]=0E[e\, a[n-j]] = 0 for all j≠dj \ne d, and E[e a[n−d]]=(∣β∣−1) sgn(β) Ea2E[e\, a[n-d]] = (|\beta| - 1)\, \mathrm{sgn}(\beta)\, E a^2. So the mean update −μE[e uˉ]-\mu E[e\, \bar u] is zero if and only if β=±1\beta = \pm 1.

Proof. With g=βedg = \beta e_d, z=βa[n−d]z = \beta a[n-d], so sgn(z)=sgn(β) sgn(a[n−d])\mathrm{sgn}(z) = \mathrm{sgn}(\beta)\, \mathrm{sgn}(a[n-d]) and

e=βa[n−d]−γ sgn(β) sgn(a[n−d]).e = \beta a[n-d] - \gamma\, \mathrm{sgn}(\beta)\, \mathrm{sgn}(a[n-d]).

This is a function of a[n−d]a[n-d] only. For j≠dj \ne d, a[n−j]a[n-j] is independent of it and has mean zero, so E[e a[n−j]]=0E[e\, a[n-j]] = 0. For j=dj = d, write a=a[n−d]a = a[n-d]:

E[e a]=βEa2−γ sgn(β) E∣a∣=βEa2−sgn(β) Ea2=sgn(β)(∣β∣−1)Ea2,E[e\, a] = \beta E a^2 - \gamma\, \mathrm{sgn}(\beta)\, E|a| = \beta E a^2 - \mathrm{sgn}(\beta)\, E a^2 = \mathrm{sgn}(\beta)(|\beta| - 1) E a^2,

using γE∣a∣=Ea2\gamma E|a| = E a^2. Now ui=y[k−i]=∑lhl a[k−i−l]u_i = y[k-i] = \sum_l h_l\, a[k-i-l], so E[e uˉi]=∑lhˉl E[e a[k−i−l]]E[e\, \bar u_i] = \sum_l \bar h_l\, E[e\, a[k-i-l]]. If β=±1\beta = \pm 1, every term is zero. If ∣β∣≠1|\beta| \ne 1, only the term with k−i−l=n−dk - i - l = n - d survives, and the vector E[e uˉ]E[e\, \bar u] is a nonzero multiple of the column of the channel convolution matrix that maps cc to gdg_d. That column is not zero, because gd=β≠0g_d = \beta \ne 0 is reachable. □\square

For raw 4-PAM, Ea2=5E a^2 = 5 and E∣a∣=2E|a| = 2, so γ=5/2\gamma = 5/2. With β=9/10\beta = 9/10, Theorem 1 gives E[e a]=−110⋅5=−12E[e\, a] = -\frac{1}{10} \cdot 5 = -\frac12. The test test_the_perfect_equalizer_is_a_stationary_point checks this with exact fractions, and checks that a residual tap of 1/51/5 is not stationary.

If line L5 uses a value γ′\gamma' in place of γ\gamma, the same computation gives the stationary gain ∣β∣=γ′E∣a∣/Ea2=γ′/γ|\beta| = \gamma' E|a| / E a^2 = \gamma' / \gamma. This is the scale error of the first pitfall on the page.

What is not proved. Theorem 1 says that the perfect equalizers are stationary. It does not say that they are the only stationary points, or that the iteration reaches one. Benveniste, Goursat and Ruget (1980) proved convergence for an equalizer of unbounded length under conditions on the input distribution. For a finite equalizer this page makes no convergence claim. The example on the page is a measurement.

Theorem 2 (sign flip). Run lines L1 to L7 on yy and on −y-y with the same NN, μ\mu, γ\gamma and spike. Then the taps are equal at every step and the outputs are negated.

Proof. By induction on kk. Both runs start from the same spike. If c′=cc' = c, then u′=−uu' = -u, z′=−zz' = -z, csgn(z′)=−csgn(z)\mathrm{csgn}(z') = -\mathrm{csgn}(z) and e′=−ee' = -e. The update adds −μe′uˉi′=−μeuˉi-\mu e' \bar u'_i = -\mu e \bar u_i, the same as in the first run. □\square

Theorem 3 (rotation by 90 degrees). Run lines L1 to L7 on yy and on jyj y. Then the taps are equal at every step, and z′=jzz' = j z.

Proof. Multiplying by jj maps x+jyx + jy to −y+jx-y + jx, so csgn(jz)=−sgn(y)+j sgn(x)=j csgn(z)\mathrm{csgn}(j z) = -\mathrm{sgn}(y) + j\, \mathrm{sgn}(x) = j\, \mathrm{csgn}(z). With c′=cc' = c, u′=juu' = j u, z′=jzz' = j z and e′=jee' = j e. The update adds −μe′uˉi′=−μ(je)(−juˉi)=−μeuˉi-\mu e' \bar u'_i = -\mu (j e)(-j \bar u_i) = -\mu e \bar u_i. □\square

For a rotation ejφe^{j\varphi} that is not a multiple of 90 degrees, csgn(ejφz)≠ejφ csgn(z)\mathrm{csgn}(e^{j\varphi} z) \ne e^{j\varphi}\, \mathrm{csgn}(z) in general, so the runs differ. This is why the QAM form, unlike CMA, can remove a carrier phase, but only up to a multiple of 90 degrees, which is the symmetry of square QAM. The test test_qam_form_removes_a_carrier_phase_up_to_90_degrees measures this for rotations of 25 and 70 degrees.

Complexity

Lines L3 to L6 cost O(N)O(N) operations per sample. KK samples cost O(KN)O(K N) time in the real RAM and O(N)O(N) extra space. Line L5 needs only two sign tests, so the algorithm is as cheap as LMS.

Properties

  • Blind. It needs only γ\gamma, which depends on the alphabet and not on the data.
  • A sign ambiguity for PAM. The cost is even in zz, and a negated input gives the same taps and a negated output.
  • Phase sensitive for QAM. The per-axis sign is not invariant under rotation, so the complex taps also remove a carrier phase, up to a multiple of 90 degrees. This needs the phase to be fixed while the equalizer converges; a phase that moves fast spoils the convergence.
  • Never quiet. For MM-PAM with M>2M > 2, the error of line L5 is not zero even at a perfect equalizer, so the taps keep moving around their target, more so for a larger μ\mu.
  • Works on nonminimum-phase channels. The sign is a nonlinear function, so the update uses more than second-order statistics.

Variants and improvements

  • Stop-and-go. Update only when the Sato error and the decision-directed error have the same sign. This makes the steps less noisy.
  • Generalized Sato. Benveniste, Goursat and Ruget replaced the sign by other odd functions and gave conditions for convergence.
  • Switch to decision-directed mode. After the eye opens, replace γ sgn(z)\gamma\, \mathrm{sgn}(z) by the decision; see adaptive equalization.
  • CMA. The constant modulus algorithm replaces the error by z(∣z∣2−R2)z(|z|^2 - R_2), which does not depend on the carrier phase.

When to use it

Use the Sato algorithm for real PAM, or for QAM when the carrier phase is fixed and the equalizer should also remove it. It is a teaching example of how a nonlinear error makes a blind LMS work. In practice, CMA is the usual choice for QAM because it can run before carrier recovery. With a training sequence, a trained LMS or RLS equalizer converges faster.

Pitfalls

  • The wrong scale for γ in line L5. γ\gamma must match the scale of the received signal. With γ\gamma for raw levels and a unit-energy signal, the equalizer still converges, but to taps that scale the output by γraw/γunit\gamma_{\text{raw}} / \gamma_{\text{unit}}, and a fixed slicer then fails.
  • Using the complex form with a moving phase. The QAM form of line L5 needs a fixed phase. If the carrier phase drifts while the taps converge, the taps chase the phase and the residual ISI stays high.
  • A step that is too large in line L6. The error never goes to zero, so a large μ\mu gives a large excess error. Pick a small step, and switch to decision-directed LMS for the final error.
  • A spike at the edge in line L1. As with CMA, a spike on the first tap allows only a small delay, which does not suit a nonminimum-phase channel.

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.

cbb.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the communications pages of https://algorithm.tamnd.com/. The authors are listed in prov/.

"""Complex baseband tools for the communications pages.

Vectors are lists of complex numbers. Matrices are lists of rows. The
functions here are plain building blocks: small linear algebra, convolution,
the DFT as a direct sum, the Gaussian Q function, dB conversion, complex
Gaussian noise and the Wilson score interval. No page algorithm (equalizer,
estimator, synchronizer, detector, precoder, demapper or power allocation)
lives in this file.

Conventions (prompts of the communications area):
- dft is X[k] = sum_n x[n] e^(-j 2 pi k n / N) with no factor; idft has 1/N.
- udft and uidft are the unitary pair, with 1/sqrt(N) on both sides.
- qfunc(x) = 0.5 erfc(x / sqrt(2)); it never computes 1 - Phi(x).
- cn(rng, var) draws CN(0, var): real and imaginary parts are independent
  with variance var / 2 each, so E|w|^2 = var.
"""

import cmath
import math
import random


# ---------------------------------------------------------------- vectors and matrices


def zeros(rows: int, cols: int | None = None) -> list:
    """A zero vector of length rows, or a rows by cols zero matrix."""
    if cols is None:
        return [0j] * rows
    return [[0j] * cols for _ in range(rows)]


def eye(n: int) -> list[list[complex]]:
    """The n by n identity matrix."""
    return [[1 + 0j if i == k else 0j for k in range(n)] for i in range(n)]


def add(a: list, b: list) -> list:
    """Elementwise a + b for two vectors or two matrices of the same shape."""
    if len(a) != len(b):
        raise ValueError("shapes differ")
    if a and isinstance(a[0], list):
        return [add(r, s) for r, s in zip(a, b)]
    return [x + y for x, y in zip(a, b)]


def sub(a: list, b: list) -> list:
    """Elementwise a - b for two vectors or two matrices of the same shape."""
    if len(a) != len(b):
        raise ValueError("shapes differ")
    if a and isinstance(a[0], list):
        return [sub(r, s) for r, s in zip(a, b)]
    return [x - y for x, y in zip(a, b)]


def scale(c: complex, a: list) -> list:
    """The scalar c times a vector or a matrix."""
    if a and isinstance(a[0], list):
        return [scale(c, r) for r in a]
    return [c * x for x in a]


def matmul(a: list[list[complex]], b: list[list[complex]]) -> list[list[complex]]:
    """The matrix product a b."""
    if not a or not b or len(a[0]) != len(b):
        raise ValueError("inner dimensions differ")
    cols = list(zip(*b))
    return [[sum(x * y for x, y in zip(row, col)) for col in cols] for row in a]


def matvec(a: list[list[complex]], x: list[complex]) -> list[complex]:
    """The matrix times vector product a x."""
    if a and len(a[0]) != len(x):
        raise ValueError("inner dimensions differ")
    return [sum(p * q for p, q in zip(row, x)) for row in a]


def herm(a: list) -> list:
    """The conjugate transpose of a matrix. A vector gives its conjugate."""
    if a and isinstance(a[0], list):
        return [[complex(a[i][k]).conjugate() for i in range(len(a))] for k in range(len(a[0]))]
    return [complex(x).conjugate() for x in a]


def dot(x: list[complex], y: list[complex]) -> complex:
    """The inner product x^H y = sum of conj(x_i) y_i."""
    if len(x) != len(y):
        raise ValueError("lengths differ")
    return sum(complex(p).conjugate() * q for p, q in zip(x, y))


def norm2(x: list) -> float:
    """The squared Euclidean norm sum |x_i|^2 (squared Frobenius norm for a matrix)."""
    if x and isinstance(x[0], list):
        return sum(norm2(r) for r in x)
    return sum(abs(v) ** 2 for v in x)


# ---------------------------------------------------------------- linear systems


def _lu(a: list[list[complex]]) -> tuple[list[list[complex]], list[int], int]:
    """LU factorization with partial pivoting. Returns (lu, perm, sign)."""
    n = len(a)
    if any(len(r) != n for r in a):
        raise ValueError("matrix is not square")
    m = [[complex(v) for v in r] for r in a]
    perm = list(range(n))
    sign = 1
    for k in range(n):
        p = max(range(k, n), key=lambda i: abs(m[i][k]))
        if abs(m[p][k]) == 0.0:
            raise ValueError("matrix is singular")
        if p != k:
            m[k], m[p] = m[p], m[k]
            perm[k], perm[p] = perm[p], perm[k]
            sign = -sign
        for i in range(k + 1, n):
            f = m[i][k] / m[k][k]
            m[i][k] = f
            if f != 0:
                rk, ri = m[k], m[i]
                for c in range(k + 1, n):
                    ri[c] -= f * rk[c]
    return m, perm, sign


def _lu_solve(lu: list[list[complex]], perm: list[int], b: list[complex]) -> list[complex]:
    n = len(lu)
    y = [complex(b[perm[i]]) for i in range(n)]
    for i in range(n):
        for c in range(i):
            y[i] -= lu[i][c] * y[c]
    for i in range(n - 1, -1, -1):
        for c in range(i + 1, n):
            y[i] -= lu[i][c] * y[c]
        y[i] /= lu[i][i]
    return y


def solve(a: list[list[complex]], b: list) -> list:
    """Solve a x = b by Gaussian elimination with partial pivoting.

    b is a vector, or a matrix whose columns are right-hand sides.
    Raises ValueError if a is singular.
    """
    lu, perm, _ = _lu(a)
    if b and isinstance(b[0], list):
        cols = [list(c) for c in zip(*b)]
        xs = [_lu_solve(lu, perm, c) for c in cols]
        return [list(r) for r in zip(*xs)]
    if len(b) != len(a):
        raise ValueError("lengths differ")
    return _lu_solve(lu, perm, b)


def inv(a: list[list[complex]]) -> list[list[complex]]:
    """The inverse of a square matrix."""
    return solve(a, eye(len(a)))


def det(a: list[list[complex]]) -> complex:
    """The determinant of a square matrix (0 for a singular matrix)."""
    try:
        lu, _, sign = _lu(a)
    except ValueError as e:
        if "singular" in str(e):
            return 0j
        raise
    d = complex(sign)
    for i in range(len(lu)):
        d *= lu[i][i]
    return d


def cholesky(a: list[list[complex]]) -> list[list[complex]]:
    """The lower triangular L with a = L L^H, for a Hermitian positive definite a.

    Raises ValueError if a is not positive definite (to rounding).
    """
    n = len(a)
    low = zeros(n, n)
    for i in range(n):
        for k in range(i + 1):
            s = complex(a[i][k]) - sum(low[i][c] * low[k][c].conjugate() for c in range(k))
            if i == k:
                if s.real <= 0.0:
                    raise ValueError("matrix is not positive definite")
                low[i][i] = complex(math.sqrt(s.real))
            else:
                low[i][k] = s / low[k][k].real
    return low


# ---------------------------------------------------------------- convolution and the DFT


def conv(a: list[complex], b: list[complex]) -> list[complex]:
    """Linear convolution, of length len(a) + len(b) - 1."""
    if not a or not b:
        return []
    out = [0j] * (len(a) + len(b) - 1)
    for i, x in enumerate(a):
        for k, y in enumerate(b):
            out[i + k] += x * y
    return out


def cconv(a: list[complex], b: list[complex], n: int | None = None) -> list[complex]:
    """Circular convolution of length n (default: the longer length).

    Both inputs are padded with zeros to length n, or must not be longer than n.
    """
    if n is None:
        n = max(len(a), len(b))
    if len(a) > n or len(b) > n:
        raise ValueError("input longer than n")
    out = [0j] * n
    for i, x in enumerate(a):
        for k, y in enumerate(b):
            out[(i + k) % n] += x * y
    return out


def _twiddles(n: int, sign: int) -> list[complex]:
    return [cmath.exp(sign * 2j * math.pi * t / n) for t in range(n)]


def dft(x: list[complex]) -> list[complex]:
    """X[k] = sum over n of x[n] e^(-j 2 pi k n / N), as a direct O(N^2) sum."""
    n = len(x)
    w = _twiddles(n, -1)
    return [sum(x[t] * w[(k * t) % n] for t in range(n)) for k in range(n)]


def idft(xf: list[complex]) -> list[complex]:
    """x[n] = (1/N) sum over k of X[k] e^(j 2 pi k n / N), the inverse of dft."""
    n = len(xf)
    w = _twiddles(n, 1)
    return [sum(xf[k] * w[(k * t) % n] for k in range(n)) / n for t in range(n)]


def udft(x: list[complex]) -> list[complex]:
    """The unitary DFT: dft(x) / sqrt(N)."""
    s = 1.0 / math.sqrt(len(x)) if x else 1.0
    return [v * s for v in dft(x)]


def uidft(xf: list[complex]) -> list[complex]:
    """The unitary inverse DFT: sqrt(N) idft(X), the inverse of udft."""
    s = math.sqrt(len(xf)) if xf else 1.0
    return [v * s for v in idft(xf)]


# ---------------------------------------------------------------- Q function and dB


def qfunc(x: float) -> float:
    """Q(x) = P(Z > x) for a standard normal Z, computed as 0.5 erfc(x / sqrt(2))."""
    return 0.5 * math.erfc(x / math.sqrt(2.0))


def qinv(p: float) -> float:
    """The x with Q(x) = p, for 0 < p < 1, by bisection on Q (which decreases)."""
    if not 0.0 < p < 1.0:
        raise ValueError("p must be in (0, 1)")
    lo, hi = -40.0, 40.0
    for _ in range(200):
        mid = 0.5 * (lo + hi)
        if qfunc(mid) > p:
            lo = mid
        else:
            hi = mid
        if hi - lo <= 1e-15 * max(1.0, abs(mid)):
            break
    return 0.5 * (lo + hi)


def db(x: float) -> float:
    """10 log10(x), for a ratio of powers or energies."""
    return 10.0 * math.log10(x)


def undb(d: float) -> float:
    """10^(d / 10), the inverse of db."""
    return 10.0 ** (d / 10.0)


# ---------------------------------------------------------------- noise and statistics


def cn(rng: random.Random, var: float) -> complex:
    """One sample of CN(0, var): independent real and imaginary parts of variance var / 2."""
    s = math.sqrt(var / 2.0)
    return complex(rng.gauss(0.0, s), rng.gauss(0.0, s))


def awgn(rng: random.Random, x: list[complex], n0: float) -> list[complex]:
    """x plus independent CN(0, n0) noise on each sample."""
    return [v + cn(rng, n0) for v in x]


def wilson(k: int, n: int, z: float = 3.29) -> tuple[float, float]:
    """The Wilson score interval for k successes in n trials (z = 3.29 is about 0.999 two-sided)."""
    if n <= 0 or not 0 <= k <= n:
        raise ValueError("need 0 <= k <= n and n > 0")
    p = k / n
    z2 = z * z
    den = 1.0 + z2 / n
    mid = (p + z2 / (2 * n)) / den
    half = z * math.sqrt(p * (1 - p) / n + z2 / (4 * n * n)) / den
    return max(0.0, mid - half), min(1.0, mid + half)
sato_algorithm.py 51 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sato-algorithm/. The authors are listed in prov/2220NN.jsonl.

"""The Sato blind equalizer for PAM, and its form for square QAM.

The equalizer is an FIR filter c of N taps with output
z[k] = sum_i c[i] y[k-i]. The Sato error is e = z - gamma sgn(z), with the
constant gamma = E a^2 / E|a| of the PAM alphabet. The update is the LMS step
c <- c - mu e conj(u). It is a stochastic gradient step on the cost
J(c) = E[z^2 / 2 - gamma |z|] for real signals.

For square QAM, the same rule runs on the real and the imaginary parts:
csgn(z) = sgn(Re z) + j sgn(Im z), and gamma = E[(Re a)^2] / E|Re a|.
For real PAM the imaginary parts are 0 and the two forms agree.
"""


def _sgn(v: float) -> float:
    return 1.0 if v > 0 else (-1.0 if v < 0 else 0.0)


def csgn(z: complex) -> complex:
    """sgn(Re z) + j sgn(Im z), with sgn(0) = 0."""
    z = complex(z)
    return complex(_sgn(z.real), _sgn(z.imag))


def sato_gamma(levels: list[float]) -> float:
    """gamma = E a^2 / E|a| for equally likely real levels (one axis of PAM or square QAM)."""
    m1 = sum(abs(v) for v in levels)
    if m1 == 0:
        raise ValueError("all levels are zero")
    return sum(v * v for v in levels) / m1


def sato(y: list[complex], n: int, mu: float, gamma: float, spike: int | None = None) -> tuple[list[complex], list[complex]]:
    """Run the Sato algorithm over y. Returns the final taps and the outputs z[k] for k = N-1, ..., len(y)-1."""
    if n < 1 or mu <= 0 or gamma <= 0:
        raise ValueError("need N >= 1, mu > 0 and gamma > 0")
    if spike is None:
        spike = n // 2
    c = [0j] * n  # @line L1
    c[spike] = 1 + 0j  # @line L1
    out = []
    for k in range(n - 1, len(y)):  # @line L2
        u = [complex(y[k - i]) for i in range(n)]  # @line L3
        z = sum(ci * ui for ci, ui in zip(c, u))  # @line L4
        e = z - gamma * csgn(z)  # @line L5
        c = [ci - mu * e * ui.conjugate() for ci, ui in zip(c, u)]  # @line L6
        out.append(z)
    return c, out  # @line L7
test_sato_algorithm.py 112 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/sato-algorithm/. The authors are listed in prov/2220NN.jsonl.

import cmath
import itertools
import math
import random
from fractions import Fraction

import pytest

import cbb
from sato_algorithm import csgn, sato, sato_gamma

PAM4 = [v / math.sqrt(5) for v in (-3, -1, 1, 3)]
QAM16 = [complex(a, b) / math.sqrt(10) for a in (-3, -1, 1, 3) for b in (-3, -1, 1, 3)]


def test_gamma_check_values() -> None:
    assert sato_gamma([-1, 1]) == 1.0
    assert sato_gamma([-3, -1, 1, 3]) == 2.5
    assert sato_gamma([-7, -5, -3, -1, 1, 3, 5, 7]) == 5.25
    assert abs(sato_gamma(PAM4) - math.sqrt(5) / 2) < 1e-12  # 1.1180 for unit-energy 4-PAM


def mean_error_times_symbols(g, levels, gamma):
    # E[e a_j] for each j, with z = sum_j g_j a_j and e = z - gamma sgn(z), by exact enumeration
    acc = [Fraction(0)] * len(g)
    count = 0
    for a in itertools.product(levels, repeat=len(g)):
        z = sum(gi * ai for gi, ai in zip(g, a))
        e = z - gamma * (1 if z > 0 else (-1 if z < 0 else 0))
        for j in range(len(g)):
            acc[j] += e * a[j]
        count += 1
    return [v / count for v in acc]


def test_the_perfect_equalizer_is_a_stationary_point() -> None:
    levels = [-3, -1, 1, 3]
    gamma = Fraction(5, 2)
    # g = e_1: the mean update E[e conj(u)] = H^* E[e a] is zero
    assert mean_error_times_symbols([0, 1, 0], levels, gamma) == [0, 0, 0]
    assert mean_error_times_symbols([0, -1, 0], levels, gamma) == [0, 0, 0]
    # a wrong gain or a residual tap is not stationary
    assert mean_error_times_symbols([0, Fraction(9, 10), 0], levels, gamma)[1] == Fraction(-1, 2)
    assert any(v != 0 for v in mean_error_times_symbols([Fraction(1, 5), 1, 0], levels, gamma))


def test_error_is_the_derivative_of_the_cost() -> None:
    # J(z) = |z|^2 / 2 - gamma (|Re z| + |Im z|); dJ / d conj(z) = e / 2 away from the axes
    gamma = 0.8
    rng = random.Random(1)
    for _ in range(20):
        z = complex(rng.uniform(-2, 2), rng.uniform(-2, 2))
        cost = lambda v: abs(v) ** 2 / 2 - gamma * (abs(v.real) + abs(v.imag))
        eps = 1e-6
        dx = (cost(z + eps) - cost(z - eps)) / (2 * eps)
        dy = (cost(z + 1j * eps) - cost(z - 1j * eps)) / (2 * eps)
        assert abs(0.5 * complex(dx, dy) - (z - gamma * csgn(z)) / 2) < 1e-8


def run(h, points, n, mu, k, n0, seed, rot=1):
    rng = random.Random(seed)
    x = [rng.choice(points) for _ in range(k)]
    y = [rot * v for v in cbb.conv(x, h)[:k]]
    if n0 > 0:
        y = cbb.awgn(rng, y, n0)
    gamma = sato_gamma([p.real for p in points])
    c, z = sato(y, n, mu, gamma)
    g = cbb.conv(c, [rot * v for v in h])
    return x, c, z, g


def test_4pam_through_a_known_channel() -> None:
    n = 11
    x, c, z, g = run([1, 0.5], PAM4, n, 0.002, 8000, 0.0, 2)
    p = [abs(v) ** 2 for v in g]
    d = max(range(len(g)), key=lambda i: p[i])
    assert (sum(p) - p[d]) / p[d] < 0.01
    sign = 1 if g[d].real > 0 else -1
    errors = sum(min(PAM4, key=lambda q: abs(z[t] * sign - q)) != x[t + n - 1 - d] for t in range(len(z) - 2000, len(z)))
    assert errors == 0


def test_sign_flip_gives_the_same_taps() -> None:
    rng = random.Random(3)
    x = [rng.choice(PAM4) for _ in range(500)]
    y = cbb.conv(x, [1, 0.4])[:500]
    c1, z1 = sato(y, 7, 0.003, sato_gamma(PAM4))
    c2, z2 = sato([-v for v in y], 7, 0.003, sato_gamma(PAM4))
    assert max(abs(u - v) for u, v in zip(c1, c2)) < 1e-12
    assert max(abs(u + v) for u, v in zip(z1, z2)) < 1e-12


def test_qam_form_removes_a_carrier_phase_up_to_90_degrees() -> None:
    # unlike CMA, the per-axis sign brings the output back to the axes of the grid
    for rot_deg in (25, 70):
        rot = cmath.exp(1j * math.radians(rot_deg))
        x, c, z, g = run([1, 0.3 + 0.2j], QAM16, 11, 0.0005, 12000, 0.0, 4, rot)
        d = max(range(len(g)), key=lambda i: abs(g[i]))
        ph = math.degrees(cmath.phase(g[d])) % 90
        assert min(ph, 90 - ph) < 3


def test_bad_input() -> None:
    with pytest.raises(ValueError):
        sato([1, 2], 0, 0.01, 1.0)
    with pytest.raises(ValueError):
        sato([1, 2], 2, 0.01, 0.0)
    with pytest.raises(ValueError):
        sato_gamma([0, 0])

History

Yoichi Sato published the method in 1975 as self-recovering equalization of multilevel amplitude modulation. It was the first blind equalizer. Benveniste, Goursat and Ruget (1980) generalized the error function and studied convergence for an equalizer of unbounded length. Godard (1980) gave the dispersion criteria that led to CMA, which replaced Sato in most QAM receivers.

References

  1. Yoichi Sato, A method of self-recovering equalization for multilevel amplitude-modulation systems, IEEE Transactions on Communications 23(6), 1975, pages 679 to 682, the error z - gamma sgn(z) and the self-recovering adjustment of a linear equalizer
  2. Albert Benveniste, Maurice Goursat and Gabriel Ruget, Robust identification of a nonminimum phase system: blind adjustment of a linear equalizer in data communications, IEEE Transactions on Automatic Control 25(3), 1980, pages 385 to 399, the generalization of the Sato algorithm and its convergence for an equalizer of unbounded length
  3. C. Richard Johnson, Jr., Philip Schniter, Thomas J. Endres, James D. Behm, Donald R. Brown and Raul A. Casas, Blind equalization using the constant modulus criterion: a review, Proceedings of the IEEE 86(10), 1998, starting at page 1927, the background on Bussgang-type blind equalizers, of which Sato is one
  4. John G. Proakis and Masoud Salehi, Digital Communications, fifth edition, McGraw-Hill, 2008, Chapter 10 (adaptive equalization), the section on blind equalization

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