Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non_coherent_gain() #308

Merged
merged 16 commits into from
Mar 3, 2024
Merged
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
with:
fetch-depth: 0 # Fetch all commits and tags, needed for intermediate versions

- name: Set up Python 3.7
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: 3.8

- name: Upgrade pip and other packaging tools
run: python3 -m pip install --upgrade pip setuptools setuptools_scm wheel build twine
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10', 3.11, 3.12]
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
steps:
- uses: actions/checkout@v3

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
# strategy:
# matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
# python-version: [3.7, 3.8, 3.9, '3.10', 3.11, 3.12]
# python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v3
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9, '3.10', 3.11, 3.12]
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: v2.3.0
hooks:
- id: check-added-large-files
args: ['--maxkb=1000']
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
Expand Down
11 changes: 11 additions & 0 deletions docs/_static/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@
[data-md-color-scheme="slate"] img.no-invert {
filter: none;
}

/* Fix ugly cell borders for Jupyter notebooks */
div.cell_input.docutils.container {
border: transparent;
border-left-color: transparent;
}

div.cell_output.docutils.container>div {
border: transparent;
background: transparent;
}
10 changes: 10 additions & 0 deletions docs/api/detection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ Detectors

.. python-apigen-group:: detection-detectors

Coherent integration
-------------------

.. python-apigen-group:: detection-coherent-integration

Non-coherent integration
------------------------

.. python-apigen-group:: detection-non-coherent-integration

Theoretical limits
------------------

Expand Down
5 changes: 0 additions & 5 deletions docs/api/link-budgets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@ Antennas
--------

.. python-apigen-group:: link-budget-antennas

Coherent integration
--------------------

.. python-apigen-group:: link-budget-coherent-integration
606 changes: 606 additions & 0 deletions docs/examples/coherent-integration.ipynb

Large diffs are not rendered by default.

530 changes: 530 additions & 0 deletions docs/examples/non-coherent-integration.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ View all available classes and functions in the `API Reference <https://mhostett
examples/farrow-resampler.ipynb
examples/psk.ipynb
examples/phase-locked-loop.ipynb
examples/coherent-integration.ipynb
examples/non-coherent-integration.ipynb

.. toctree::
:caption: Development
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ classifiers = [
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand All @@ -43,7 +42,7 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
]
requires-python = ">=3.7"
requires-python = ">=3.8"
dependencies = [
"numpy", # Use galois's version limitation
"numba", # Use galois's version limitation
Expand Down
2 changes: 2 additions & 0 deletions src/sdr/_detection/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
A subpackage for various detection algorithms.
"""
from ._coherent_integration import *
from ._correlator import *
from ._energy import *
from ._non_coherent_integration import *
from ._theory import *
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
A module containing functions related to coherent gain loss.
A module containing functions related to coherent integration.
"""
from __future__ import annotations

Expand All @@ -16,25 +16,28 @@ def coherent_gain(
n_c: npt.ArrayLike,
) -> npt.NDArray[np.float64]:
r"""
Computes the SNR improvement by coherently integrating $N_c$ samples.
Computes the SNR improvement by coherently integrating $N_C$ samples.

Arguments:
n_c: The number of samples $N_c$ to coherently integrate.
n_c: The number of samples $N_C$ to coherently integrate.

Returns:
The coherent gain $G_c$ in dB.
The coherent gain $G_C$ in dB.

Notes:
$$y[m] = \sum_{n=0}^{N_c-1} x[m-n]$$
$$\text{SNR}_{y,\text{dB}} = \text{SNR}_{x,\text{dB}} + G_c$$
$$G_c = 10 \log_{10} N_c$$
$$y[m] = \sum_{n=0}^{N_C-1} x[m-n]$$
$$\text{SNR}_{y,\text{dB}} = \text{SNR}_{x,\text{dB}} + G_C$$
$$G_C = 10 \log_{10} N_C$$

Examples:
See the :ref:`coherent-integration` example.

Compute the coherent gain for various integration lengths.

.. ipython:: python

sdr.coherent_gain(1)
sdr.coherent_gain(2)
sdr.coherent_gain(10)
sdr.coherent_gain(20)

Expand All @@ -47,12 +50,12 @@ def coherent_gain(
@savefig sdr_coherent_gain_1.png
plt.figure(); \
plt.semilogx(n_c, sdr.coherent_gain(n_c)); \
plt.xlabel("Number of samples, $N_c$"); \
plt.ylabel("Coherent gain (dB), $G_c$"); \
plt.xlabel("Number of samples, $N_C$"); \
plt.ylabel("Coherent gain (dB), $G_C$"); \
plt.title("Coherent gain as a function of the number of integrated samples");

Group:
link-budget-coherent-integration
detection-coherent-integration
"""
n_c = np.asarray(n_c)
if np.any(n_c < 1):
Expand Down Expand Up @@ -104,7 +107,7 @@ def coherent_gain_loss(
plt.plot(f, sdr.coherent_gain_loss(0.5e-3, f), label="0.5 ms"); \
plt.plot(f, sdr.coherent_gain_loss(1e-3, f), label="1 ms"); \
plt.plot(f, sdr.coherent_gain_loss(2e-3, f), label="2 ms"); \
plt.legend(); \
plt.legend(title="Integration time"); \
plt.ylim(-5, 55); \
plt.xlabel("Frequency offset (Hz)"); \
plt.ylabel("Coherent gain loss (dB)"); \
Expand All @@ -121,14 +124,14 @@ def coherent_gain_loss(
plt.plot(t * 1e3, sdr.coherent_gain_loss(t, 100), label="100 Hz"); \
plt.plot(t * 1e3, sdr.coherent_gain_loss(t, 200), label="200 Hz"); \
plt.plot(t * 1e3, sdr.coherent_gain_loss(t, 400), label="400 Hz"); \
plt.legend(); \
plt.legend(title="Frequency offset"); \
plt.ylim(-5, 55); \
plt.xlabel("Integration time (ms)"); \
plt.ylabel("Coherent gain loss (dB)"); \
plt.title("Coherent gain loss for various frequency offsets");

Group:
link-budget-coherent-integration
detection-coherent-integration
"""
integration_time = np.asarray(integration_time)
freq_offset = np.asarray(freq_offset)
Expand Down Expand Up @@ -210,7 +213,7 @@ def max_integration_time(
plt.title("Maximum integration time for various frequency offsets");

Group:
link-budget-coherent-integration
detection-coherent-integration
"""
cgl = np.asarray(cgl)
freq_offset = np.asarray(freq_offset)
Expand Down Expand Up @@ -305,7 +308,7 @@ def max_frequency_offset(
plt.title("Maximum frequency offset for various integration times");

Group:
link-budget-coherent-integration
detection-coherent-integration
"""
cgl = np.asarray(cgl)
integration_time = np.asarray(integration_time)
Expand Down
Loading
Loading