Skip to main content

Ramanujan Frame Expansion and Periodicity Transform

Project description

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.

License

Apache 2.0 — see LICENSE.

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

ramanujanframe-0.0.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

ramanujanframe-0.0.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file ramanujanframe-0.0.1.tar.gz.

File metadata

  • Download URL: ramanujanframe-0.0.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for ramanujanframe-0.0.1.tar.gz
Algorithm Hash digest
SHA256 646098b6b7c35b85f1380cae048665516e15b655dbbcf27eb1c336c85675678d
MD5 0a0261743d3b5455d266dae55b24f154
BLAKE2b-256 3a5ba0ae301f4c5100b034c952c78b70483a1243f18e8bd39148ec3851ba3fcb

See more details on using hashes here.

File details

Details for the file ramanujanframe-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ramanujanframe-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for ramanujanframe-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b0023b3d8770f61771ca98b8dcfc0129fa7be3b439397e7e952e758b8ca63b30
MD5 ac7836613b0b3c510418570cc2d8fbec
BLAKE2b-256 f9fa0e5c45a534a358f61131a3ed44e05e496352c92fecd9b1d97c4f6aaeff9c

See more details on using hashes here.

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