Algorithm Search⌘K

Algorithmadvanced

Channel shortening equalizer

Also called time-domain equalizer for DMT, TEQ.

A filter that compresses the channel impulse response to fit within the cyclic prefix of a multicarrier system.

Time
O(L m^2 + K m^3) worst
Space
O(m^2) extra
Where
K = the number of iterations; L = the number of channel taps; m = the number of filter taps (L_w on the page)
Properties
deterministiclinearneeds channel
Origin
David D. Falconer, F. R. Magee, 1973

A channel shortening equalizer, or time-domain equalizer (TEQ), is a short FIR filter ww that the receiver of a multicarrier system puts in front of the DFT. The cyclic prefix of ν\nu samples makes the channel act per subcarrier only when the channel has at most ν+1\nu + 1 taps. Telephone lines in DMT are much longer than any prefix the system can pay for. The TEQ makes the effective channel c=h∗wc = h * w put almost all of its energy into a window of ν+1\nu + 1 consecutive taps. The maximum shortening SNR (MSSNR) design maximizes the energy inside the window over the energy outside it, the wall. This ratio is a generalized Rayleigh quotient, so the best filter is a generalized eigenvector, which inverse iteration finds.

In plain words

A long echo makes each received block leak into the next. The prefix absorbs only a short echo. The TEQ is a filter that cancels most of the echo tail, so that what is left fits in the prefix. It does not try to make the channel flat, as a usual equalizer does. It only makes the channel short, and the per-bin equalizer after the DFT handles the rest. Because only the shape of the channel matters, the design is the filter that puts the largest share of the channel energy inside the window.

The problem

The input is a real channel h0,…,hL−1h_0, \ldots, h_{L-1}, the filter length LwL_w, the prefix length ν\nu and a delay dd. With the convolution matrix H\mathbf{H} of L+Lw−1L + L_w - 1 rows, Hkj=hk−j\mathbf{H}_{kj} = h_{k-j}, the effective channel is c=Hwc = \mathbf{H} w. The window is the set of indices d,…,d+νd, \ldots, d + \nu. Let B\mathbf{B} be the sum of hkhkT\mathbf{h}_k \mathbf{h}_k^T over the rows hk\mathbf{h}_k of H\mathbf{H} inside the window, and A\mathbf{A} the same sum over the rows outside it. The output is the filter that maximizes the shortening SNR

S(w)=∑k=dd+νck2∑k outsideck2=wTBwwTAw,S(w) = \frac{\sum_{k=d}^{d+\nu} c_k^2}{\sum_{k \text{ outside}} c_k^2} = \frac{w^T \mathbf{B} w}{w^T \mathbf{A} w},

and the value of that maximum. The delay is a design parameter. The usual practice is to try every delay.

The algorithm

  1. MSSNR-TEQ(h, Lw, ν, d)
  2. 1A, B ← wall and window matrices of h for the delay d
  3. 2w ← (1, 1, ..., 1)
  4. 3repeat until μ stops changing
  5. 4solve A v = B w
  6. 5w ← v / sqrt(vᵀ B v) ▷ now wᵀ B w = 1
  7. 6μ ← wᵀ A w ▷ the wall energy
  8. 7return w, 1/μ ▷ the filter and its SNR

Line L1 builds the two Lw×LwL_w \times L_w matrices from the rows of the convolution matrix. Lines L4 and L5 are inverse iteration for the pencil A−μB\mathbf{A} - \mu \mathbf{B} with the shift 0, which is the power iteration on A−1B\mathbf{A}^{-1}\mathbf{B}. It converges to the generalized eigenvector with the smallest μ\mu in Aw=μBw\mathbf{A} w = \mu \mathbf{B} w. Line L5 keeps the window energy at 1, so the wall energy in line L6 is 1/S(w)1/S(w). The code then takes up to 3 Rayleigh quotient steps, with the shift μ\mu, and keeps a step only if it does not increase μ\mu.

Example

