---
title: "Project: a 2.4 GHz sensor link"
heading: Antenna directivity, path loss, mismatch and cable loss, combined into a link budget
eyebrow: B7 · Lesson 14 · Project
xp: 80
---

::: hook
A wireless sensor in a field sends readings to a gateway in a barn. Will the link work, and how far can it reach? Answering takes everything in this unit: how strongly the antennas focus their radiation, how the wave spreads over distance, how much power a poor antenna match reflects, and how much a coax cable turns into heat through the skin effect. In this project you'll compute each piece from its physics, check it against the textbook values, and combine them into a link budget that gives the range with a safety margin.
:::

::: play
- A transmitter feeds a half-wave dipole through 2 m of thin coax, and an identical setup receives. The curve is the received power against distance, in dBm.
- The dashed line is the receiver's sensitivity, −90 dBm, raised by a 10 dB fade margin for walls, foliage and multipath. The link works out to where the curve crosses it.
- Lower the frequency or raise the power: the readout gives the range. Every 6 dB of extra budget doubles it.
:::

```sim plot
view: graph
x: d = 10..10000 log m
y: P = -110..-30
slider: Pt = 0..30 step 1 = 20 dBm
slider: f = 0.4..6 step 0.05 = 2.4 GHz
plot: Pt + 4.302 - 2.52 - 20*log(4*pi*d*f*1e9/3e8) | label: received power (dBm) | samples: 400
plot: -80 | dashed | label: sensitivity plus fade margin
readout: range with a 10 dB margin, m = 3e8/(4*pi*f*1e9)*10^((Pt + 4.302 - 2.52 + 80)/20) | digits: 4
```

::: predict
## The same radios and dipoles move from 2.4 GHz to 915 MHz, with the same power. What happens to the range?

- [ ] It stays the same: free space has no loss
- [x] It grows about 2.6 times
- [ ] It shrinks about 2.6 times
- [ ] It grows about 6.9 times

::: reveal
It grows about 2.6 times, from 1.2 km to 3.2 km. The wave spreads the same way at any frequency, but a dipole's effective area, the power it collects per unit of incoming intensity, scales as $\lambda^2$. A dipole for 915 MHz is 2.6 times longer and catches 6.9 times more power, which buys a 2.6 times longer path, since received power falls as $\frac{1}{d^2}$.
:::
:::

::: nameit
## Directivity

An antenna's radiation intensity $U(\theta, \varphi)$ is power per unit solid angle. Its **directivity** compares the peak with the average over all directions:

$$D = \frac{4\pi U_\text{max}}{\oint U\,d\Omega}, \qquad d\Omega = \sin\theta\,d\theta\,d\varphi.$$

A short dipole, $U \propto \sin^2\theta$, has D = 1.5 (1.76 dBi); a half-wave dipole, $U \propto \left(\frac{\cos(\frac\pi2\cos\theta)}{\sin\theta}\right)^2$, has 1.641 (2.15 dBi). Gain is directivity times the antenna's efficiency.

## Path loss and Friis

Between isotropic antennas, the **free-space path loss** is $\left(\frac{4\pi df}{c}\right)^2$, or $20\log_{10}\frac{4\pi df}{c}$ dB, and in decibels the received power is

$$P_r = P_t + G_t + G_r - \text{FSPL} - \text{losses}.$$

## Mismatch and cable loss

