Algorithm Search⌘K

Definitioncore

Offset QPSK

Also called OQPSK, staggered QPSK.

QPSK with the quadrature stream delayed by half a symbol, so the phase never jumps by 180 degrees and the envelope of the filtered signal stays away from zero.

Offset QPSK (OQPSK) is QPSK in which the quadrature component is delayed by half a symbol period against the in-phase component. The two components then never change at the same instant, so the phase of the signal moves by at most 9090 degrees at a time and never by 180180 degrees. After a band-limiting filter, the envelope of QPSK falls close to zero at each 180180 degree step, while the envelope of OQPSK stays well away from zero. This matters when a nonlinear amplifier would otherwise spread the filtered spectrum again. The spectrum and the error rate in white noise are the same as for QPSK.

Definition

Let TT be the symbol period, g(t)g(t) a real pulse with unit energy, and let the bits be grouped in pairs (b2k,b2k+1)(b_{2k}, b_{2k+1}). Map them to the levels aI,k=(1−2b2k)/2a_{I,k} = (1 - 2b_{2k})/\sqrt2 and aQ,k=(1−2b2k+1)/2a_{Q,k} = (1 - 2b_{2k+1})/\sqrt2, so that each symbol has energy Es=1E_s = 1 and each bit Eb=1/2E_b = 1/2. The offset QPSK signal in complex baseband is

s(t)=∑kaI,k g(t−kT)+j∑kaQ,k g ⁣(t−kT−T2),s(t) = \sum_k a_{I,k}\, g(t - kT) + j \sum_k a_{Q,k}\, g\!\left(t - kT - \frac{T}{2}\right),

where jj is the imaginary unit. On a carrier of frequency fcf_c it is Re{s(t)ej2πfct}\mathrm{Re}\{s(t) e^{j2\pi f_c t}\}. Plain QPSK is the same formula without the delay T/2T/2; it is PSK with 44 points at the phases π/4+kπ/2\pi/4 + k\pi/2.

Properties.

  • No 180 degree steps. With a rectangular pulse of length TT, the in-phase level can change only at t=kTt = kT and the quadrature level only at t=kT+T/2t = kT + T/2. At each instant only one sign flips, which moves the point to a neighbor at ±90\pm 90 degrees. In QPSK both signs can flip at once, which moves the point to the opposite side: a 180180 degree step through the origin.
  • The envelope after filtering. With a smooth pulse, such as a root-raised-cosine filter, a 180180 degree step of QPSK makes the signal pass near 00. In OQPSK one component is at its peak while the other changes, so the envelope stays away from 00 and varies less. A smaller range of the envelope means less regrowth of the spectrum in a nonlinear amplifier.
  • Same spectrum. The two components carry independent data, so the power spectral density is the sum of theirs, and a delay of one component does not change its spectrum. OQPSK has the spectrum of QPSK with the same pulse: ∣G(f)∣2/T|G(f)|^2/T up to a constant.
  • Same error rate. The receiver applies the matched filter and samples the in-phase part at kTkT and the quadrature part at kT+T/2kT + T/2, each after the delay of the filters. With a pulse whose matched pair is a Nyquist pulse, each component is a binary decision in white noise, and the bit error rate is Q(2Eb/N0)Q(\sqrt{2E_b/N_0}), as for QPSK, with QQ the Gaussian Q function.
  • Constant envelope with a half-sine pulse. With g(t)=sin⁡(πt/T)g(t) = \sin(\pi t/T) on 0≤t≤T0 \le t \le T, the two components satisfy sin⁡2+cos⁡2=1\sin^2 + \cos^2 = 1 at every instant, and the signal has a constant amplitude. This is minimum-shift keying, whose bit period is T/2T/2.

The modulator and the receiver

  1. OQPSK-MODULATE(b_0, ..., b_{2N-1}, g, L_s) ▷ L_s even, g the taps of the pulse at L_s per T
  2. 1a_I[k] ← (1 - 2 b_{2k})/√2, a_Q[k] ← (1 - 2 b_{2k+1})/√2
  3. 2s ← Σ_k a_I[k] · g shifted by k·L_s samples
  4. 3s ← s + j · Σ_k a_Q[k] · g shifted by k·L_s + L_s/2 samples ▷ the offset of T/2
  5. 4return s
  6. OQPSK-RECEIVE(r, g, L_s, N)
  7. 5z ← r filtered with the time-reversed taps of g; D ← len(g) - 1
  8. 6b̂_{2k} ← [Re z[k·L_s + D] < 0]
  9. 7b̂_{2k+1} ← [Im z[k·L_s + L_s/2 + D] < 0] ▷ the quadrature part, half a symbol later
  10. 8phase step between the middles of two half-symbol intervals: arg(s[m′] · conj(s[m]))

The tests build both signals with a rectangular pulse and with an RRC pulse at Ls=8L_s = 8, check that OQPSK has only steps of 00 and ±90\pm 90 degrees while QPSK also has steps of 180180 degrees, check the envelope numbers below, and recover the bits through the matched filter.

Examples and non-examples