Take h=(1,0.5)h = (1, 0.5), Lw=2L_w = 2, ν=0\nu = 0 and d=0d = 0, so the window is the single tap c0c_0. The rows of H\mathbf{H} are (1,0)(1, 0), (0.5,1)(0.5, 1) and (0,0.5)(0, 0.5), so

B=(1000),A=(0.250.50.51.25).\mathbf{B} = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}, \qquad \mathbf{A} = \begin{pmatrix} 0.25 & 0.5 \\ 0.5 & 1.25 \end{pmatrix}.

With w0=1w_0 = 1 the wall energy is 0.25+w1+1.25w120.25 + w_1 + 1.25 w_1^2, which is smallest at w1=−0.4w_1 = -0.4, with the value 0.050.05. So w=(1,−0.4)w = (1, -0.4), c=(1,0.1,−0.2)c = (1, 0.1, -0.2), and S=1/0.05=20S = 1/0.05 = 20, or 13.01 dB. Without the TEQ, the window holds c0=1c_0 = 1 and the wall holds 0.520.5^2, so S=4S = 4, or 6.02 dB. The delays d=1d = 1 and d=2d = 2 give only 4.25 and 0.3125, so d=0d = 0 is the best delay.

A longer case: hk=0.8kh_k = 0.8^k for k=0,…,7k = 0, \ldots, 7, with ν=2\nu = 2 and Lw=4L_w = 4. The best window of 3 taps of hh holds 4.99 dB more energy than the wall. The MSSNR filter at the best delay d=0d = 0 is w≈(0.6985,0,0,−0.3285)w \approx (0.6985, 0, 0, -0.3285), and it gives 15.87 dB. The filter is close to 1−0.83z−31 - 0.8^3 z^{-3} times a constant, which cancels the geometric tail of hh after 3 taps: the effective channel is (0.6985,0.5588,0.4470)(0.6985, 0.5588, 0.4470) in the window and at most 0.108 in magnitude outside it.

Correctness

Claim. If A\mathbf{A} is positive definite and the largest generalized eigenvalue λ1\lambda_1 of Bw=λAw\mathbf{B} w = \lambda \mathbf{A} w is simple, the iteration converges to the filter ww that maximizes S(w)S(w) for the delay dd, and 1/μ=S(w)=λ11/\mu = S(w) = \lambda_1.

Key step. With the Cholesky factorization A=RRT\mathbf{A} = \mathbf{R}\mathbf{R}^T and u=RTwu = \mathbf{R}^T w, the ratio S(w)S(w) is the ordinary Rayleigh quotient of the symmetric matrix R−1BR−T\mathbf{R}^{-1} \mathbf{B} \mathbf{R}^{-T}, whose maximum is its largest eigenvalue. The matrix A−1B\mathbf{A}^{-1}\mathbf{B} is similar to it, so the power method on A−1B\mathbf{A}^{-1}\mathbf{B} converges to the right vector, with the error ratio λ2/λ1\lambda_2/\lambda_1 per step. The proofs folder has the details.

Proof: The MSSNR filter is the leading generalized eigenvector of the window and wall matrices, and the iteration converges to itfull

The channel taps are real, h0,…,hL−1h_0, \ldots, h_{L-1}, and the filter is w=(w0,…,wLw−1)w = (w_0, \ldots, w_{L_w-1}). The effective channel is c=h∗wc = h * w, of length L+Lw−1L + L_w - 1. In matrix form c=Hwc = \mathbf{H} w, where H\mathbf{H} has L+Lw−1L + L_w - 1 rows and LwL_w columns, Hkj=hk−j\mathbf{H}_{kj} = h_{k-j} (zero outside 0≤k−j≤L−10 \le k - j \le L - 1). Write hk\mathbf{h}_k for row kk. For the delay dd and the prefix length ν\nu, the window is the set of indices W={d,…,d+ν}W = \{d, \ldots, d + \nu\}, and the wall is the rest. Line L1 computes

B=∑k∈WhkhkT,A=∑k∉WhkhkT.\mathbf{B} = \sum_{k \in W} \mathbf{h}_k \mathbf{h}_k^T, \qquad \mathbf{A} = \sum_{k \notin W} \mathbf{h}_k \mathbf{h}_k^T.

