Skip to main content

RamanujanFrame

PyPI Version Python Versions TensorFlow CVXPY License

Ramanujan Frame Expansion and Periodicity Transform (RPT)

Ramanujan Frames are overcomplete dictionaries built from Ramanujan sums and their cyclic shifts, spanning all integer periods 1 to Q (maximum period to be detected) for discrete signals of length N. Decomposing a signal over this frame via sparse ℓ1 minimization (the Ramanujan Periodicity Transform, RPT) identifies the exact integer periods present through the subspace energies. They are particularly useful in detecting hidden periodicities in short discrete sequences that the Discrete Fourier Transform cannot resolve when the period does not divide the signal length.

Install

Install inside a virtual environment.

First install TensorFlow (CPU or GPU) following the official instructions, then:

pip install RamanujanFrame

Usage

import numpy as np
from RamanujanFrame import RamanujanDict

# Build the Ramanujan dictionary
# N : signal length
# Q : search periods 1 ... Q
rd = RamanujanDict(N=64, Q=16)

# Decompose a signal
signal = np.array([1.0, 0.6, -0.2, -0.8, -0.4] * 13, dtype=np.float32)  # period-5
coeffs, energy = rd.solve_for_y_optimal(signal)

# coeffs : ndarray (Φ(Q), 1)  optimal Ramanujan coefficients y★
# energy : list of Q floats   energy per Ramanujan subspace S_q

A dominant peak at energy[q-1] identifies period q in the signal. See examples/ for runnable demos including a DFT comparison.


How it works

Ramanujan sum

The Ramanujan sum for integer period q at sample n is

$$c_q(n) = \sum_{\substack{k=1 \ \gcd(k,,q)=1}}^{q} e^{,j\frac{2\pi}{q}kn}$$

The sum runs over integers k coprime to q. c_q(n) is real-valued and integer-valued for all n.

Ramanujan dictionary A

For each period q = 1, ..., Q the dictionary includes φ(q) columns: c_q(n) and its φ(q) − 1 cyclic shifts, where φ is Euler's totient function. The full matrix A has shape (N, Φ(Q)) where Φ(Q) = Σ_{q=1}^{Q} φ(q).

When Φ(Q) > N the columns form an overcomplete frame for the N-dimensional signal space. This is the key advantage over the Discrete Fourier Transform (DFT) basis {W_N^k | k divides N} which covers only the divisors of N and cannot represent all integer periods.

Sparse decomposition (RPT)

Given signal x of length N, RPT solves

$$\min_{y} ;|Dy|_1 \quad \text{subject to} \quad Ay = x$$

D is a diagonal penalty matrix with D_{ii} = φ(P_i), where P_i is the period index of column i. The ℓ1 norm promotes sparsity across Ramanujan subspaces. Solved via CVXPY with the ECOS solver.

Subspace energy

The energy of period q is the squared ℓ2 norm of its coefficients in the optimal solution:

$$E_q = \sum_{i:,P_i = q} |y^\star_i|^2$$


References

[1] P. P. Vaidyanathan and S. Tenneti, "Srinivasa Ramanujan and signal-processing problems," Philosophical Transactions of the Royal Society A, vol. 378, no. 2163, p. 20180446, 2020.

Citation

This software is released for broad research, educational, and engineering use. If this package helps your work, please cite the following paper:

@misc{tarafdar2026interpretablefrugallearningsystems,
      title={Interpretable and Frugal Learning Systems Employing Multiresolution Pyramids and Volterra Kernels},
      author={Kishore Kumar Tarafdar},
      year={2026},
      eprint={2606.15011},
      archivePrefix={arXiv},
      primaryClass={eess.SP},
      url={https://arxiv.org/abs/2606.15011},
}

License

Apache 2.0 — see LICENSE.

Metadata

Release files for RamanujanFrame 0.0.3

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

Source distribution (sdist)

Source distribution for RamanujanFrame 0.0.3
File Size Uploaded Provenance
ramanujanframe-0.0.3.tar.gz 9.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for RamanujanFrame 0.0.3
File Interpreter ABI Platform
ramanujanframe-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 20.1 kB

Release files / ramanujanframe-0.0.3.tar.gz

Download URL ramanujanframe-0.0.3.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4367d9c1f436ea51fb76546370fa2f105897d8f710d672687aebeba1d4f336dc
BLAKE2b-256 checksum
How to use checksums
64d8381555a63aa35d772485443b5b41c57845e9fdacde7efd9ac90ab03e514c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / ramanujanframe-0.0.3-py3-none-any.whl

Download URL ramanujanframe-0.0.3-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3bc5a3035c5294a9f66b20c190bc846dfebfa95299f1c063e3d8b5c54ad3e713
BLAKE2b-256 checksum
How to use checksums
eb4c5b026d893e493b1fc82f3016723960a91ea0a0fecd636e73221e379f2ea4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for RamanujanFrame 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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