An antenna with standing-wave ratio S reflects $|\Gamma|^2$ of the power, with $|\Gamma| = \frac{S - 1}{S + 1}$: a **mismatch loss** of $-10\log_{10}(1 - |\Gamma|^2)$ dB. A coax with conductor radii a and b loses, to the skin effect alone, $\alpha = \frac{R'}{2Z_0}$ nepers per meter, with $R' = \frac{R_s}{2\pi}\left(\frac1a + \frac1b\right)$, $R_s = \sqrt{\pi f\mu_0\rho}$ and $Z_0 = \frac{59.96}{\sqrt{\varepsilon_r}}\ln\frac ba$; that's 8.686α dB per meter. Real cables lose more, from the braid and the dielectric, so this is a lower bound.

## The link budget

Add every gain and subtract every loss; compare with the receiver's sensitivity plus a **fade margin**, typically 10 to 20 dB, for the things free space leaves out. The surplus decides the range: every 6 dB doubles it.
:::

::: example
## Find the directivity of a short dipole and of a half-wave dipole by integrating their patterns.

::: solution
1. **Integrate the short dipole's pattern.** For $U = \sin^2\theta$,
   $$\begin{aligned} \oint U\,d\Omega &= 2\pi\int_0^\pi\sin^3\theta\,d\theta \\ &= \frac{8\pi}{3} \end{aligned}$$
2. **Short dipole's directivity.**
   $$\begin{aligned} D &= \frac{4\pi}{8\pi/3} \\ &= 1.5 \end{aligned}$$
   or 1.76 dBi.
3. **Half-wave dipole.** Its pattern has no simple integral, but a numerical one gives D = 1.641, or 2.15 dBi.
4. **Compare.** The longer dipole squeezes its pattern slightly toward broadside, gaining 0.39 dB.
5. **Mounting.** Both radiate nothing along their own axis, so a dipole pointed at the gateway is the worst way to mount one.

**Answer:** the short dipole's directivity is 1.5 (1.76 dBi), and the half-wave dipole's is 1.641 (2.15 dBi).
:::
:::

::: example
## A thin coax has a 0.45 mm inner conductor, a 1.47 mm shield radius and polyethylene insulation (εᵣ = 2.25). What is its impedance, and its conductor loss at 2.4 GHz?

::: solution
1. **Impedance.**
   $$\begin{aligned} Z_0 &= \frac{59.96}{1.5}\ln\frac{1.47}{0.45} \\ &= 47.3\ \Omega \end{aligned}$$
2. **Surface resistance.** At 2.4 GHz copper's surface resistance is
   $$\begin{aligned} R_s &= \sqrt{\pi f\mu_0\rho} \\ \pi f\mu_0\rho &= \pi \times 2.4 \times 10^9 \\ &\quad \times 4\pi \times 10^{-7} \\ &\quad \times 1.72 \times 10^{-8} \\ &= 1.63 \times 10^{-4} \\ R_s &= 12.8\ \text{m}\Omega \end{aligned}$$
3. **Conductor loss.** The loss works out to 0.54 dB per meter.
4. **The cables in the link.** So 2 m of it at each end costs 2.2 dB:
   $$4 \times 0.54 = 2.2\ \text{dB}$$
5. **Other frequencies.** The loss grows as $\sqrt f$: at 100 MHz the same cable loses 11 dB per 100 m. Keeping cables short, or putting the radio at the antenna, matters more at high frequencies.

**Answer:** the coax's impedance is 47.3 Ω, and at 2.4 GHz its conductor loss is 0.54 dB per meter.
:::
:::

::: example
## With 20 dBm (100 mW) into half-wave dipoles at both ends, 2 m of that coax at each end, and antennas with SWR 1.5, what is the received power at 1 km and 2.4 GHz?

::: solution
1. **Path loss.**
   $$\begin{aligned} L_\text{fs} &= 20\log_{10}\frac{4\pi \times 1000 \times 2.4 \times 10^9}{3 \times 10^8} \\ &= 100.05\ \text{dB} \end{aligned}$$
2. **Cable and mismatch losses.** The cables cost 2.16 dB and the two mismatches 0.18 dB each:
   $$2.16 + 2 \times 0.18 = 2.52\ \text{dB}$$
3. **Received power.**
   $$\begin{aligned} P_r &= 20 + 2.15 + 2.15 \\ &\quad - 2.52 - 100.05 \\ &= -78.3\ \text{dBm} \end{aligned}$$
4. **Margin.** Against a −90 dBm sensitivity that's an 11.7 dB surplus, just above a 10 dB fade margin: the link would work to about 1.2 km.

**Answer:** about −78.3 dBm arrives at 1 km, 11.7 dB above the receiver's sensitivity, so the link would work to about 1.2 km.
:::
:::

::: check
kind: python

## Step 1. Write `directivity(U, n)` that integrates a pattern U(θ) (a function of a NumPy array of angles, the same for every φ) over the sphere with n midpoints in θ, and returns $D = \frac{4\pi U_\text{max}}{\oint U\,d\Omega}$.

```python starter
import numpy as np

def directivity(U, n):
    return 1.0

print(directivity(lambda t: np.sin(t)**2, 2000))
```

```python solution
import numpy as np

def directivity(U, n):
    th = (np.arange(n) + 0.5) * np.pi / n
    u = U(th)
    total = 2 * np.pi * np.sum(u * np.sin(th)) * np.pi / n
    return float(4 * np.pi * u.max() / total)

print(directivity(lambda t: np.sin(t)**2, 2000))
```

```python tests
import numpy as np
assert abs(directivity(lambda t: np.sin(t)**2, 2000) - 1.5) < 1e-5, "A short dipole has D = 1.5."
h = directivity(lambda t: (np.cos(np.pi / 2 * np.cos(t)) / np.sin(t))**2, 20000)
assert abs(h - 1.6409) < 2e-4, f"A half-wave dipole has D = 1.641; got {h:.5f}."
assert abs(directivity(lambda t: 1 + 0 * t, 1000) - 1) < 1e-5, "An isotropic pattern has D = 1."
```

::: right
Right. Integrating with $\sin\theta$ weights each ring of directions by its size, so a pattern bright only near the poles counts for little.
:::
:::

::: check
kind: python

## Step 2. Write `fspl_db(f, d)` for the free-space path loss in dB, and `received_dbm(Pt, Gt, Gr, f, d)` for the Friis received power (powers in dBm, gains in dBi).

```python starter
import math

def fspl_db(f, d):
    return 20 * math.log10(d)

def received_dbm(Pt, Gt, Gr, f, d):
    return Pt - fspl_db(f, d)

print(fspl_db(2.4e9, 1000), received_dbm(20, 2.15, 2.15, 2.4e9, 1000))
```

```python solution
import math

def fspl_db(f, d):
    return 20 * math.log10(4 * math.pi * d * f / 3e8)

def received_dbm(Pt, Gt, Gr, f, d):
    return Pt + Gt + Gr - fspl_db(f, d)

print(fspl_db(2.4e9, 1000), received_dbm(20, 2.15, 2.15, 2.4e9, 1000))
```

```python tests
assert abs(fspl_db(2.4e9, 1000) - 100.046) < 1e-3, f"At 2.4 GHz over 1 km the path loss is 100.05 dB; got {fspl_db(2.4e9, 1000):.3f}."
assert abs(fspl_db(2.4e9, 2000) - fspl_db(2.4e9, 1000) - 6.0206) < 1e-4, "Doubling the distance adds 6.02 dB."
assert abs(received_dbm(20, 2.15, 2.15, 2.4e9, 1000) - (-75.746)) < 1e-3, "With dipoles and no other losses: -75.75 dBm."
```

::: right
Right. In decibels the whole link is a sum, which is why engineers keep budgets as tables of plus and minus entries.
:::
:::

::: check
kind: python

## Step 3. Write `mismatch_db(swr)` returning the mismatch loss in dB for a standing-wave ratio swr.

```python starter
def mismatch_db(swr):
    return 0.0

print(mismatch_db(1.5), mismatch_db(3))
```

```python solution
import math

def mismatch_db(swr):
    G = (swr - 1) / (swr + 1)
    return -10 * math.log10(1 - G * G)

print(mismatch_db(1.5), mismatch_db(3))
```

```python tests
assert abs(mismatch_db(1.5) - 0.17729) < 1e-4, f"SWR 1.5 loses 0.177 dB; got {mismatch_db(1.5):.5f}."
assert abs(mismatch_db(2) - 0.51153) < 1e-4 and abs(mismatch_db(3) - 1.24939) < 1e-4, "SWR 2 loses 0.51 dB and SWR 3 1.25 dB."
assert abs(mismatch_db(1.0)) < 1e-12, "A perfect match loses nothing."
```

::: right
Right. An SWR of 1.5 reflects only 4% of the power: matching matters less for the received power than for protecting transmitters from reflected power.
:::
:::

::: check
kind: python

## Step 4. Write `coax_db(f, a, b, L, er)` that returns `(loss_dB, Z0)` for L meters of copper coax (ρ = 1.72 × 10⁻⁸ Ω·m) with inner radius a and shield radius b, counting conductor loss only.

```python starter
import math

def coax_db(f, a, b, L, er):
    return 0.0, 50.0

print(coax_db(2.4e9, 0.45e-3, 1.47e-3, 1, 2.25))
```

```python solution
import math

def coax_db(f, a, b, L, er):
    Rs = math.sqrt(math.pi * f * 4e-7 * math.pi * 1.72e-8)
    Rp = Rs / (2 * math.pi) * (1 / a + 1 / b)
    Z0 = 59.96 / math.sqrt(er) * math.log(b / a)
    return 8.686 * Rp / (2 * Z0) * L, Z0

print(coax_db(2.4e9, 0.45e-3, 1.47e-3, 1, 2.25))
```

```python tests
loss, Z0 = coax_db(2.4e9, 0.45e-3, 1.47e-3, 1, 2.25)
assert abs(Z0 - 47.319) < 1e-2, f"The impedance is 47.3 Ω; got {Z0:.3f}."
assert abs(loss - 0.5412) < 1e-3, f"At 2.4 GHz it loses 0.541 dB per meter; got {loss:.4f}."
assert abs(coax_db(9.6e9, 0.45e-3, 1.47e-3, 1, 2.25)[0] / loss - 2) < 1e-9, "Four times the frequency, twice the loss: the skin depth shrinks as 1/√f."
```

::: right
Right. The loss rises as $\sqrt f$ because the current crowds into a thinner skin, and the thinner inner conductor does most of the losing.
:::
:::

::: check
kind: python

## Step 5. Write `max_range(Pt, Gt, Gr, f, losses, sens, margin)` that returns the distance in meters at which the received power, after the given extra losses (dB), falls to the sensitivity plus the margin. `fspl_db` is included.

```python starter
import math

def fspl_db(f, d):
    return 20 * math.log10(4 * math.pi * d * f / 3e8)

def max_range(Pt, Gt, Gr, f, losses, sens, margin):
    return 1000.0

print(max_range(20, 2.15, 2.15, 2.4e9, 2.52, -90, 10))
```

```python solution
import math

def fspl_db(f, d):
    return 20 * math.log10(4 * math.pi * d * f / 3e8)

def max_range(Pt, Gt, Gr, f, losses, sens, margin):
    allowed = Pt + Gt + Gr - losses - (sens + margin)
    return 3e8 / (4 * math.pi * f) * 10**(allowed / 20)

print(max_range(20, 2.15, 2.15, 2.4e9, 2.52, -90, 10))
```

```python tests
r = max_range(20, 2.151, 2.151, 2.4e9, 2.5196, -90, 10)
assert abs(r - 1221.3) < 1, f"The link reaches 1221 m with a 10 dB margin; got {r:.1f}."
r2 = max_range(20, 2.151, 2.151, 915e6, 2.5196, -90, 10)
assert abs(r2 / r - 2.4e9 / 915e6) < 1e-9, "At 915 MHz the range grows by the frequency ratio, 2.62 times."
assert abs(max_range(26, 2.151, 2.151, 2.4e9, 2.5196, -90, 10) / r - 10**0.3) < 1e-9, "6 dB more power doubles the range."
```

::: right
Right. The budget turns every decibel into distance: 6 dB doubles the range, 20 dB multiplies it by ten, and a 10 dB margin costs two thirds of the range a bare calculation would promise.
:::
:::

::: check
kind: parts
given: Pt = 10 | 20; f = 0.868 | 2.4 | 5.8; d = 100 | 1000

## A link uses half-wave dipoles (2.15 dBi) at both ends, {Pt} dBm of transmit power, and runs at {f} GHz over {d} m, with no other losses.

::: part
answer: 20*log(4*pi*d*f*1e9/3e8)
unit: dB
tolerance: 0.5%

### What is the free-space path loss?

::: misses
- [20*log(4*pi*d*f*1e9/3e8)/2] Path loss in dB uses 20 log, since it goes as the square of the distance.
- [any] $20\log_{10}\frac{4\pi df}{c}$.
:::
:::

::: part
answer: Pt + 4.3 - 20*log(4*pi*d*f*1e9/3e8)
unit: dBm
tolerance: 0.5%

### What power arrives?

::: misses
- [any] $P_t + G_t + G_r - \text{FSPL}$.
:::
:::
:::

::: check
given: S = 1.2 | 2 | 4
answer: -10*log(1 - ((S - 1)/(S + 1))^2)
unit: dB
tolerance: 0.5%

## An antenna has an SWR of {S}. What mismatch loss does it cause?

::: right
Right. $-10\log_{10}(1 - |\Gamma|^2)$ with $|\Gamma| = \frac{S - 1}{S + 1}$.
:::

::: misses
- [-20*log(1 - ((S - 1)/(S + 1)))] Use the reflected power, $|\Gamma|^2$, in $1 - |\Gamma|^2$.
- [any] $|\Gamma| = \frac{S - 1}{S + 1}$.
:::
:::

::: explain
## Why does a link budget need a fade margin when the free-space calculation already says the signal is above the receiver's sensitivity?

::: model
The free-space formula describes a wave spreading through empty space between two perfectly placed antennas. Real paths have walls, trees, people and the ground, which absorb some of the signal, and reflections that arrive by several routes and partly cancel at the receiver, so the received power can dip far below the free-space value at some spots and moments. Those dips are unpredictable, so instead of computing them, the budget sets aside a margin, often 10 to 20 dB, between the predicted power and the sensitivity. A link with no margin works on the bench and fails in the field whenever a dip comes along.
:::
:::

::: practice

::: check
given: f = 0.433 | 2.4; d = 50 | 5000
answer: 20*log(4*pi*d*f*1e9/3e8)
unit: dB
tolerance: 0.5%

## Free-space path loss at {f} GHz over {d} m?

::: misses
- [any] $20\log_{10}\frac{4\pi df}{c}$.
:::
:::

::: check
given: x = 3 | 6 | 12 | 20
answer: 10^(x/20)
tolerance: 0.5%

## By what factor does {x} dB of extra link budget multiply the range?

::: misses
- [10^(x/10)] Received power goes as $\frac{1}{d^2}$, so use $10^{x/20}$.
- [any] $10^{x/20}$.
:::
:::
:::