A sequence by hand. Take the bit pairs 00,11,1000, 11, 10. The levels (times 2\sqrt2) are I=+1,−1,−1I = +1, -1, -1 and Q=+1,−1,+1Q = +1, -1, +1. In QPSK the point goes from (+,+)(+,+) to (−,−)(-,-) at t=Tt = T: a 180180 degree step. In OQPSK, at t=Tt = T only II changes, to (−,+)(-,+), a 9090 degree step; at t=3T/2t = 3T/2 the QQ part changes, to (−,−)(-,-), another 9090 degree step. At t=2Tt = 2T the II part stays at −1-1, and at t=5T/2t = 5T/2 the QQ part changes to +1+1: one more step of 9090 degrees.

Envelope with RRC pulses. With β=0.5\beta = 0.5, Ls=8L_s = 8, filters of 88 symbols on each side, and 15001500 random symbols (seed 77 in the tests), the envelope of QPSK ranges from 0.00160.0016 to 1.461.46 times its rms value, and the envelope of OQPSK from 0.570.57 to 1.401.40 times its rms value. The peaks hardly change; the deep dips of QPSK are gone.

Where it is used. The 2.4 GHz physical layer of IEEE 802.15.4 sends OQPSK with half-sine pulses, which is MSK in another form. The reverse link of IS-95 CDMA used OQPSK so that the handset amplifier could run close to saturation.

Non-example: pi/4-QPSK. This scheme alternates between two QPSK constellations rotated by 4545 degrees, so that every step is ±45\pm 45 or ±135\pm 135 degrees. It also avoids the step through the origin, but both components change at the same instants and there is no offset in time. It is often detected differentially, as in differential phase-shift keying.

Non-example: offset 16-QAM. Delaying the quadrature part of 16-QAM by T/2T/2 (offset QAM) keeps the data rate, but the levels of each component still pass near zero, so the gain in envelope is smaller. It is used in filter-bank multicarrier systems for reasons of orthogonality, not for the envelope.

Code

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.

offset_qpsk.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/offset-qpsk/. The authors are listed in prov/HPEG9T.jsonl.

"""Offset QPSK at L_s samples per symbol: the modulator, the matched-filter receiver, and the
phase steps of the signal.

Bits 2k and 2k+1 give the in-phase and quadrature levels (1 - 2b)/sqrt(2), so E_s = 1 for a
pulse whose taps have unit energy. offset=False gives plain QPSK with the same pulse, for comparison.
L_s must be even, so that the offset of T/2 is L_s/2 samples.
"""

import math


def rrc_taps(beta: float, ls: int, span: int) -> list[float]:
    """Root-raised-cosine taps g(n/ls), |n| <= span*ls, T = 1, scaled to unit energy."""
    g = []
    for n in range(-span * ls, span * ls + 1):
        u = n / ls
        if u == 0:
            v = 1 - beta + 4 * beta / math.pi
        elif abs(abs(4 * beta * u) - 1) < 1e-12:
            a = math.pi / (4 * beta)
            v = beta / math.sqrt(2) * ((1 + 2 / math.pi) * math.sin(a) + (1 - 2 / math.pi) * math.cos(a))
        else:
            v = (math.sin(math.pi * (1 - beta) * u) + 4 * beta * u * math.cos(math.pi * (1 + beta) * u)) / (
                math.pi * u * (1 - (4 * beta * u) ** 2)
            )
        g.append(v)
    e = math.sqrt(sum(v * v for v in g))
    return [v / e for v in g]


def levels(bits: list[int]) -> tuple[list[float], list[float]]:
    """The in-phase and quadrature levels of each symbol."""
    if len(bits) % 2:
        raise ValueError("need an even number of bits")
    s = 1 / math.sqrt(2)
    a_i = [(1 - 2 * b) * s for b in bits[0::2]]  # @line L1
    a_q = [(1 - 2 * b) * s for b in bits[1::2]]
    return a_i, a_q


def modulate(bits: list[int], taps: list[float], ls: int, offset: bool = True) -> list[complex]:
    """sum_k a_I[k] g(t - kT) + j sum_k a_Q[k] g(t - kT - T/2), at ls samples per T."""
    if ls % 2:
        raise ValueError("ls must be even")
    a_i, a_q = levels(bits)
    off = ls // 2 if offset else 0
    out = [0j] * (len(a_i) * ls + len(taps) + off)
    for k, (x, y) in enumerate(zip(a_i, a_q)):
        for n, h in enumerate(taps):
            out[k * ls + n] += x * h  # @line L2
            out[k * ls + off + n] += 1j * y * h  # @line L3
    return out  # @line L4


def demodulate(r: list[complex], taps: list[float], ls: int, nsym: int, offset: bool = True) -> list[int]:
    """Matched filter, then I at kT and Q at kT + T/2 (after the delay of the two filters)."""
    off = ls // 2 if offset else 0
    d = len(taps) - 1

    def matched(m: int) -> complex:
        # The output at sample m of r filtered with the time-reversed taps.
        return sum(r[m - d + n] * h for n, h in enumerate(taps) if 0 <= m - d + n < len(r))  # @line L5

    bits = []
    for k in range(nsym):
        bits.append(1 if matched(k * ls + d).real < 0 else 0)  # @line L6
        bits.append(1 if matched(k * ls + off + d).imag < 0 else 0)  # @line L7
    return bits


