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 inside a virtual environment.
First install TensorFlow (CPU or GPU) following the official instructions, then:
pip install RamanujanFrameimport 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_qA dominant peak at energy[q-1] identifies period q in the signal.
See examples/ for runnable demos including a DFT comparison.
The Ramanujan sum for integer period q at sample n is
The sum runs over integers k coprime to q. c_q(n) is real-valued and integer-valued for all n.
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.
Given signal x of length N, RPT solves
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.
The energy of period q is the squared ℓ2 norm of its coefficients in the optimal solution:
[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.
Apache 2.0 — see LICENSE.