Skip to content

Version 0.1.0 is a first version, for trial. See what is not proven →

bogolang
FR

← Examples

radio_link

Plans a microwave hop: free-space loss, Fresnel zone, fade margin, rain and availability.

This program plans one microwave hop. It works out the free-space loss, the first Fresnel zone, the received level and the fade margin. It then estimates the loss from rain and the availability of the hop, and compares it with a target. No device is contacted.

Run it from this folder:

bogo run radio_link.bogo
bogo test radio_link.bogo

To use it on your own hop, change the fields at the top of the class RadioLink: the frequency, the distance, the transmit power, the antenna gains, the feeder loss and the receiver sensitivity from the radio data sheet.

The rain rate and the latitude depend on where the hop is. The values in the program (42 mm/h and 45 degrees) are examples only. Take the rain rate R0.01 of your site from the ITU-R P.837 maps or from local records. The result is an estimate for rain only. It does not count multipath fading, obstruction or equipment failure.

radio_link.bogo
edition 2027
"""The plan of one microwave hop: free-space loss, link budget, fade margin and rain."""


class RadioLink:
    """Checks one microwave hop against a target availability.

    The rain rate and the latitude depend on where the hop is. The values below are
    examples only: take the rain rate R0.01 for your site from the ITU-R P.837 maps or
    from local records, and the latitude of your own hop.
    """

    name = "site-a to site-b"
    freq = 18GHz
    distance = 12km
    tx = 18dBm
    antenna_a = 38dBi
    antenna_b = 38dBi
    feeder_loss = 2dB  # waveguide and connectors, both ends together
    sensitivity = -70dBm  # receiver threshold of the chosen modulation
    rain_rate = 42.0  # EXAMPLE: mm/h passed for 0.01 percent of the year
    latitude = 45.0  # EXAMPLE: degrees, north or south
    polarization = "vertical"
    target = 99.99pct

    @staticmethod
    def budget(distance: Distance, freq: Frequency) -> Budget:
        losses: list[Gain] = [fspl(distance, freq), RadioLink.feeder_loss]
        gains: list[Gain] = [RadioLink.antenna_a, RadioLink.antenna_b]
        return link_budget(RadioLink.tx, gains, losses, RadioLink.sensitivity)

    @staticmethod
    def verdict(availability: Percent, target: Percent) -> str:
        if availability >= target:
            return "meets the target"
        return "misses the target"

    @staticmethod
    def downtime_minutes(availability: Percent) -> float:
        """Minutes of rain outage in an average year."""
        return (100 - availability.value) / 100 * 365 * 24 * 60

    @staticmethod
    def main(args: list[str]) -> None:
        r = RadioLink
        b = r.budget(r.distance, r.freq)
        fade = rain_fade(r.distance, r.freq, r.rain_rate, r.polarization)
        print(f"Hop {r.name}: {r.distance} at {r.freq}, {r.polarization} polarization")
        print(f"  Free-space loss     {fspl(r.distance, r.freq)}")
        print(f"  First Fresnel zone  {fresnel(r.distance, r.freq)} radius at mid-hop")
        print(f"  Received level      {b.rx}")
        print(f"  Fade margin         {b.margin}")
        print(f"  Rain fade (0.01%)   {fade} at {r.rain_rate} mm/h")
        if not b.ok:
            print("  The link does not close: no availability to compute.")
            return
        avail = rain_availability(
            b.margin, r.distance, r.freq, r.rain_rate, r.polarization, latitude=r.latitude
        )
        minutes = r.downtime_minutes(avail)
        print(f"  Availability (rain) {avail}, about {minutes:.0f} min down a year")
        print(f"  Target {r.target}: the hop {r.verdict(avail, r.target)}")


class TestRadioLink:
    def test_free_space_loss_matches_itu_formula(self) -> None:
        # ITU-R P.525: 32.44 + 20 log10(18000 MHz) + 20 log10(1 km) = 117.55 dB
        assert abs(fspl(1km, 18GHz).value - 117.55) < 0.01

    def test_longer_hop_has_less_margin(self) -> None:
        assert RadioLink.budget(20km, 18GHz).margin < RadioLink.budget(12km, 18GHz).margin

    def test_verdict(self) -> None:
        assert RadioLink.verdict(99.995pct, 99.99pct) == "meets the target"
        assert RadioLink.verdict(99.9pct, 99.99pct) == "misses the target"

    def test_downtime_of_three_nines(self) -> None:
        assert round(RadioLink.downtime_minutes(99.9pct)) == 526