Skip to main content

Flexible-grid approximations to continuous Fourier transforms

Project description

FlexFT

Documentation

FlexFT evaluates finite-sum approximations to continuous Fourier transforms (CFTs) on uniform input and output grids whose spacings can be chosen independently. It uses the Bailey-Swarztrauber fractional DFT/Bluestein convolution, implemented with JAX FFTs.

For samples f(x) on

x[n] = x0 + (n - floor(N / 2)) * dx

the forward transform flexft(f, dx=dx, dk=dk, x0=x0, k0=k0) returns approximations on

k[m] = k0 + (m - floor(N / 2)) * dk.

Computational cost

flexft uses Bluestein's algorithm to rewrite the discretised CFT approximation as a linear convolution, then evaluates that convolution with FFTs. A one-shot transform currently needs two forward FFTs and one inverse FFT, each of length 2N, where N is the number of samples.

The asymptotic complexity is therefore the same as an FFT, but with a larger constant prefactor. When the convolution kernel is precomputed by reusing a FlexFT plan, each subsequent transform needs only one forward FFT and one inverse FFT of length 2N.

Installation

pip install flexft

The quick-start plot below also uses Matplotlib.

Quick start

import jax.numpy as jnp
import matplotlib.pyplot as plt
from flexft import flexft

N = 512
dx = 0.04
dk = 0.01

x = (jnp.arange(N) - N // 2) * dx
k = (jnp.arange(N) - N // 2) * dk

# With the convention F(k) = integral f(x) exp(-i 2 pi k x) dx,
# exp(-pi x^2) is its own continuous Fourier transform.
f = jnp.exp(-jnp.pi * x**2)
F_flexft = flexft(f, dx=dx, dk=dk)
F_exact = jnp.exp(-jnp.pi * k**2)

fig, ax = plt.subplots(figsize=(6, 3.5))
ax.plot(k, F_exact, label="exact", linewidth=2)
ax.plot(k, F_flexft.real, "--", label="flexft", linewidth=2)
ax.set(xlabel="k", ylabel="F(k)")
ax.legend()
fig.tight_layout()
fig.savefig("docs/assets/readme-quick-start.png", dpi=200)

FlexFT approximation compared with the exact Gaussian transform

Omit dk in the forward transform to use the FFT-compatible spacing 1 / (N * dx). Conversely, omit dx in the inverse transform to use 1 / (N * dk).

For repeated transforms with unchanged grids, construct and reuse FlexFT or IFlexFT; this reuses the precomputed convolution kernel.

Documentation

Read the full documentation for the derivation, shifted grids, 2D transforms, API reference, and more examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flexft-0.1.1.tar.gz (229.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flexft-0.1.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file flexft-0.1.1.tar.gz.

File metadata

  • Download URL: flexft-0.1.1.tar.gz
  • Upload date:
  • Size: 229.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flexft-0.1.1.tar.gz
Algorithm Hash digest
SHA256 69514cfb7c4f65c8355fbe21791cb58f48a1afb4b8bda4154e99fa30165b9e7d
MD5 1b10d60c81e9acf338486e854196538f
BLAKE2b-256 3330b5a305d606334ee1a22a0c6765b7a6679f94a460a07e4a304fd6e146a1f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for flexft-0.1.1.tar.gz:

Publisher: publish.yml on tomsturges/FlexFT

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flexft-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: flexft-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flexft-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7421f7f06be11c45f372c9573a8f45603c8cb6f3e4d89e5dab00150b7b8f0361
MD5 25d66120db12fa7bd8e13eee6fb0fb41
BLAKE2b-256 9591fdd4a783a892f8445fe2e55c4b4afaa6be0da6cb7a20710ecffa94bc3c43

See more details on using hashes here.

Provenance

The following attestation bundles were made for flexft-0.1.1-py3-none-any.whl:

Publisher: publish.yml on tomsturges/FlexFT

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page