Algorithm Search⌘K

Definitionintro

Raised-cosine filter

Also called raised-cosine pulse.

A Nyquist pulse whose spectrum is flat in the middle and falls off as half a cosine period. The roll-off beta sets the excess bandwidth, from 0 (a sinc) to 1 (twice the minimum).

The raised-cosine filter is the pulse h(t)h(t) whose spectrum is flat up to (1−β)/(2T)(1 - \beta)/(2T) and then falls to zero at (1+β)/(2T)(1 + \beta)/(2T) along half a period of a cosine raised above zero. Its folded spectrum is flat, so by the Nyquist ISI criterion it is zero at every nonzero multiple of the symbol period TT and causes no intersymbol interference. The roll-off factor β∈[0,1]\beta \in [0, 1] trades bandwidth for a faster decay in time. In practice the raised cosine is the overall response of a link, split into two root-raised-cosine filters, one at the transmitter and one at the receiver.

Definition

Let T>0T > 0 be the symbol period and β∈[0,1]\beta \in [0, 1] the roll-off factor, and let sinc(x)=sin⁡(πx)/(πx)\mathrm{sinc}(x) = \sin(\pi x)/(\pi x) with sinc(0)=1\mathrm{sinc}(0) = 1. The raised-cosine spectrum is

H(f)={T,∣f∣≤1−β2T,T2[1+cos⁡ ⁣(πTβ(∣f∣−1−β2T))],1−β2T<∣f∣≤1+β2T,0,∣f∣>1+β2T,H(f) = \begin{cases} T, & |f| \le \dfrac{1 - \beta}{2T}, \\[2mm] \dfrac{T}{2}\left[1 + \cos\!\left(\dfrac{\pi T}{\beta}\left(|f| - \dfrac{1 - \beta}{2T}\right)\right)\right], & \dfrac{1 - \beta}{2T} < |f| \le \dfrac{1 + \beta}{2T}, \\[2mm] 0, & |f| > \dfrac{1 + \beta}{2T}, \end{cases}

and the raised-cosine pulse is its inverse Fourier transform,

h(t)=sinc ⁣(tT)cos⁡(πβt/T)1−(2βt/T)2.h(t) = \mathrm{sinc}\!\left(\frac{t}{T}\right) \frac{\cos(\pi \beta t / T)}{1 - (2 \beta t / T)^2}.

At t=±T/(2β)t = \pm T/(2\beta) the fraction is 0/00/0; the limit, and the value of hh there, is (π/4) sinc(1/(2β))(\pi/4)\, \mathrm{sinc}(1/(2\beta)). For β=0\beta = 0 the pulse is sinc(t/T)\mathrm{sinc}(t/T). A raised-cosine filter is a linear filter with impulse response h(t)h(t), or in discrete time an FIR filter with taps h(nT/Ls)h(nT/L_s) for ∣n∣≤SLs|n| \le S L_s, where LsL_s is the number of samples per symbol and SS the span in symbols on each side.

Why the formula in time. HH is the convolution of the rectangle T 1{∣f∣<1/(2T)}T\,\mathbf{1}\{|f| < 1/(2T)\} with the half-cosine bump Q(f)=(πT/(2β))cos⁡(πTf/β)Q(f) = (\pi T / (2\beta)) \cos(\pi T f/\beta) on ∣f∣≤β/(2T)|f| \le \beta/(2T), which has area 11. Convolving with a bump of area 11 keeps the flat part at TT and turns each edge of the rectangle into the integral of the bump, which is the raised cosine edge. In time, convolution becomes a product: the rectangle gives sinc(t/T)\mathrm{sinc}(t/T), and the bump gives ∫Q(f)ej2πftdf=cos⁡(πβt/T)/(1−(2βt/T)2)\int Q(f) e^{j 2\pi f t} df = \cos(\pi\beta t/T)/(1 - (2\beta t/T)^2).

Properties.

  • No ISI. h(0)=1h(0) = 1 and h(kT)=0h(kT) = 0 for every integer k≠0k \ne 0, because the factor sinc(t/T)\mathrm{sinc}(t/T) is zero there. (At kT=±T/(2β)kT = \pm T/(2\beta), which happens for β=1/2\beta = 1/2 at k=±1k = \pm 1, the value (π/4) sinc(k)(\pi/4)\,\mathrm{sinc}(k) is 00 too.) In frequency: the edge satisfies H(1/(2T)−x)+H(1/(2T)+x)=TH(1/(2T) - x) + H(1/(2T) + x) = T for 0≤x≤β/(2T)0 \le x \le \beta/(2T), since cos⁡(π/2−y)+cos⁡(π/2+y)=0\cos(\pi/2 - y) + \cos(\pi/2 + y) = 0, so the fold is the constant TT.
  • Bandwidth. The spectrum is zero for ∣f∣>(1+β)/(2T)|f| > (1 + \beta)/(2T). The baseband bandwidth is (1+β)/(2T)(1 + \beta)/(2T); the bandwidth of the passband signal on a carrier is twice that, (1+β)/T(1 + \beta)/T. The excess bandwidth over the Nyquist minimum 1/(2T)1/(2T) is the fraction β\beta.
  • Decay. For β>0\beta > 0 and large ∣t∣|t|, ∣h(t)∣≤T3/(π ∣t∣ (4β2t2−T2))|h(t)| \le T^3/(\pi\, |t|\,(4\beta^2 t^2 - T^2)), which falls like 1/∣t∣31/|t|^3. The sinc (β=0\beta = 0) falls only like 1/∣t∣1/|t|.
  • Energy. By Parseval, ∫h2 dt=∫H2 df=T(1−β/4)\int h^2\, dt = \int H^2\, df = T(1 - \beta/4).

Computing the pulse

The function below returns the pulse, with the limit at the two singular points. The filter taps are its values at t=nT/Lst = nT/L_s.

  1. RC-PULSE(t, β, T) ▷ the raised-cosine pulse h(t)
  2. 1u ← t / T
  3. 2if β > 0 and |2βu| = 1 then
  4. 3return (π/4) · sinc(1 / (2β)) ▷ the limit at t = ±T/(2β)
  5. 4return sinc(u) · cos(πβu) / (1 - (2βu)²)
  6. RC-TAPS(β, L_s, S) ▷ T = 1, L_s samples per symbol, S symbols on each side
  7. 5return [RC-PULSE(n / L_s, β, 1) for n = -S·L_s, ..., S·L_s]

The implementation also gives H(f)H(f). Its tests check the values on this page, the zeros at kTkT for several β\beta, the flat fold, the energy T(1−β/4)T(1 - \beta/4) in time and in frequency, and the continuity at t=±T/(2β)t = \pm T/(2\beta).

Examples and non-examples

Check values. For β=0.5\beta = 0.5 and T=1T = 1: h(0.5)=sinc(0.5)cos⁡(π/4)/(1−0.25)=(2/π)(0.70711)/0.75=0.60021h(0.5) = \mathrm{sinc}(0.5) \cos(\pi/4)/(1 - 0.25) = (2/\pi)(0.70711)/0.75 = 0.60021, h(1)=0h(1) = 0, and h(1.5)=−0.12004h(1.5) = -0.12004. For β=0.25\beta = 0.25: h(0.5)=0.62737h(0.5) = 0.62737 and h(1.5)=−0.18562h(1.5) = -0.18562. The baseband bandwidth for β=0.25\beta = 0.25 and T=1T = 1 is 1.25/2=0.6251.25/2 = 0.625 Hz.

The fold at one frequency. For β=0.5\beta = 0.5 and T=1T = 1, the edge runs from 0.250.25 to 0.750.75. At f=0.4f = 0.4, H(0.4)=12[1+cos⁡(0.3π)]=0.79389H(0.4) = \tfrac12[1 + \cos(0.3\pi)] = 0.79389, and its partner H(0.4−1)=H(0.6)=12[1+cos⁡(0.7π)]=0.20611H(0.4 - 1) = H(0.6) = \tfrac12[1 + \cos(0.7\pi)] = 0.20611. The sum is 1=T1 = T.

Full roll-off. For β=1\beta = 1 the pulse is sinc(t/T)cos⁡(πt/T)/(1−4t2/T2)=sinc(2t/T)/(1−4t2/T2)\mathrm{sinc}(t/T)\cos(\pi t/T)/(1 - 4t^2/T^2) = \mathrm{sinc}(2t/T)/(1 - 4t^2/T^2). Besides the zeros at kTkT, it is zero at ±3T/2,±5T/2,…\pm 3T/2, \pm 5T/2, \ldots, and h(±T/2)=1/2h(\pm T/2) = 1/2. Zero crossings halfway between the symbols make the timing easy to track, at the cost of twice the minimum bandwidth.

Decay in numbers. The largest ∣h(t)∣|h(t)| over 10T≤t≤11T10T \le t \le 11T is 0.03030.0303 for β=0\beta = 0, 4.79×10−44.79 \times 10^{-4} for β=0.25\beta = 0.25, and 2.21×10−42.21 \times 10^{-4} for β=0.5\beta = 0.5. A filter truncated to 88 symbols on each side loses little for β≥0.25\beta \ge 0.25, and much for the sinc.

Bandwidth of a link. QPSK at 11 million symbols per second with β=0.25\beta = 0.25 occupies 1.251.25 MHz around the carrier and carries 22 Mbit/s, a spectral efficiency of 2/1.25=1.62/1.25 = 1.6 bits/s/Hz.

Non-example: one root-raised-cosine filter. The root-raised-cosine filter has the spectrum H(f)\sqrt{H(f)}. Its folded spectrum is not flat on the edge, so a single RRC pulse has ISI: for β=0.5\beta = 0.5, its value at t=Tt = T is −0.0934-0.0934 times its peak. Only the cascade of two RRC filters is a raised cosine.

Non-example: a raised cosine in time. The pulse 12(1−cos⁡(2πt/(LT)))\tfrac12(1 - \cos(2\pi t/(LT))) on 0≤t≤LT0 \le t \le LT, the frequency pulse of LRC continuous-phase modulation, is a raised cosine in time. It is a different object with the same name, and it is not a Nyquist pulse.

Non-example: a Gaussian pulse. The Gaussian filter of Gaussian minimum-shift keying is never zero, so it has ISI at every symbol instant; GMSK accepts this for a compact spectrum.

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.

raised_cosine_filter.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/raised-cosine-filter/. The authors are listed in prov/QN0P95.jsonl.

"""The raised-cosine pulse h(t), its spectrum H(f) and the taps of a truncated FIR filter.

T is the symbol period and beta in [0, 1] the roll-off factor. sinc(x) = sin(pi x)/(pi x).
The pulse has h(0) = 1 and h(kT) = 0 for every integer k != 0.
"""

import math


def sinc(x: float) -> float:
    """sin(pi x)/(pi x), with sinc(0) = 1."""
    if x == 0:
        return 1.0
    return math.sin(math.pi * x) / (math.pi * x)


def rc_pulse(t: float, beta: float, period: float = 1.0) -> float:
    """The raised-cosine pulse at time t."""
    if not 0 <= beta <= 1:
        raise ValueError("beta must be in [0, 1]")
    u = t / period  # @line L1
    if beta > 0 and abs(abs(2 * beta * u) - 1) < 1e-12:  # @line L2
        return math.pi / 4 * sinc(1 / (2 * beta))  # @line L3
    return sinc(u) * math.cos(math.pi * beta * u) / (1 - (2 * beta * u) ** 2)  # @line L4


def rc_spectrum(f: float, beta: float, period: float = 1.0) -> float:
    """The raised-cosine spectrum H(f), equal to T on the flat part."""
    a = abs(f)
    lo = (1 - beta) / (2 * period)
    hi = (1 + beta) / (2 * period)
    if beta == 0 and a == lo:
        return period / 2  # the midpoint of the jump, so that the fold stays flat
    if a <= lo:
        return period
    if a > hi:
        return 0.0
    return period / 2 * (1 + math.cos(math.pi * period / beta * (a - lo)))


def rc_taps(beta: float, ls: int, span: int) -> list[float]:
    """h(n/ls) for n = -span*ls, ..., span*ls, with T = 1 and ls samples per symbol."""
    return [rc_pulse(n / ls, beta) for n in range(-span * ls, span * ls + 1)]  # @line L5
test_raised_cosine_filter.py 91 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/raised-cosine-filter/. The authors are listed in prov/QN0P95.jsonl.

import math

from raised_cosine_filter import rc_pulse, rc_spectrum, rc_taps, sinc


def test_check_values() -> None:
    assert abs(rc_pulse(0.5, 0.5) - 0.60021) < 5e-6
    assert abs(rc_pulse(1.5, 0.5) - (-0.12004)) < 5e-6
    assert abs(rc_pulse(0.5, 0.25) - 0.62737) < 5e-6
    assert abs(rc_pulse(1.5, 0.25) - (-0.18562)) < 5e-6
    assert abs(rc_pulse(0.5, 1.0) - 0.5) < 1e-12
    assert abs(rc_pulse(1.0, 0.5)) < 1e-12
    # The pulse scales with T: h(t) for period T equals h(t/T) for period 1.
    assert abs(rc_pulse(1.0, 0.5, 2.0) - rc_pulse(0.5, 0.5)) < 1e-15


def test_zero_at_nonzero_multiples_of_t() -> None:
    for beta in (0.0, 0.1, 0.25, 0.35, 0.5, 0.75, 1.0):
        assert rc_pulse(0.0, beta) == 1.0
        for k in range(1, 30):
            assert abs(rc_pulse(k, beta)) < 1e-12
            assert abs(rc_pulse(-k, beta)) < 1e-12


def test_beta_zero_is_sinc() -> None:
    for t in (0.1, 0.5, 1.3, 7.7):
        assert abs(rc_pulse(t, 0.0) - sinc(t)) < 1e-15


def test_continuity_at_singular_points() -> None:
    for beta in (0.2, 0.25, 0.35, 0.5, 1.0):
        t0 = 1 / (2 * beta)
        at = rc_pulse(t0, beta)
        for eps in (1e-6, -1e-6):
            assert abs(rc_pulse(t0 + eps, beta) - at) < 1e-5
            assert abs(rc_pulse(-t0 + eps, beta) - at) < 1e-5


def test_folded_spectrum_is_flat() -> None:
    for beta in (0.0, 0.25, 0.5, 1.0):
        for i in range(-50, 51):
            f = i / 100
            fold = sum(rc_spectrum(f - m, beta) for m in range(-3, 4))
            assert abs(fold - 1.0) < 1e-12
    assert abs(rc_spectrum(0.4, 0.5) - 0.79389) < 5e-6
    assert abs(rc_spectrum(0.6, 0.5) - 0.20611) < 5e-6
    assert rc_spectrum(0.5, 0.5) == 0.5


def test_bandwidth() -> None:
    assert rc_spectrum(0.625, 0.25) == 0.0
    assert rc_spectrum(0.6249, 0.25) > 0.0


def test_energy_in_time_and_frequency() -> None:
    for beta in (0.25, 0.5, 1.0):
        want = 1 - beta / 4
        # Simpson's rule on H^2 over the band.
        n = 2000
        hi = (1 + beta) / 2
        step = 2 * hi / n
        s = 0.0
        for i in range(n + 1):
            w = 1 if i in (0, n) else (4 if i % 2 else 2)
            s += w * rc_spectrum(-hi + i * step, beta) ** 2
        assert abs(s * step / 3 - want) < 1e-6
        # A Riemann sum of h^2 with step 1/16 over |t| <= 100: the pulse is band-limited
        # to below 8, so the sum is exact apart from the tail beyond 100.
        e = sum(rc_pulse(n / 16, beta) ** 2 for n in range(-1600, 1601)) / 16
        assert abs(e - want) < 1e-5


def test_decay() -> None:
    def peak(beta: float, k: int) -> float:
        return max(abs(rc_pulse(k + i / 1000, beta)) for i in range(1001))

    assert abs(peak(0.0, 10) - 0.0303) < 5e-5
    assert abs(peak(0.25, 10) - 4.79e-4) < 5e-6
    assert abs(peak(0.5, 10) - 2.21e-4) < 5e-6


def test_taps() -> None:
    taps = rc_taps(0.25, 8, 8)
    assert len(taps) == 2 * 8 * 8 + 1
    assert taps[64] == 1.0
    assert all(abs(taps[64 + 8 * k]) < 1e-12 for k in range(-8, 9) if k != 0)
    assert all(abs(taps[i] - taps[-1 - i]) < 1e-15 for i in range(len(taps)))
    assert math.isclose(taps[68], rc_pulse(0.5, 0.25))

References

  1. John G. Proakis and Masoud Salehi, Digital Communications, fifth edition, McGraw-Hill, 2008, Section 9.2-1 (the raised cosine spectrum, its pulse in time, the roll-off factor and the split of the spectrum between the transmit and the receive filter)
  2. Robert G. Gallager, Principles of Digital Communication, Cambridge University Press, 2008, Section 6.3.1 (band-edge symmetry and the raised cosine pulse as its standard example)

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/QN0P95/text.yaml