Lemma 1 (energies as quadratic forms). The window energy ∑k∈Wck2\sum_{k \in W} c_k^2 equals wTBww^T \mathbf{B} w, and the wall energy ∑k∉Wck2\sum_{k \notin W} c_k^2 equals wTAww^T \mathbf{A} w. Both matrices are symmetric and positive semidefinite.

Proof. ck=hkTwc_k = \mathbf{h}_k^T w, so ck2=wThkhkTwc_k^2 = w^T \mathbf{h}_k \mathbf{h}_k^T w. Sum over the window or over the wall. Each term is symmetric and positive semidefinite, so the sums are too. □\square

So the shortening SNR of ww is the generalized Rayleigh quotient S(w)=wTBw/wTAwS(w) = w^T \mathbf{B} w / w^T \mathbf{A} w. From here on, A\mathbf{A} is positive definite. This holds when the wall rows have full column rank LwL_w, which is the usual case. If A\mathbf{A} is singular, a nonzero ww puts no energy on the wall, the channel is shortened exactly, and the solve in line L4 fails, which the code reports.

Lemma 2 (the optimum is an eigenvector). Let A=RRT\mathbf{A} = \mathbf{R}\mathbf{R}^T be the Cholesky factorization and C=R−1BR−T\mathbf{C} = \mathbf{R}^{-1} \mathbf{B} \mathbf{R}^{-T}. Then C\mathbf{C} is symmetric and positive semidefinite, with the eigenvalues λ1≥λ2≥⋯≥λLw≥0\lambda_1 \ge \lambda_2 \ge \cdots \ge \lambda_{L_w} \ge 0. The maximum of S(w)S(w) over w≠0w \ne 0 is λ1\lambda_1, and it is reached exactly at the vectors ww with Bw=λ1Aw\mathbf{B} w = \lambda_1 \mathbf{A} w.

Proof. Put u=RTwu = \mathbf{R}^T w, a bijection of the nonzero vectors. Then wTAw=uTuw^T \mathbf{A} w = u^T u and wTBw=uTCuw^T \mathbf{B} w = u^T \mathbf{C} u, so S(w)=uTCu/uTuS(w) = u^T \mathbf{C} u / u^T u, the Rayleigh quotient of C\mathbf{C}. Its maximum is λ1\lambda_1, reached exactly at the eigenvectors of λ1\lambda_1. And Cu=λu\mathbf{C} u = \lambda u is the same as Bw=λAw\mathbf{B} w = \lambda \mathbf{A} w, by multiplying with R\mathbf{R} on the left. □\square

With μ=1/λ\mu = 1/\lambda, the condition is Aw=μBw\mathbf{A} w = \mu \mathbf{B} w, so the optimum is the generalized eigenvector with the smallest μ\mu, and the best shortening SNR is 1/μmin⁡1/\mu_{\min}.

Lemma 3 (the iteration is the power method). Lines L4 and L5 compute w′=Mw/(Mw)TB(Mw)w' = \mathbf{M} w / \sqrt{(\mathbf{M}w)^T \mathbf{B} (\mathbf{M}w)} with M=A−1B\mathbf{M} = \mathbf{A}^{-1}\mathbf{B}. The matrix M\mathbf{M} is similar to C\mathbf{C}, so it has the same real nonnegative eigenvalues and is diagonalizable. If λ1>λ2\lambda_1 > \lambda_2 and the start vector has a nonzero component along the eigenvector of λ1\lambda_1, the direction of ww converges to that eigenvector, and the error shrinks by the factor λ2/λ1\lambda_2/\lambda_1 per step.

