Skip to content

Commit

Permalink
Reorganize library and API reference
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Jul 27, 2023
1 parent ac6cc8a commit fe8fa84
Show file tree
Hide file tree
Showing 47 changed files with 496 additions and 387 deletions.
2 changes: 1 addition & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
api/
api/sdr.*
build/
jupyter_execute/
savefig/
79 changes: 0 additions & 79 deletions docs/api.rst

This file was deleted.

4 changes: 4 additions & 0 deletions docs/api/data-manipulation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Data manipulation
-----------------

.. python-apigen-group:: data
6 changes: 6 additions & 0 deletions docs/api/filtering.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. py:module:: sdr
Filtering
=========

.. python-apigen-group:: filtering
17 changes: 17 additions & 0 deletions docs/api/link-budgets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Link budgets
============

Channel capacity
----------------

.. python-apigen-group:: link-budget-channel-capacity

Path losses
-----------

.. python-apigen-group:: link-budget-path-losses

Antennas
--------

.. python-apigen-group:: link-budget-antennas
17 changes: 17 additions & 0 deletions docs/api/measurement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Measurement
===========

Energy
------

.. python-apigen-group:: measurement-energy

Power
-----

.. python-apigen-group:: measurement-power

Voltage
-------

.. python-apigen-group:: measurement-voltage
22 changes: 22 additions & 0 deletions docs/api/modulation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Modulation
==========

Classes
-------

.. python-apigen-group:: modulation-classes

Pulse shaping
-------------

.. python-apigen-group:: modulation-pulse-shaping

Symbol mapping
--------------

.. python-apigen-group:: modulation-symbol-mapping

Symbol encoding
---------------

.. python-apigen-group:: modulation-symbol-encoding
22 changes: 22 additions & 0 deletions docs/api/plotting.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Plotting
--------

Configuration
.............

.. python-apigen-group:: plot-config

Time-domain
...........

.. python-apigen-group:: plot-time

Frequency-domain
................

.. python-apigen-group:: plot-freq

Filter analysis
...............

.. python-apigen-group:: plot-filter
4 changes: 4 additions & 0 deletions docs/api/probability.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Probability
-----------

.. python-apigen-group:: probability
4 changes: 4 additions & 0 deletions docs/api/resampling.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Resampling
----------

.. python-apigen-group:: resampling
12 changes: 12 additions & 0 deletions docs/api/simulation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Simulation
==========

Channel models
--------------

.. python-apigen-group:: simulation-channel-models

Signal impairments
------------------

.. python-apigen-group:: simulation-impairments
4 changes: 4 additions & 0 deletions docs/api/synchronization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Synchronization
===============

.. python-apigen-group:: pll
14 changes: 12 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,19 @@ Features
.. toctree::
:caption: API Reference
:hidden:
:maxdepth: 2
:maxdepth: 4

api.rst
api/filtering.rst
api/resampling.rst
api/modulation.rst
api/synchronization.rst
api/impairments.rst
api/measurement.rst
api/simulation.rst
api/link-budgets.rst
api/probability.rst
api/data-manipulation.rst
api/plotting.rst

.. toctree::
:caption: Release Notes
Expand Down
5 changes: 1 addition & 4 deletions src/sdr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
)

from . import plot
from ._capacity import *
from ._channel_model import *
from ._data import *
from ._farrow import *
from ._filter import *
from ._impairment import *
from ._link_budget import *
from ._loop_filter import *
from ._measurement import *
from ._modulation import *
from ._nco import *
from ._pll import *
from ._probability import *
from ._pulse_shape import *
from ._simulation import *
4 changes: 4 additions & 0 deletions src/sdr/_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
A module with various physical constants.
"""
SPEED_OF_LIGHT = 299_792_458 # m/s
2 changes: 2 additions & 0 deletions src/sdr/_farrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def resample(self, x: npt.ArrayLike, rate: float) -> np.ndarray:
Examples:
See the :ref:`farrow-arbitrary-resampler` example.
"""
if not isinstance(rate, (int, float)):
raise TypeError("Argument 'rate' must be an integer or float.")
if not rate > 0:
raise ValueError("Argument 'rate' must be positive.")

Expand Down
6 changes: 6 additions & 0 deletions src/sdr/_link_budget/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
A subpackage for link budget calculations.
"""
from ._antenna import *
from ._capacity import *
from ._path_loss import *
53 changes: 4 additions & 49 deletions src/sdr/_link_budget.py → src/sdr/_link_budget/_antenna.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,13 @@
"""
A module containing functions for calculating link budgets.
A module containing functions for calculating antenna gains.
"""
from __future__ import annotations

import numpy as np
import numpy.typing as npt

from ._helper import export

SPEED_OF_LIGHT = 299_792_458 # m/s


@export
def fspl(d: npt.ArrayLike, f: npt.ArrayLike) -> npt.ArrayLike:
r"""
Calculates the free-space path loss (FSPL) in dB.
$$\text{FSPL} = 10 \log_{10} \left( \frac{4 \pi d f}{c} \right)^2$$
Arguments:
d: The distance $d$ in meters between the transmitter and receiver.
f: The frequency $f$ in Hz of the signal.
Returns:
The free-space path loss (FSPL) in dB.
Examples:
Compute the free-space path loss for a 1 km link at 1 GHz.
.. ipython:: python
sdr.fspl(1e3, 1e9)
The free-space path loss is proportional to the square of the distance. So, doubling the distance
results in a 6 dB increase in the free-space path loss.
.. ipython:: python
sdr.fspl(2e3, 1e9)
The free-space path loss is also proportional to the square of the frequency. So, doubling the frequency
results in a 6 dB increase in the free-space path loss.
.. ipython:: python
sdr.fspl(1e3, 2e9)
Group:
link-budget
"""
d = np.asarray(d)
f = np.asarray(f)
loss = 20 * np.log10(4 * np.pi * d * f / SPEED_OF_LIGHT)
return loss
from .._constants import SPEED_OF_LIGHT
from .._helper import export


@export
Expand Down Expand Up @@ -94,7 +49,7 @@ def parabolic_antenna(
sdr.parabolic_antenna(1e9, 2)
Group:
link-budget
link-budget-antennas
"""
freq = np.asarray(freq)

Expand Down
8 changes: 4 additions & 4 deletions src/sdr/_capacity.py → src/sdr/_link_budget/_capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import numpy.typing as npt

from ._helper import export
from .._helper import export


def Hb(x: npt.ArrayLike) -> np.ndarray:
Expand Down Expand Up @@ -60,7 +60,7 @@ def bsc_capacity(p: npt.ArrayLike) -> np.ndarray:
plt.tight_layout()
Group:
link-budget
link-budget-channel-capacity
"""
p = np.asarray(p)
if not (np.all(0 <= p) and np.all(p <= 1)):
Expand Down Expand Up @@ -108,7 +108,7 @@ def bec_capacity(p: npt.ArrayLike) -> np.ndarray:
plt.tight_layout()
Group:
link-budget
link-budget-channel-capacity
"""
p = np.asarray(p)
if not (np.all(0 <= p) and np.all(p <= 1)):
Expand Down Expand Up @@ -185,7 +185,7 @@ def awgn_capacity(snr: npt.ArrayLike, bandwidth: float | None = None) -> np.ndar
plt.tight_layout()
Group:
link-budget
link-budget-channel-capacity
"""
snr = np.asarray(snr)
snr_linear = 10 ** (snr / 10)
Expand Down
Loading

0 comments on commit fe8fa84

Please sign in to comment.