def phase_steps(s: list[complex], ls: int, start: int, count: int) -> list[float]:
    """Phase change in degrees between the middles of consecutive half-symbol intervals."""
    half = ls // 2
    mids = [s[start + m * half + half // 2] for m in range(count)]
    steps = []
    for p, q in zip(mids, mids[1:]):
        d = math.degrees(math.atan2((q * p.conjugate()).imag, (q * p.conjugate()).real))  # @line L8
        steps.append(d)
    return steps
test_offset_qpsk.py 79 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/offset-qpsk/. The authors are listed in prov/HPEG9T.jsonl.

import math
import random

from offset_qpsk import demodulate, levels, modulate, phase_steps, rrc_taps

LS = 8


def random_bits(seed: int, n: int) -> list[int]:
    rng = random.Random(seed)
    return [rng.randrange(2) for _ in range(n)]


def test_levels() -> None:
    a_i, a_q = levels([0, 1, 1, 1])
    s = 1 / math.sqrt(2)
    assert a_i == [s, -s] and a_q == [-s, -s]
    assert all(abs(complex(x, y)) == 1.0 or abs(abs(complex(x, y)) - 1) < 1e-15 for x, y in zip(a_i, a_q))


def test_rectangular_oqpsk_never_jumps_by_180_degrees() -> None:
    bits = random_bits(1, 400)
    s = modulate(bits, [1.0] * LS, LS, offset=True)
    nsym = len(bits) // 2
    # Between T/2 and the end of the last I pulse both branches are on, and |s| = 1.
    body = s[LS // 2 : nsym * LS]
    assert max(abs(abs(v) - 1) for v in body) < 1e-12
    steps = phase_steps(s, LS, LS // 2, 2 * nsym - 2)
    assert all(min(abs(d), abs(abs(d) - 90)) < 1e-9 for d in steps)
    assert any(abs(abs(d) - 90) < 1e-9 for d in steps)


def test_rectangular_qpsk_has_180_degree_jumps() -> None:
    bits = random_bits(1, 400)
    s = modulate(bits, [1.0] * LS, LS, offset=False)
    steps = phase_steps(s, LS, 0, len(bits) - 1)
    assert any(abs(abs(d) - 180) < 1e-9 for d in steps)
    assert all(min(abs(d), abs(abs(d) - 90), abs(abs(d) - 180)) < 1e-9 for d in steps)


def test_envelope_with_rrc_pulses() -> None:
    # beta = 0.5, ls = 8, span 8, seed 7, 1500 symbols: QPSK passes near zero, OQPSK does not.
    taps = rrc_taps(0.5, LS, 8)
    bits = random_bits(7, 3000)
    ratios = {}
    for offset in (False, True):
        s = modulate(bits, taps, LS, offset)
        env = [abs(v) for v in s[len(taps) + 50 * LS : (1500 - 50) * LS]]
        rms = math.sqrt(sum(e * e for e in env) / len(env))
        ratios[offset] = (min(env) / rms, max(env) / rms)
    assert ratios[False][0] < 0.05
    assert ratios[True][0] > 0.4
    assert ratios[True][1] < ratios[False][1]


def test_matched_filter_round_trip() -> None:
    taps = rrc_taps(0.35, LS, 8)
    bits = random_bits(3, 400)
    for offset in (False, True):
        r = modulate(bits, taps, LS, offset)
        assert demodulate(r, taps, LS, len(bits) // 2, offset) == bits


def test_no_isi_at_the_sampling_instants() -> None:
    taps = rrc_taps(0.35, LS, 8)
    bits = random_bits(4, 200)
    a_i, a_q = levels(bits)
    r = modulate(bits, taps, LS, True)
    d = len(taps) - 1
    for k in range(20, 80):
        zi = sum(r[k * LS + n] * h for n, h in enumerate(taps))
        zq = sum(r[k * LS + LS // 2 + n] * h for n, h in enumerate(taps))
        # The truncated filters leave a residual ISI below 1% of the level 1/sqrt(2).
        assert abs(zi.real - a_i[k]) < 5e-3
        assert abs(zq.imag - a_q[k]) < 5e-3
    assert d == 128

References

  1. Steven A. Gronemeyer and Alan L. McBride, MSK and offset QPSK modulation, IEEE Transactions on Communications 24(8), 1976, pp. 809 to 820 (offset QPSK and MSK as the same structure with a rectangular and a half-sine pulse, their spectra, and their behavior after band limiting and a hard limiter)
  2. John G. Proakis and Masoud Salehi, Digital Communications, fifth edition, McGraw-Hill, 2008, Chapter 3 (digital modulation schemes, including offset QPSK and its relation to MSK)

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 proofH0 no proof
  • add a proof in proofs/ (06.5)
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)
WritingW4 complete
  • a review of the text: no review record reviews/HPEG9T/text.yaml