Proof. RTMR−T=RTR−TR−1BR−T=C\mathbf{R}^T \mathbf{M} \mathbf{R}^{-T} = \mathbf{R}^T \mathbf{R}^{-T}\mathbf{R}^{-1} \mathbf{B} \mathbf{R}^{-T} = \mathbf{C}. So M=R−TCRT\mathbf{M} = \mathbf{R}^{-T} \mathbf{C} \mathbf{R}^T, and with the eigenvectors uiu_i of C\mathbf{C}, the vectors vi=R−Tuiv_i = \mathbf{R}^{-T} u_i are a basis of eigenvectors of M\mathbf{M}. Write the start vector as ∑iaivi\sum_i a_i v_i. After tt steps, up to a positive scale, w=∑iaiλitvi=λ1t(a1v1+∑i≥2ai(λi/λ1)tvi)w = \sum_i a_i \lambda_i^t v_i = \lambda_1^t \big(a_1 v_1 + \sum_{i \ge 2} a_i (\lambda_i/\lambda_1)^t v_i\big), and the sum over i≥2i \ge 2 goes to zero as (λ2/λ1)t(\lambda_2/\lambda_1)^t. The scaling in line L5 changes only the length. Line L4 is an inverse iteration for the pencil A−μB\mathbf{A} - \mu \mathbf{B} with the shift 0, which is why the smallest μ\mu wins. □\square

Theorem 1 (the output). At the fixed point, line L6 gives μ=wTAw=1/λ1\mu = w^T \mathbf{A} w = 1/\lambda_1, and the returned value 1/μ1/\mu is the shortening SNR of the returned ww and the largest shortening SNR of any filter with LwL_w taps for the delay dd.

Proof. Line L5 makes wTBw=1w^T \mathbf{B} w = 1, so wTAw=1/S(w)w^T \mathbf{A} w = 1/S(w) for every iterate, and 1/μ=S(w)1/\mu = S(w) exactly, even before convergence. At the limit, Bw=λ1Aw\mathbf{B} w = \lambda_1 \mathbf{A} w, so 1=wTBw=λ1wTAw1 = w^T \mathbf{B} w = \lambda_1 w^T \mathbf{A} w and μ=1/λ1\mu = 1/\lambda_1. By Lemma 2 this is the maximum. □\square

Lemma 4 (the polishing steps are safe). The code then takes up to 3 Rayleigh quotient steps, v=(A−μB)−1Bwv = (\mathbf{A} - \mu \mathbf{B})^{-1} \mathbf{B} w, and keeps a step only if the new μ\mu is not larger than the old one (up to a relative 10−910^{-9}). A kept step cannot make the result worse than by that margin, and the result is never above the optimum.

Proof. Every candidate is scaled so that wTBw=1w^T \mathbf{B} w = 1, so its μ\mu is 1/S(w)≥1/λ11/S(w) \ge 1/\lambda_1 by Lemma 2. A kept step therefore leaves S(w)≤λ1S(w) \le \lambda_1 and does not lower S(w)S(w) by more than the margin. Near a simple eigenvalue the Rayleigh quotient iteration converges fast, so these steps remove the last rounding error of the power method. □\square

Lemma 5 (the best delay). best_delay runs the method for every delay dd with 0≤d≤L+Lw−2−ν0 \le d \le L + L_w - 2 - \nu, the delays for which the window lies inside cc, and keeps the largest SNR. By Theorem 1 each run gives the optimum for its delay, so the result is the optimum over all filters and delays.

Theorem 2 (the cost). Line L1 costs O((L+Lw)Lw2)O((L + L_w) L_w^2). Each step of the loop solves an Lw×LwL_w \times L_w system, O(Lw3)O(L_w^3) by Gaussian elimination. With KK steps, a delay costs O((L+Lw)Lw2+KLw3)O((L + L_w) L_w^2 + K L_w^3), and the search over all delays multiplies this by L+Lw−1−νL + L_w - 1 - \nu. The extra space is O(Lw2)O(L_w^2).

Proof. Each of the L+Lw−1L + L_w - 1 rows adds an outer product of size Lw×LwL_w \times L_w to one of the matrices. The rest is counted in the code. A factorization of A\mathbf{A} computed once would make each step O(Lw2)O(L_w^2). □\square

Complexity

