# Test to distinguish periodic from almost periodic data

Suppose I have some unknown function $f$ with domain $ℝ$, which I know to fulfill some reasonable conditions like continuity. I know the exact values of $f$ (because the data comes from a simulation) at some equidistant sampling points $t_i=t_0 + iΔt$ with $i∈\{1,…,n\}$, which I can assume to be sufficiently fine to capture all relevant aspects of $f$, e.g., I can assume that there is at most one local extremum of $f$ in between two sampling points. I am looking for a test that tells me whether my data complies with $f$ being exactly periodic, i.e., $∃τ: f(t+τ)=f(t) \,∀\,t$, with the period length being somewhat resonable, for example $Δt < τ < n·Δt$ (but it’s conceivable that I can make stronger constraints, if needed).

From another point of view, I have data ${x_0, …, x_n}$ and am looking for a test that answers the question whether a periodic function $f$ (fulfilling conditions as above) exists such that $f(t_i)=x_i ∀ i$.

The important point is that $f$ is at least very close to periodicity (it could be for example $f(t) := \sin(g(t)·t)$ or $f(t) := g(t)·\sin(t)$ with $g'(t) ≪ g(t_0)/Δt$) to the extent that changing one data point by a small amount may suffice to make the data comply with $f$ being exactly periodic. Thus standard tools for frequency analysis such as the Fourier transform or analysing zero crossings will not help much.

Note that the test I am looking for will likely not be probabilistic.

I have some ideas how to design such a test myself but want to avoid reinventing the wheel. So I am looking for an existing test.

• Given that you have data, could you explain what you mean by the test not being "statistical"? What kind of test do you have in mind then?
– whuber
Sep 13 '14 at 18:43
• By the way, you might want to start here in case you are looking for a statistical test of periodicity. Sep 13 '14 at 19:06
• How were the sampling points determined? Since you presumably don't know exactly what $f$ is, then if someone else were to sample $f$, wouldn't they use different "times" and therefore obtain different values? That's variability. Incidentally, there is no such thing as exact data unless you are performing a theoretical mathematical exercise, so it would be a good idea to explain how you have found the values of $f$.
– whuber
Sep 13 '14 at 21:49
• As @whuber and amoeba are driving at, this question will remain difficult to answer until a satisfactory definition of periodic and/or test is supplied. Given $n$ arbitrary points sampled without error there are infinitely many continuous periodic functions (using the literal definition) that will fit the points. It's a simple exercise in interpolation. But this is obviously no more an answer to your question than the fact that a set of $n$ random predictors will perfectly fit $n$ points via linear regression. Hence, we wait with bated breath for your clarification. Sep 19 '14 at 23:41
• For any $\tau$ that is not a rational multiple of $\Delta t$, the data you have can always be viewed as a sample of a continuous periodic function of period $\tau$ because you have no observations exactly an integral multiple of $\tau$ apart. This leads to @cardinal's observations, which amount to noting that this conclusion is too trivial to be useful but nevertheless you haven't provided any criteria to rule it out.
– whuber
Sep 22 '14 at 16:05

As I said, I had an idea how to do this, which I realised, refined and wrote a paper about, which is now published: Chaos 25, 113106 (2015)preprint on ArXiv.

The investigated criterion is almost the same as sketched in the question: Given data $x_1, \ldots, x_n$ sampled at time points $t_0, t_0 + Δt, \ldots, t_0 + nΔt$, the test decides whether there is a function $f: [t_0, t_0 + Δt] → ℝ$ and a $τ ∈ [2Δt,(n-1)Δt]$ such that:

• $f(t_0 + iΔt)=x_i\quad \forall i∈\{1,…,n\}$
• $f(t+τ)=f(t) \quad∀t∈[t_0, t_0 + Δt-τ]$
• $f$ has no more local extrema than the sequence $x$, with the possible exception of at most one extremum close to the beginning and end of $f$ each.

The test can be modified to account for small errors, such as numerical errors of the simulation method.

I hope that my paper also answers why I was interested in such a test.

Transform the data into frequency domain using the discrete Fourier transform (DFT). If the data is perfectly periodic, there will be exactly one frequency bin with a high value, and other bins will be zero (or near zero, see spectral leakage).

Note that the frequency resolution is given by $\frac{\text{sampling frequency}}{\text{Number of samples}}$. So this sets the limit for the detection precision.

• As I already stated in the question, the Fourier transform (at least all by itself) is not even remotely precise enough to detect the differences I am interested in and will hardly detect any difference between $\sin(x)$ and $(1+εx)·\sin(x)$. Also, what you are claiming only holds for sinusoidal data. For any other data, the subharmonics will show up. Sep 16 '14 at 14:16

If you know the actual periodic signal, calculate

$\text{difference} = \Big|\text{theoretical data} - \text{measured data}\big|$

Then sum the elements of $\text{difference}$. If it is above a threshold (consider error from floating point arithmetic) the data is not periodic.

• Apart from the fact that I do not know the underlying signal, this has nothing to do with periodicity but would work whenever I know the underlying signal. Sep 16 '14 at 14:23