Skip to main content

PyNAFF

Authors:

  • Foteini Asvesta (fasvesta .at. cern .dot. ch)
  • Nikos Karastathis (nkarast .at. cern .dot. ch)
  • Panagiotis Zisopoulos (pzisopou .at. cern .dot. ch)

A Python implementation of J. Laskar's Numerical Analysis of Fundamental Frequencies (NAFF) method.

Installation

python -m pip install PyNAFF

Single BPM

import numpy as np
import PyNAFF as pnf

t = np.arange(3001)
signal = np.sin(2.0 * np.pi * 0.12345 * t)
result = pnf.naff(signal, turns=500, nterms=1, window=1)

# Each row is:
# [order, frequency, amplitude, real amplitude, imaginary amplitude]
frequency = result[0, 1]

turns is the number of integration intervals, so the input must contain at least turns + 1 observations. For real sinusoids, the reported amplitude is the magnitude of one complex Fourier coefficient, equal to half the sinusoid's peak amplitude.

Multiple BPMs

Place observations on axis 0 and BPMs on axis 1:

signals = np.column_stack([
    np.sin(2.0 * np.pi * 0.12345 * t),
    2.0 * np.sin(2.0 * np.pi * 0.27123 * t),
])
results = pnf.naff(signals, turns=500, nterms=1)

# results.shape == (2 BPMs, 1 term, 5 values)
frequencies = results[:, 0, 1]
amplitudes = results[:, 0, 2]

For multi-BPM input, unused term rows are filled with NaN when extraction for a BPM stops before nterms.

The tol option controls duplicate residual handling as a fraction of one FFT bin. If NAFF stops early because a residual peak is very close to a previously extracted frequency, increasing tol can let it remove that residual and continue to weaker frequencies. The default is 1e-4; large values can also turn spectral leakage into spurious frequencies, so compare results across several values. nterms is an upper bound, not a guaranteed result count.

For real input, prefer getFullSpectrum=False. A full spectrum contains both positive and negative conjugate frequencies, and each one occupies a result row.

Metadata

Release files for PyNAFF 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyNAFF 1.2.0
File Size Uploaded
pynaff-1.2.0.tar.gz 20.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyNAFF 1.2.0
File Interpreter ABI Platform
pynaff-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.7 kB

Release files / pynaff-1.2.0.tar.gz

Download URL pynaff-1.2.0.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b93651927999f666e061aaf0d1f82c816a60b65132eacaceb6fb533754131291
BLAKE2b-256 checksum
How to use checksums
d1dd0d294d11552dcf1cea94b2280c44f55de7fe3075f30e7e33282310b6a38f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.10

Release files / pynaff-1.2.0-py3-none-any.whl

Download URL pynaff-1.2.0-py3-none-any.whl
Size 18.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c382584e72564a651714cb46867a501b7e9a4e680bac77b079b4975c5812057
BLAKE2b-256 checksum
How to use checksums
029863c68e5fa24d2f18d54060f0bd8c47933d54d05706b80c6a6e109998c1ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.10

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

3 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

3 release files

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page