In the real RAM, line L1 costs O((L+Lw)Lw2)O((L + L_w) L_w^2), and each step of the loop solves an Lw×LwL_w \times L_w system in O(Lw3)O(L_w^3). With KK steps, one delay costs O(LLw2+KLw3)O(L L_w^2 + K L_w^3), with O(Lw2)O(L_w^2) extra space. If A\mathbf{A} is factored once, each step costs only O(Lw2)O(L_w^2). The number of steps depends on the gap λ2/λ1\lambda_2/\lambda_1. The search over all delays repeats this L+Lw−1−νL + L_w - 1 - \nu times. This is design work, done once per channel estimate. In operation, the TEQ costs LwL_w multiplications per sample.

Properties

  • Optimal for its criterion. For a fixed delay, no filter of LwL_w taps has a larger shortening SNR. In the tests, 2000 random filters for each of 5 random channels (seed 7903) never beat it.
  • Scale free. S(w)S(w) does not change when ww is scaled, so the gain of the filter is free. The per-bin equalizer after the DFT absorbs it.
  • Shape, not flatness. The TEQ does not equalize the window taps. The effective channel inside the window can have any shape, and the frequency-domain equalizer inverts it.
  • Noise is ignored. MSSNR looks only at the channel. It can put deep nulls in the frequency response of ww and so lower the SNR in some bins.
  • Linear and real. The filter is real for a real baseband channel, as in DMT.

Variants and improvements

  • MMSE target impulse response. Choose ww and a target bb of ν+1\nu + 1 taps to minimize E(w∗r−b∗x)2E(w * r - b * x)^2 with a norm constraint on bb. Falconer and Magee used this form in 1973 to cut the channel memory in front of a Viterbi detector, and it is the MMSE TEQ of DMT.
  • Bit rate designs. Al-Dhahir and Cioffi gave finite-length designs for multicarrier receivers, including one that maximizes the geometric mean of the bin SNRs, a proxy for the bit rate. Later designs maximize the bit rate directly.
  • Shortening for MLSE. The same filter can shorten a channel for a Viterbi equalizer, so that the trellis has MνM^{\nu} states instead of ML−1M^{L-1}. Reduced-state sequence estimation is the alternative that keeps the full channel and cuts the trellis.
  • Blind and adaptive TEQs. The filter can be adapted from the received data without a training sequence, by using the redundancy of the prefix.
  • Per-tone equalization. Move the TEQ into the frequency domain, with a few taps per subcarrier, so that each bin gets its own optimal filter.

When to use it

Use a TEQ in a DMT or OFDM receiver when the channel is longer than the prefix and a longer prefix would cost too much throughput, as on ADSL lines. If the prefix already covers the channel, the TEQ is not needed. For single-carrier blocks with a prefix, use frequency-domain equalization, which needs the same condition L−1≤νL - 1 \le \nu.

Pitfalls

  • The delay matters. The best delay can change the shortening SNR by many dB. In the first example, the three delays give 13.01 dB, 6.28 dB and below 0 dB. Search over all delays.
  • A singular wall matrix. If LwL_w is large enough to zero the wall exactly, A\mathbf{A} is singular and the shortening SNR is infinite. The solve in line L4 fails. Use a shorter filter, or solve for the null space of A\mathbf{A}.
  • A singular window matrix. B\mathbf{B} has rank at most ν+1\nu + 1, so it is singular when Lw>ν+1L_w > \nu + 1. Methods that factor B\mathbf{B} fail then. The iteration here factors only A\mathbf{A}.
  • Shortening SNR is not bit rate. A filter with a high shortening SNR can still have deep spectral nulls that ruin some bins. Check the bin SNRs after the design.
  • A bad start vector. The power method needs a start with a component along the best eigenvector. The all-ones start can fail for special channels. Restart with another vector if Bw=0\mathbf{B} w = 0.

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.

channel_shortening_equalizer.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/channel-shortening-equalizer/. The authors are listed in prov/B8R7HN.jsonl.

