Algorithmcore
Squaring loop
Also called squaring carrier recovery, Mth-power loop.
Raises each M-PSK sample to the power M, which removes the data and leaves a tone at M times the carrier phase. A PLL locks to the tone, and the phase divided by M is correct modulo 2 pi/M.
- Solves
- Carrier recovery
- Time
- O(N log M) worst
- Space
- O(1) extra
- Where
- M = the number of PSK phases; N = the number of symbols
- Model
- Real RAM
- Properties
- deterministicnon data aidedonline
- Evidence
- Proof sketchCode in 1 languages
- Origin
- William C. Lindsey, Marvin K. Simon, 1973
The squaring loop recovers the carrier of a suppressed-carrier signal by removing the modulation with a power law. For BPSK, squaring the sample turns both symbols into , so has a tone at twice the carrier phase. For M-PSK, the power does the same: every symbol satisfies . A phase-locked loop then locks to the tone, and its phase divided by estimates the carrier phase modulo . It is a classic algorithm of carrier recovery. For BPSK it gives exactly the same phase as the Costas loop with the same gains. The Viterbi and Viterbi estimator uses the same power, but averages over a block instead of feeding a loop. Compared with decision-directed carrier recovery, the squaring loop needs no decisions, but the power multiplies noise with noise, which raises the phase variance by the squaring loss. Under strong noise, the loop jumps between its lock points; see cycle slip.
In plain words
A PSK signal moves its phase between a few fixed positions to carry data. The receiver does not know the data, so it cannot simply follow the phase. If you multiply each phase by the number of positions, all the positions fall on top of each other. The data disappear, and what is left is one steady signal whose phase is a multiple of the carrier phase. An ordinary loop can lock onto that. Divide its phase by the same number and you have the carrier phase. The price is twofold. You cannot tell which of the positions is the true one, and the multiplication makes the noise stronger.
The problem
The input is , , one sample per symbol, where is an M-PSK symbol with unknown index and known constellation phase ( for BPSK, for QPSK), so . The noise is , white, and . The loop must output phase estimates from the past samples, with modulo .
The algorithm
SQUARING-LOOP(r[0..N-1], M, Kp, Ki, phase0, phi0)- 1
psi <- M * phi0; s <- 0 ▷ psi tracks M times the carrier phase - 2
for k <- 0 to N - 1 do - 3
est[k] <- psi / M - 4
y <- r[k]^M * exp(-j * M * phase0) ▷ the data are gone: a^M = exp(j M phase0) - 5
e <- Im(y * exp(-j * psi)) ▷ PLL phase detector: sin(M theta - psi) - 6
s <- s + Ki * e - 7
psi <- psi + Kp * e + s - 8
return est
Line L4 is the power law. For QPSK, alone gives , because ; the factor removes this sign. Lines L5 to L7 are the second-order PLL acting on , with detector gain , so its gains come from the PLL design rule for the noise bandwidth of the loop on . Line L3 divides by . In an analog receiver, line L4 is a squarer or an Mth-law device followed by a band-pass filter at times the carrier frequency, and the PLL output is passed through a frequency divider by .
Example
Take QPSK, , a carrier phase rad, no noise and random data (seed 1), with the loop gains for : and . Line L4 gives for every symbol, so line L5 outputs :
| est (line L3) | (line L5) | (line L6) | new (line L7) | ||
|---|---|---|---|---|---|
| 0 | |||||
| 1 | |||||
| 2 |
The start is near the edge of the S-curve, where is small, so the loop moves slowly at first. The error is at , at , at , at , at and at . It stays below from on. For 8-PSK and the same , the start is beyond , and the loop settles at instead.
The noise is amplified by the power. With (exact digital value ), the linear model gives the variance , where the squaring loss is for and for :
| case | squaring loss | predicted variance | measured (40000 symbols) | ratio |
|---|---|---|---|---|
| , 10 dB, seed 1 | ||||
| , 10 dB, seed 2 | ||||
| , 6 dB, seed 3 |
At 3 dB the linear model breaks down. In the same setup with seed 5, the QPSK loop moved between lock points 52 times in 40000 symbols and ended 8 quarter turns away from where it started; at 4 dB it moved 12 times, and at 5 dB not once. These counts are measurements of one simulated run each.
Correctness
Claim. Without noise, line L4 outputs for every M-PSK symbol, so the loop locks to and the estimate to modulo , with the steady-state behavior of the PLL. In the linear model, the variance of the estimate is . For the loop gives the same phase as the BPSK Costas loop.
Key steps. The power maps every symbol to . The noise after the power is a sum of terms , which are uncorrelated, with for circular Gaussian ; the PLL turns a white detector noise of variance into a phase variance , and the division by divides the variance by . For , , the Costas detector. The full proof is in the proofs file.
The variance formula is a closed form under assumptions: the linear model, white Gaussian noise, a constant amplitude and correct symbol timing. The cycle slip counts are measurements.
Proof: The Mth-power loop removes M-PSK data, locks to the carrier phase modulo 2 pi/M, and has the variance (B_L T/M^2) sum C(M,n)^2 n! N0^n in the linear modelfull
The input is , where is an M-PSK symbol with unknown index , is the known phase of the constellation (the argument phase0), , and are independent, with . The loop of lines L5 to L7 is the second-order phase-locked loop acting on , and line L3 outputs . We use the PLL proof for the linear closed loop , the stability conditions and the noise bandwidth .
Lemma 1 (the power removes the data). Without noise, for every .
Proof. .
So line L5 outputs , and the PLL proof applies to with the input phase and detector gain .
Theorem 1 (lock and ambiguity). With gains that satisfy the PLL stability conditions and no noise, the estimate tends to modulo for a constant , and the phase error tends to zero modulo for a frequency step in the linear model.
Proof. The stable lock points of a PLL with the detector are . Dividing by gives . A frequency step on is a frequency step on , which the PLL tracks with zero steady-state error.
The ambiguity is a property of the input, not of the loop: the sequences and give the same , and is again an M-PSK symbol.
Lemma 2 (the noise after the power). At fixed, with
and is circular, so its component along any fixed direction has half this variance. The are independent over .
Proof. The binomial theorem gives the sum. For circular complex Gaussian , for and , since is exponential with mean . The terms of the sum are therefore uncorrelated, and . Each is circular, because a rotation of by rotates by and leaves its law unchanged, so is circular. Independence over follows from the independence of the and the .
Theorem 2 (variance in the linear model). At lock, in the linear model, the carrier phase error has variance
For this is , and for it is .
Proof. Near lock, line L5 outputs . By Lemma 2 and the independence of from the past, the noise term is white with variance . The PLL proof gives the variance of as , and dividing by divides the variance by . For : . For : .
The ratio of to , the variance of a loop that knows the data, is the squaring loss. It is for and grows with , because the power multiplies noise terms with each other.
Lemma 3 (M = 2 is the BPSK Costas loop). For and , equals the phase of the BPSK Costas loop with the same and at every step.
Proof. With and , line L5 is . Write the Costas loop as , , and multiply by 2: it is lines L6 and L7 with and the integrator .
The tests check Lemma 3 sample by sample, Theorem 1 for , and , and Theorem 2 by simulation at 10 dB and 6 dB within a factor of 1.25.
Complexity
Line L4 costs complex multiplications by repeated squaring, or one table lookup on the phase if the amplitude is not needed, and lines L5 to L7 cost . So symbols cost in the real RAM, with extra space. For BPSK and QPSK this is one or two complex squarings per symbol.
Properties
- Non-data-aided. The loop needs no decisions and no known symbols, so it acquires before the receiver can make reliable decisions.
- Squaring loss. The variance is times that of a loop that knows the data. At 10 dB, for BPSK and for QPSK; at 6 dB it is and . It grows fast with and , which limits the method to small or high SNR.
- Ambiguity of . The estimate is correct only modulo , and the loop picks the lock point nearest its start.
- Smaller pull range. The tone has times the frequency offset of the carrier. A frequency offset appears to the PLL as , so the loop must be wider, or the offset smaller, than for an unmodulated carrier.
- Equivalence with Costas for BPSK. With the same gains, the squaring loop and the Costas loop give the same phase for BPSK. Their hardware differs: the squaring loop works at and divides by 2.
Variants and improvements
- Amplitude nonlinearity. Replace by , as in the Viterbi and Viterbi estimator. A smaller weight on the amplitude, for example or for QPSK, reduces the noise times noise terms and lowers the squaring loss at moderate SNR.
- Feedforward form. Average over a block of symbols and take . This is the Viterbi and Viterbi estimator; it needs no acquisition and has no hang-up.
- Costas form. For BPSK, the Costas loop computes the same detector as at the carrier frequency, without a squarer and a divider.
- Decision-directed tracking. After the squaring loop has locked, a decision-directed loop can take over. It has no squaring loss when the decisions are correct.
- QAM. For square QAM, the fourth power does not remove the data, but is a negative real number for square QAM, so the fourth power of QAM samples still has a tone at in the mean. The self noise from the data is large, and the method works only with long averages.
When to use it
Use the squaring loop for continuous BPSK or QPSK when no pilot is present and the SNR is moderate to high, especially in analog or mixed hardware where a squarer and a divider are simple. For 8-PSK and above, the squaring loss is high, and a decision-directed loop is better once lock is reached. For bursts, use the feedforward Viterbi and Viterbi estimator.
Pitfalls
- Forgetting the constellation phase. For QPSK with , points to . Without the factor of line L4, the estimate is off by , a quarter of the ambiguity period, which is the worst place for decisions.
- Dividing the gains by M. The gains of lines L6 and L7 act on , not on the carrier phase. The noise bandwidth of the loop on is also the noise bandwidth of the estimate ; do not scale it by .
- Using the formula at low SNR. The variance formula holds only in the linear model. In the example at 3 dB, slips made the error drift by many quarter turns, and the measured variance was hundreds of times the formula.
- Large frequency offsets. The power multiplies the frequency offset by . A QPSK signal with an offset of 0.05 cycles per symbol gives a tone at 0.2 cycles per symbol, too fast for a narrow loop.
- Unresolved ambiguity. As with every non-data-aided method, the receiver must resolve the ambiguity with a preamble, a unique word or differential encoding.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/squaring-loop/. The authors are listed in prov/PVGB8C.jsonl.
"""The squaring loop and its generalization, the Mth-power loop, for M-PSK.
For an M-PSK symbol a = e^(j(phase0 + 2 pi m / M)), a^M = e^(j M phase0) for every m.
So y = r^M e^(-j M phase0) is a tone with phase M theta plus noise, and an ordinary
second-order PLL locks its phase psi to M theta. The carrier phase estimate is psi / M,
which is correct modulo 2 pi / M.
The loop runs on psi: e = Im(y e^(-j psi)), s <- s + ki e, psi <- psi + kp e + s.
Without noise e = sin(M theta - psi), so the detector gain on psi is 1. For M = 2
and phase0 = 0 the phase estimate equals that of the BPSK Costas loop with the same
gains.
In the linear model, the variance of the carrier phase estimate is
(B_L T / M^2) sum_{n=1}^{M} C(M, n)^2 n! N0^n,
which is B_L T N0 (1 + N0/2) for M = 2 and B_L T N0 (1 + 4.5 N0 + 6 N0^2 + 1.5 N0^3) for M = 4.
"""
import cmath
import math
from typing import Sequence
def loop_gains(bl_t: float, zeta: float = 1.0 / math.sqrt(2.0)) -> tuple[float, float]:
"""(kp, ki) of the loop on psi for the noise bandwidth B_L T and damping zeta."""
wn_t = 2.0 * bl_t / (zeta + 1.0 / (4.0 * zeta))
return 2.0 * zeta * wn_t, wn_t * wn_t
def squaring_loop(r: Sequence[complex], m: int, kp: float, ki: float, phase0: float = 0.0, phi0: float = 0.0) -> list[float]:
"""Run the Mth-power loop on r. Element k is the carrier phase estimate used on r[k]."""
rot = cmath.exp(-1j * m * phase0)
psi = m * phi0 # @line L1
s = 0.0 # @line L1
est = []
for x in r: # @line L2
est.append(psi / m) # @line L3
y = x**m * rot # @line L4
e = (y * cmath.exp(-1j * psi)).imag # @line L5
s += ki * e # @line L6
psi += kp * e + s # @line L7
return est # @line L8
def variance_factor(m: int, n0: float) -> float:
"""sum_{n=1}^{M} C(M, n)^2 n! N0^n / M^2, the phase variance divided by B_L T."""
return sum(math.comb(m, n) ** 2 * math.factorial(n) * n0**n for n in range(1, m + 1)) / (m * m)
test_squaring_loop.py 87 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/squaring-loop/. The authors are listed in prov/PVGB8C.jsonl.
import cmath
import math
import random
from squaring_loop import loop_gains, squaring_loop, variance_factor
def psk_samples(rng, m, phase0, theta, n, n0=0.0):
sd = math.sqrt(n0 / 2)
out = []
for _ in range(n):
a = cmath.exp(1j * (phase0 + 2 * math.pi * rng.randrange(m) / m))
w = complex(rng.gauss(0, sd), rng.gauss(0, sd)) if n0 > 0 else 0j
out.append(a * cmath.exp(1j * theta) + w)
return out
def noise_bandwidth(kp, ki):
b0, b1, a1, a2 = kp + ki, -kp, kp + ki - 2.0, 1.0 - kp
return 0.5 * ((b0 * b0 + b1 * b1) * (1 + a2) - 2 * b0 * b1 * a1) / ((1 - a2) * ((1 + a2) ** 2 - a1 * a1))
def wrap(x, period):
return (x + period / 2) % period - period / 2
def test_m2_equals_the_bpsk_costas_loop() -> None:
rng = random.Random(11)
r = psk_samples(rng, 2, 0.0, 0.7, 3000, n0=0.1)
kp, ki = loop_gains(0.02)
est = squaring_loop(r, 2, kp, ki)
# The Costas recursion written out: e = I Q on z = r e^(-j phi), with the same gains.
phi, s = 0.0, 0.0
for k, x in enumerate(r):
assert abs(est[k] - phi) < 1e-9
z = x * cmath.exp(-1j * phi)
e = z.real * z.imag
s += ki * e
phi += kp * e + s
def test_variance_factor_closed_forms() -> None:
for n0 in (0.01, 0.1, 0.5):
assert abs(variance_factor(2, n0) - n0 * (1 + n0 / 2)) < 1e-15
assert abs(variance_factor(4, n0) - n0 * (1 + 4.5 * n0 + 6 * n0**2 + 1.5 * n0**3)) < 1e-15
def test_lock_without_noise_and_the_ambiguity() -> None:
rng = random.Random(1)
kp, ki = loop_gains(0.02)
for m, phase0 in ((2, 0.0), (4, math.pi / 4), (8, 0.0)):
r = psk_samples(rng, m, phase0, 0.7, 1500)
est = squaring_loop(r, m, kp, ki, phase0)
# The loop locks to theta modulo 2 pi / M, at the lock point nearest the start.
target = 0.7 - 2 * math.pi / m * round(0.7 * m / (2 * math.pi))
assert max(abs(target - p) for p in est[400:]) < 1e-3
assert abs(target - est[-1]) < 1e-9
# For 8-PSK, 0.7 rad is beyond pi/8, so the loop settles at 0.7 - pi/4.
r = psk_samples(rng, 8, 0.0, 0.7, 1500)
assert abs(squaring_loop(r, 8, kp, ki)[-1] - (0.7 - math.pi / 4)) < 1e-9
def test_frequency_offset_without_noise() -> None:
rng = random.Random(2)
kp, ki = loop_gains(0.02)
w = 2 * math.pi * 0.0005
r = [x * cmath.exp(1j * w * k) for k, x in enumerate(psk_samples(rng, 4, math.pi / 4, 0.3, 2500))]
est = squaring_loop(r, 4, kp, ki, math.pi / 4)
assert max(abs(wrap(0.3 + w * k - est[k], math.pi / 2)) for k in range(800, 2500)) < 1e-4
def test_variance_against_the_linear_model() -> None:
# B_L T = 0.01; M = 2 and M = 4 at 10 dB, M = 4 at 6 dB. Factor 1.25 either way.
kp, ki = loop_gains(0.01)
bl = noise_bandwidth(kp, ki)
for m, phase0, snr_db, seed in ((2, 0.0, 10, 1), (4, math.pi / 4, 10, 2), (4, math.pi / 4, 6, 3)):
n0 = 10 ** (-snr_db / 10)
rng = random.Random(seed)
r = psk_samples(rng, m, phase0, 0.2, 40000, n0)
err = [0.2 - p for p in squaring_loop(r, m, kp, ki, phase0)[2000:]]
mean = sum(err) / len(err)
var = sum((e - mean) ** 2 for e in err) / len(err)
assert abs(mean) < 0.01
assert 0.8 < var / (bl * variance_factor(m, n0)) < 1.25
History
Squaring loops appeared with suppressed-carrier transmission in the 1950s and 1960s, as an alternative to the Costas loop of 1956. Both regenerate a carrier from a double-sideband suppressed-carrier signal, and the analyses of the time treated them as equivalent. William Lindsey and Marvin Simon, in their book Telecommunication Systems Engineering (1973) and in papers on suppressed-carrier tracking, expressed the extra phase noise of these loops against a loop with a carrier by one factor, the squaring loss. The Mth-power loop for M-PSK followed with the use of QPSK and 8-PSK on satellite links. In 1983, A. J. Viterbi and A. M. Viterbi turned the same power law into a feedforward block estimator with a nonlinearity on the amplitude.
References
- John G. Proakis and Masoud Salehi, Digital Communications, fifth edition, McGraw-Hill, 2008, Section 5.2-5 (non-decision-directed loops: the squaring loop, the Mth-power loop and the Costas loop, with their squaring losses)
- Umberto Mengali and Aldo N. D'Andrea, Synchronization Techniques for Digital Receivers, Plenum Press, 1997, Chapter 5 (carrier phase recovery with linear modulations, the non-data-aided schemes for PSK)
- Heinrich Meyr, Marc Moeneclaey and Stefan A. Fechtel, Digital Communication Receivers, Wiley, 1998, Chapter 6 (performance analysis of synchronizers, the tracking performance of feedback loops)
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag PVGB8C Edit this page History Report an error Markdown