Metadata-Version: 2.5
Name: cafest
Version: 0.1.0
Summary: Frequency-shift (Doppler) estimation from the cross-ambiguity function: methods, Cramér–Rao bounds, signals
Project-URL: Homepage, https://github.com/ekomarova/cafest
Project-URL: Documentation, https://github.com/ekomarova/cafest/blob/main/docs/API.md
Project-URL: Repository, https://github.com/ekomarova/cafest
Project-URL: Issues, https://github.com/ekomarova/cafest/issues
Author: Evseniia Komarova
License-Expression: BSD-3-Clause
License-File: LICENSE
Keywords: caf,cramer-rao-bound,cross-ambiguity-function,doppler,frequency-estimation,frequency-shift,signal-processing,spectral-estimation
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.11
Requires-Dist: numpy
Requires-Dist: scipy
Description-Content-Type: text/markdown

# CAFest

Test bench and reference implementations of 13 estimators of the frequency shift (Doppler) between a reference and a received signal, computed from their cross-ambiguity function (CAF). One call, the same data, accuracy against the Cramér–Rao bound, and speed.

## Installing

```
pip install cafest
```

Python 3.11 or newer.

## Example

```python
import cafest
from cafest import GridSpec
from cafest.signals import SignalSpec, generate

pair = generate(SignalSpec(shift=2345.6, snr_db=10.0), seed=1)   # test signals: pair.ref, pair.rx; the true shift is 2345.6 Hz
grid = GridSpec(fs=600e3, f_min=0.0, f_max=10e3, df=1.0)          # frequencies to search, Hz

for method in ("fft-unpadded", "czt", "hierarchical"):
    print(method, cafest.estimate(method, pair.ref, pair.rx, grid).f_hat)
# fft-unpadded 2340.0    the nearest bin of the FFT, 60 Hz wide
# czt 2346.0             the nearest node of the 1 Hz grid
# hierarchical 2345.54   refined between the nodes
```

![The CAF near its peak and its values at the bins of fft-unpadded](https://raw.githubusercontent.com/ekomarova/cafest/main/docs/img/caf_peak.png)

The figure shows the CAF of this pair near its peak (blue) and what `fft-unpadded` sees of it: the FFT without zero padding gives the CAF only at bins `fs/N` = 60 Hz apart (orange), so its maximum is found to within a bin. `czt` evaluates the CAF on the 1 Hz grid you give it, and `hierarchical` refines the maximum between the nodes.

### Your own signals

`ref` and `rx` can be any 1-D complex arrays, not only those made by `cafest.signals`; `GridSpec(fs=...)` must be their real sampling rate, otherwise the result is in wrong Hz.

```python
grid = GridSpec(fs=250e3, f_min=0.0, f_max=3000.0, df=1.0)   # signals sampled at 250 kHz, search 0..3000 Hz
print(cafest.estimate("fft-zeropad", ref, rx, grid).f_hat)    # ref, rx: your arrays of equal length
```

## Who it is for

- Researchers and students in passive radar, GNSS and sonar who need to choose or compare CAF-based frequency-shift estimators.
- Authors of a new method: put it behind the same call and compare it with the others.

## What it does and does not do

It covers the estimation stage: given a reference and a received signal (and, for an unknown delay, a window of lags) it returns the frequency shift in Hz. Pre-processing (clutter and direct-signal suppression), detection (CFAR) and tracking are outside the package. CPU only.

The model is one constant frequency shift (narrowband Doppler) of one target; scaling of the time axis (the wideband ambiguity function), a drifting shift and several shifts in one pair are not modelled.

The input is one pair of 1-D signals. Several channels, batches of pairs or 2-D signals are not supported (`estimate` raises `ValueError` for an array that is not 1-D); to process many pairs, call `estimate` in a loop.

## Methods

13 methods in three groups:

| group | methods |
|---|---|
| CAF on a frequency grid | `fft-zeropad`, `czt`, `filterbank-overlap-save`, `filterbank-scipy`, `block-decim` |
| coarse spectrum (bins `fs/N` wide, no zero padding) | `fft-unpadded` |
| refinement of the peak | `parabolic-interp`, `three-bin-interp`, `hierarchical`, `dtft-newton`, `capon-burg`, `capon-sample`, `music` |

![Estimates of the 13 methods at low and at high noise](https://raw.githubusercontent.com/ekomarova/cafest/main/docs/img/method_estimates.png)

Two ways to call it: with a known delay (the signals are aligned), or with `lags=(lo, hi)` to search a window of lags for the delay.

### Which method to choose

| if you need | start with |
|---|---|
| the CAF on a grid of any step and band | `czt` (no grid restrictions); `fft-zeropad` when `fs/df` is an integer |
| an estimate finer than the grid step | `hierarchical` (coarse grid, then a fine search around the peak); `dtft-newton` (no grid: Newton's method on the peak of the FFT) |
| a cheap refinement of an FFT peak | `parabolic-interp` on a fine grid; `three-bin-interp` for a tone that fills the whole frame |
| an unknown delay (`lags=(lo, hi)`) | any grid method over a window of lags; the refiners first find the lag with a coarse `fft-unpadded` stage |
| all lags at once | `block-decim` (block sums; `d = 1` is exact, a larger `d` is approximate and suits small shifts) |
| high-resolution spectral estimates | `capon-sample`, `music`: expensive, mostly for comparison |

## Status and limitations

Early version (0.1.0, alpha). Results come from simulation on synthetic signals with white noise; do not transfer conclusions about which method is better to real data without checking. See "Known limitations" in [docs/OVERVIEW.md](https://github.com/ekomarova/cafest/blob/main/docs/OVERVIEW.md).

## Building

The package is pure Python. Build it from the repository root with [uv](https://docs.astral.sh/uv/); the build backend is hatchling and uv fetches it itself:

```
uv build --wheel
```

The wheel appears in `dist/`. Install it with `pip install dist/*.whl`.

## More information

- [docs/OVERVIEW.md](https://github.com/ekomarova/cafest/blob/main/docs/OVERVIEW.md): how the package works, where each method comes from (the methods are implementations of published algorithms), the signal model and input data, what is checked, known limitations, references.
- [docs/API.md](https://github.com/ekomarova/cafest/blob/main/docs/API.md): full description of `estimate`, `Result` and the method parameters.
- [tests/sanity/](https://github.com/ekomarova/cafest/tree/main/tests/sanity): quick acceptance tests with known answers (`pytest -m sanity`); each test file starts with a docstring that says what it checks.