"""The maximum shortening SNR (MSSNR) channel shortening equalizer.

A multicarrier receiver needs the channel to fit in the cyclic prefix of nu
samples. A time-domain equalizer (TEQ) w of Lw taps makes the effective channel
c = h * w, of length L + Lw - 1. For a delay d, the window is the nu + 1 taps
c[d], ..., c[d + nu], and the wall is the rest. With the full convolution matrix
Hc (Hc[k][j] = h[k - j]), the window energy is w^T B w and the wall energy is
w^T A w, where B and A sum the outer products of the rows of Hc inside and
outside the window. MSSNR (Melsa, Younce and Rohrs) maximizes the shortening
SNR w^T B w / w^T A w, so w is the eigenvector of the pencil A w = mu B w with
the smallest mu. It is found here by inverse iteration, followed by a few
Rayleigh quotient steps. The channel and the filter are real, as in DMT.
"""

import math


def conv_matrix(h: list[float], lw: int) -> list[list[float]]:
    n = len(h) + lw - 1
    return [[h[k - j] if 0 <= k - j < len(h) else 0.0 for j in range(lw)] for k in range(n)]


def window_wall(h: list[float], lw: int, nu: int, d: int) -> tuple[list[list[float]], list[list[float]]]:
    """The matrices A (wall) and B (window) for the delay d."""
    hc = conv_matrix(h, lw)
    if not 0 <= d <= len(hc) - nu - 1:
        raise ValueError("the window must lie inside the effective channel")
    a = [[0.0] * lw for _ in range(lw)]
    b = [[0.0] * lw for _ in range(lw)]
    for k, row in enumerate(hc):
        m = b if d <= k <= d + nu else a
        for i in range(lw):
            for j in range(lw):
                m[i][j] += row[i] * row[j]
    return a, b


def _solve(m: list[list[float]], v: list[float]) -> list[float]:
    n = len(m)
    t = [row[:] + [v[i]] for i, row in enumerate(m)]
    for c in range(n):
        p = max(range(c, n), key=lambda r: abs(t[r][c]))
        if abs(t[p][c]) < 1e-300:
            raise ValueError("singular matrix")
        t[c], t[p] = t[p], t[c]
        for r in range(c + 1, n):
            f = t[r][c] / t[c][c]
            for k in range(c, n + 1):
                t[r][k] -= f * t[c][k]
    x = [0.0] * n
    for r in range(n - 1, -1, -1):
        x[r] = (t[r][n] - sum(t[r][k] * x[k] for k in range(r + 1, n))) / t[r][r]
    return x


def _mv(m: list[list[float]], v: list[float]) -> list[float]:
    return [sum(a * b for a, b in zip(row, v)) for row in m]


def _dot(u: list[float], v: list[float]) -> float:
    return sum(a * b for a, b in zip(u, v))


def mssnr_teq(h: list[float], lw: int, nu: int, d: int, iters: int = 500, tol: float = 1e-15) -> tuple[list[float], float]:
    """The MSSNR filter w (scaled so that w^T B w = 1) and the shortening SNR 1/mu."""
    a, b = window_wall(h, lw, nu, d)  # @line L1
    w = [1.0] * lw  # @line L2
    mu = math.inf
    for _ in range(iters):  # @line L3
        v = _solve(a, _mv(b, w))  # @line L4
        nb = math.sqrt(_dot(v, _mv(b, v)))
        if nb == 0:
            raise ValueError("the window gets no energy")
        w = [x / nb for x in v]  # @line L5
        new = _dot(w, _mv(a, w))  # @line L6
        done = abs(new - mu) <= tol * max(1.0, abs(new))
        mu = new
        if done:
            break
    for _ in range(3):  # Rayleigh quotient steps polish the vector
        try:
            v = _solve([[a[i][j] - mu * b[i][j] for j in range(lw)] for i in range(lw)], _mv(b, w))
        except ValueError:
            break
        nb = math.sqrt(abs(_dot(v, _mv(b, v))))
        if nb == 0 or not math.isfinite(nb):
            break
        cand = [x / nb for x in v]
        new = _dot(cand, _mv(a, cand))
        if new > mu * (1 + 1e-9) + 1e-300:
            break  # never move away from the smallest eigenvalue
        w, mu = cand, new
    if w[max(range(lw), key=lambda i: abs(w[i]))] < 0:
        w = [-x for x in w]
    return w, 1.0 / mu  # @line L7


