Techniqueintro
Direct-sequence spread spectrum
Also called DSSS, direct-sequence spreading.
Multiply each data symbol by a fast pseudorandom chip code, so that the signal fills a wide band. Correlating with the same code restores the symbol and spreads out interference.
Direct-sequence spread spectrum (DSSS) sends each data symbol as a block of short pulses, the chips, whose signs follow a pseudorandom code known to the receiver. The chip rate is times the symbol rate, so the signal takes about times the bandwidth that the data needs. The receiver multiplies the received chips by the same code and adds them up over each symbol. This despreading collapses the wanted signal back into one strong value, while noise, narrowband interference and the signals of other codes stay spread out and add up only weakly. The factor by which the wanted signal gains over the interference is the processing gain, about . DSSS is the basis of CDMA, of GPS and of the first Wi-Fi rates.
In plain words
Each data bit is sent as a long, fast pattern of plus and minus pulses, chosen to look random. The receiver knows the pattern. It multiplies what it hears by the pattern, pulse by pulse, and adds up the results.
For the wanted signal every product has the same sign, so the sum grows large. For noise, for a steady tone, or for a user with another pattern, the products have mixed signs and mostly cancel. So the wanted bit stands out even when each single pulse is buried under the interference.
The cost is bandwidth: the fast pattern takes up a much wider band than the data alone. The receiver must also line up its copy of the pattern with the received one to within a fraction of a pulse, before it can decode anything.
When it applies
- There is spare bandwidth, and a strong narrowband interferer, a jammer, or many other users must share the band.
- The receiver can find and follow the code timing: an acquisition step finds it to within about one chip, and a tracking loop keeps it there.
- Multipath delays are longer than one chip, so a rake receiver can separate the paths and add them.
- Several users share the band at the same time, each with its own code, and their powers can be controlled. Without power control, a near user can swamp a far one; see near-far problem.
- The signal must be hard to detect or to read without the code: its power density can be below the noise floor.
The template
Let be a code of chips, for example one period of an m-sequence, and let be the data symbols. The transmitter sends the chips . The receiver gets $r = x + $ interference and computes, for each symbol, the correlation with the code, which is a matched filter for one symbol:
where is the interference. With white noise of variance per chip, the signal-to-noise ratio is per chip and after despreading, a gain of .
SPREAD(d, c) ▷ d data symbols ±1, c code of N chips ±1- 1
for each symbol d_i do - 2
send d_i c_0, d_i c_1, …, d_i c_{N-1} DESPREAD(r, c)- 3
for each block i do z_i ← Σ_{n=0}^{N-1} r[iN + n] c_n - 4
return d̂_i ← sign(z_i) for each i
Spreading and despreading cost operations per symbol. On a real link the chips are shaped pulses on a carrier, and the receiver must also find the code phase and the carrier before L3; see serial-search code acquisition, parallel code phase search and the delay-locked loop.
Classic examples
- Length 7. With the m-sequence of and the mapping , , the code is . The symbols become chips, and despreading gives exactly and .
- A constant jammer. The chips of an m-sequence of length add up to , since the sequence has one more 1 than 0. A constant interferer of amplitude therefore adds exactly to each correlator output, against for the symbol. With and , the jammer is dB stronger than the signal on each chip, but the outputs are and , and every decision is right.
- White noise. With and noise variance per chip, the signal-to-noise ratio per chip is dB. After despreading it is , or dB.
- Two users. User 1 uses an m-sequence of length , and user 2 uses a cyclic shift of it. Two different shifts of an m-sequence have periodic cross-correlation , so user 1 sees exactly . With Gold sequences the cross-talk is larger but bounded, and there are many more codes.
- GPS C/A code. Each satellite spreads bit/s of navigation data with its own Gold code of chips at Mchip/s, so one bit spans code periods and chips.
- IS-95 and WCDMA. IS-95 spreads at Mchip/s and separates the downlink users with Walsh codes of length . WCDMA spreads at Mchip/s with OVSF codes and a long scrambling code.
Variations
- Short and long codes. A short code repeats every symbol, which makes acquisition fast and allows multiuser detection. A long code spans many symbols and makes the interference look more like noise.
- Spreading with complex codes. Two independent codes on the in-phase and quadrature branches (QPSK spreading) make the interference less dependent on carrier phase.
- Code-shift keying. Each group of bits selects one of codes; the receiver correlates with all of them and picks the largest. IEEE 802.11b at 5.5 and 11 Mbit/s uses a related scheme, complementary code keying.
- Orthogonal codes in a synchronous downlink. When all signals leave one transmitter at the same time, orthogonal codes such as OVSF codes remove the cross-talk on a single path.
- Frequency hopping. The other main way to spread is to hop the carrier; see frequency-hopping spread spectrum.
Pitfalls
- The gain is not free against white noise. Spreading does not change the energy per bit to noise density ratio, so the bit error rate on an AWGN channel is the same as without spreading. The gain is against interference whose power is fixed and does not grow with the bandwidth.
- The code timing must be known. An error of one chip or more makes the correlation fall to the off-peak level. Despreading only works after acquisition and with tracking.
- Near-far. The cross-talk from another user scales with its amplitude. A user near the base station can swamp a far user, unless the transmit powers are controlled.
- Partial correlations. In an asynchronous system, one symbol of the other user may change sign in the middle of the correlation window. The cross-talk is then an odd or partial correlation, not the periodic correlation, and it can be larger.
- Bandwidth. The signal needs times the bandwidth of the data. If the band is the limit and there is no interference to fight, DSSS lowers the spectral efficiency of a single link.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/direct-sequence-spread-spectrum/. The authors are listed in prov/5PQ8PD.jsonl.
"""Direct-sequence spreading and despreading with a +1/-1 chip code.
Each symbol d[i] in {+1, -1} is sent as d[i] c[0], ..., d[i] c[N - 1], where c
is a chip code of length N (here usually one period of an m-sequence). The
receiver correlates each block of N chips with c and takes the sign.
"""
def mseq_chips(exps: list[int]) -> list[int]:
"""One period of an m-sequence as chips: bit 0 -> +1 and bit 1 -> -1.
The polynomial is the list of its exponents, for example [3, 1, 0] for
x^3 + x + 1, and s[k + n] = XOR over the exponents i < n of s[k + i].
"""
n = max(exps)
s = [1] + [0] * (n - 1)
taps = [i for i in exps if i < n]
while len(s) < (1 << n) - 1:
k = len(s) - n
bit = 0
for i in taps:
bit ^= s[k + i]
s.append(bit)
return [1 - 2 * b for b in s]
def spread(symbols: list[int], code: list[int]) -> list[int]:
"""The chip stream: each symbol times the whole code."""
chips = []
for d in symbols: # @line L1
chips.extend(d * c for c in code) # @line L2
return chips
def despread(received: list[float], code: list[int]) -> list[float]:
"""The correlator outputs z[i] = sum over n of r[i N + n] c[n]."""
n = len(code)
if len(received) % n:
raise ValueError("length must be a multiple of the code length")
return [sum(received[i + j] * code[j] for j in range(n)) for i in range(0, len(received), n)] # @line L3
def decide(z: list[float]) -> list[int]:
"""Hard decisions: +1 if z >= 0, else -1."""
return [1 if v >= 0 else -1 for v in z] # @line L4
test_direct_sequence_spread_spectrum.py 66 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/direct-sequence-spread-spectrum/. The authors are listed in prov/5PQ8PD.jsonl.
import random
from direct_sequence_spread_spectrum import decide, despread, mseq_chips, spread
POLYS = {3: [3, 1, 0], 5: [5, 2, 0], 7: [7, 1, 0]}
def test_check_value_degree_three() -> None:
c = mseq_chips(POLYS[3])
assert c == [-1, 1, 1, -1, 1, -1, -1] # bits 1001011
assert spread([1, -1], c) == c + [-v for v in c]
assert despread(spread([1, -1], c), c) == [7, -7]
def test_round_trip_without_noise() -> None:
rng = random.Random(1)
for poly in POLYS.values():
c = mseq_chips(poly)
d = [rng.choice((-1, 1)) for _ in range(50)]
z = despread(spread(d, c), c)
assert z == [len(c) * v for v in d]
assert decide(z) == d
def test_constant_jammer_is_reduced_to_minus_its_amplitude() -> None:
# The chips of an m-sequence sum to -1, so a constant A adds exactly -A per symbol.
rng = random.Random(2)
for poly in POLYS.values():
c = mseq_chips(poly)
n = len(c)
assert sum(c) == -1
d = [rng.choice((-1, 1)) for _ in range(20)]
for a in (1, 5, 40):
r = [x + a for x in spread(d, c)]
assert despread(r, c) == [n * v - a for v in d]
def test_second_user_on_a_shifted_code() -> None:
# Two shifts of one m-sequence have periodic cross-correlation -1.
rng = random.Random(3)
c = mseq_chips(POLYS[5])
n = len(c)
for tau in (1, 7, 30):
c2 = c[tau:] + c[:tau]
d1 = [rng.choice((-1, 1)) for _ in range(30)]
d2 = [rng.choice((-1, 1)) for _ in range(30)]
r = [x + y for x, y in zip(spread(d1, c), spread(d2, c2))]
assert despread(r, c) == [n * a - b for a, b in zip(d1, d2)]
def test_white_noise_gain_equals_code_length() -> None:
# Per chip: signal 1, noise variance s2. After despreading: signal N^2, noise N s2.
rng = random.Random(4)
c = mseq_chips(POLYS[5])
n = len(c)
s2 = 4.0
count = 4000
d = [rng.choice((-1, 1)) for _ in range(count)]
r = [x + rng.gauss(0.0, s2 ** 0.5) for x in spread(d, c)]
z = despread(r, c)
noise = [zi - n * di for zi, di in zip(z, d)]
var = sum(v * v for v in noise) / count
assert abs(var / (n * s2) - 1) < 0.1
Exercises
- Show that for an m-sequence of length and a constant interferer , the correlator output is exactly. How large can be before a symbol of is decided wrongly?
- Two users share the band with codes and and periodic cross-correlation . Write the output of the correlator for user 1 as a function of the two symbols, and find the largest that still allows error-free decisions without noise.
- With white noise of variance per chip, show that the variance of is , for any code.
References
- Raymond L. Pickholtz, Donald L. Schilling and Laurence B. Milstein, Theory of spread-spectrum communications, a tutorial, IEEE Transactions on Communications 30(5), 1982, pp. 855 to 884 (direct-sequence spreading, processing gain, jamming margin, code acquisition and tracking)
- Andrew J. Viterbi, CDMA, Principles of Spread Spectrum Communication, Addison-Wesley, 1995, The opening chapters on direct-sequence spreading and its use for multiple access
- John G. Proakis and Masoud Salehi, Digital Communications, 5th edition, McGraw-Hill, 2008, The chapter on spread spectrum signals for digital communications
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag 5PQ8PD Edit this page History Report an error Markdown