def shortening_snr(h: list[float], w: list[float], nu: int, d: int) -> float:
    """Window energy over wall energy of c = h * w."""
    c = [0.0] * (len(h) + len(w) - 1)
    for i, x in enumerate(h):
        for j, y in enumerate(w):
            c[i + j] += x * y
    win = sum(v * v for v in c[d:d + nu + 1])
    wall = sum(v * v for v in c) - win
    return win / wall


def best_delay(h: list[float], lw: int, nu: int) -> tuple[int, list[float], float]:
    """Try every delay and keep the one with the largest shortening SNR."""
    best = None
    for d in range(len(h) + lw - 1 - nu):
        try:
            w, s = mssnr_teq(h, lw, nu, d)
        except ValueError:
            continue
        if best is None or s > best[2]:
            best = (d, w, s)
    if best is None:
        raise ValueError("no delay works")
    return best
test_channel_shortening_equalizer.py 132 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/channel-shortening-equalizer/. The authors are listed in prov/B8R7HN.jsonl.

import math
import random

import pytest

from channel_shortening_equalizer import best_delay, mssnr_teq, shortening_snr, window_wall


def mv(m, v):
    return [sum(a * b for a, b in zip(row, v)) for row in m]


def cholesky(a):
    n = len(a)
    r = [[0.0] * n for _ in range(n)]
    for i in range(n):
        for j in range(i + 1):
            s = a[i][j] - sum(r[i][k] * r[j][k] for k in range(j))
            r[i][j] = math.sqrt(s) if i == j else s / r[j][j]
    return r


def jacobi_eigenvalues(s):
    n = len(s)
    a = [row[:] for row in s]
    for _ in range(100):
        off = sum(a[i][j] ** 2 for i in range(n) for j in range(n) if i != j)
        if off < 1e-30:
            break
        for p in range(n):
            for q in range(p + 1, n):
                if abs(a[p][q]) < 1e-300:
                    continue
                theta = (a[q][q] - a[p][p]) / (2 * a[p][q])
                t = (1 if theta >= 0 else -1) / (abs(theta) + math.sqrt(theta * theta + 1))
                c = 1 / math.sqrt(t * t + 1)
                sn = t * c
                for k in range(n):
                    akp, akq = a[k][p], a[k][q]
                    a[k][p], a[k][q] = c * akp - sn * akq, sn * akp + c * akq
                for k in range(n):
                    apk, aqk = a[p][k], a[q][k]
                    a[p][k], a[q][k] = c * apk - sn * aqk, sn * apk + c * aqk
    return [a[i][i] for i in range(n)]


def largest_ssnr(a, b):
    # B w = lambda A w with A = R R^T is the symmetric problem (R^-1 B R^-T) u = lambda u
    n = len(a)
    r = cholesky(a)
    rinv = [[0.0] * n for _ in range(n)]
    for col in range(n):
        for i in range(n):
            s = (1.0 if i == col else 0.0) - sum(r[i][k] * rinv[k][col] for k in range(i))
            rinv[i][col] = s / r[i][i]
    c = [[sum(rinv[i][k] * b[k][l] * rinv[j][l] for k in range(n) for l in range(n)) for j in range(n)] for i in range(n)]
    return max(jacobi_eigenvalues(c))


def test_example_on_the_page() -> None:
    w, s = mssnr_teq([1, 0.5], 2, 0, 0)
    assert abs(w[1] / w[0] + 0.4) < 1e-12
    assert abs(s - 20) < 1e-9
    a, b = window_wall([1, 0.5], 2, 0, 0)
    assert a == [[0.25, 0.5], [0.5, 1.25]] and b == [[1, 0], [0, 0]]
    h = [0.8**k for k in range(8)]
    d, w, s = best_delay(h, 4, 2)
    assert d == 0 and abs(10 * math.log10(s) - 15.87) < 0.005
    base = max(shortening_snr(h, [1.0], 2, k) for k in range(6))
    assert abs(10 * math.log10(base) - 4.99) < 0.005


def test_eigen_residual_and_snr() -> None:
    rng = random.Random(7901)
    for _ in range(30):
        h = [rng.gauss(0, 1) for _ in range(rng.randint(3, 9))]
        lw, nu = rng.randint(2, 6), rng.randint(0, 3)
        d = rng.randint(0, len(h) + lw - 2 - nu)
        a, b = window_wall(h, lw, nu, d)
        try:
            w, s = mssnr_teq(h, lw, nu, d)
        except ValueError:
            continue
        mu = 1 / s
        aw, bw = mv(a, w), mv(b, w)
        assert abs(sum(x * y for x, y in zip(w, bw)) - 1) < 1e-9
        scale = max(1.0, max(abs(x) for x in aw))
        assert max(abs(x - mu * y) for x, y in zip(aw, bw)) < 1e-9 * scale
        assert abs(shortening_snr(h, w, nu, d) - s) < 1e-7 * s


def test_it_is_the_largest_generalized_eigenvalue() -> None:
    rng = random.Random(7902)
    checked = 0
    for _ in range(25):
        h = [rng.gauss(0, 1) for _ in range(rng.randint(4, 8))]
        lw, nu = rng.randint(2, 5), rng.randint(1, 2)
        d = rng.randint(0, len(h) + lw - 2 - nu)
        a, b = window_wall(h, lw, nu, d)
        w, s = mssnr_teq(h, lw, nu, d)
        assert abs(s - largest_ssnr(a, b)) < 1e-8 * s
        checked += 1
    assert checked == 25


def test_beats_random_search() -> None:
    rng = random.Random(7903)
    for _ in range(5):
        h = [rng.gauss(0, 1) for _ in range(7)]
        lw, nu, d = 4, 2, 2
        _, s = mssnr_teq(h, lw, nu, d)
        best = 0.0
        for _ in range(2000):
            w = [rng.gauss(0, 1) for _ in range(lw)]
            best = max(best, shortening_snr(h, w, nu, d))
        assert best <= s * (1 + 1e-12)
        assert best > 0.5 * s  # the search gets close, so the bound is not trivial


def test_best_delay_is_best() -> None:
    h = [0.3, 1, 0.8, 0.5, 0.3, 0.2, 0.1]
    d, _, s = best_delay(h, 3, 2)
    for k in range(len(h) + 3 - 1 - 2):
        assert mssnr_teq(h, 3, 2, k)[1] <= s * (1 + 1e-12)


def test_input_checks() -> None:
    with pytest.raises(ValueError):
        window_wall([1, 0.5], 2, 0, 3)

History

In 1973, Falconer and Magee proposed a prefilter in front of a Viterbi detector, adapted so that the channel seen by the detector has a short desired impulse response, to make maximum likelihood sequence estimation practical on long channels. When DMT was developed for digital subscriber lines, the same idea was used to fit the channel into the cyclic prefix. In 1996, Melsa, Younce and Rohrs gave the maximum shortening SNR design as a generalized eigenvalue problem, and Al-Dhahir and Cioffi gave optimum finite-length designs for multicarrier transceivers.

References

  1. D. D. Falconer and F. R. Magee, Adaptive channel memory truncation for maximum likelihood sequence estimation, Bell System Technical Journal 52(9), 1973, pages 1541 to 1562, a prefilter and a short desired impulse response chosen for the minimum mean squared error, in front of a Viterbi detector
  2. Peter J. W. Melsa, Richard C. Younce and Charles E. Rohrs, Impulse response shortening for discrete multitone transceivers, IEEE Transactions on Communications 44(12), 1996, pages 1662 to 1672, the maximum shortening SNR design as a generalized eigenvalue problem
  3. Naofal Al-Dhahir and John M. Cioffi, Optimum finite-length equalization for multicarrier transceivers, IEEE Transactions on Communications 44(1), 1996, pages 56 to 64, finite-length TEQ designs for multicarrier receivers, including the design that maximizes the geometric SNR

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