Time Series Plots

Time-series EDA assumes the model y = f(t) + e — a signal component plus random error. The plots in this section reveal dominant frequencies, autocorrelation structure, and the amplitude/phase evolution of the signal.

All time-series plots require a continuous index variable t (not restricted to calendar time — scan number, wavelength, and position all qualify).

Reference: NIST Handbook Chapter 1.3.3

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from drippy import EDAData
from drippy import (
    run_sequence_plot,
    spectral_plot,
    autocorrelation_plot,
    complex_demodulation_amplitude_plot,
    complex_demodulation_phase_plot,
)

rng = np.random.default_rng(42)

# 200-point sinusoidal signal — beam-deflection-like measurement
t = np.linspace(0, 10, 200)
noise = rng.normal(scale=0.5, size=200)
y = 2.0 * np.sin(2 * np.pi * 0.5 * t) + noise
data = EDAData(y=y, t=t)

Run Sequence Plot (NIST 1.3.3.25)

The run-sequence plot is the natural first step for time-series data. When t is provided, it becomes the x-axis, giving the correct physical scale.

fig, ax = run_sequence_plot(data)
plt.show()
../_images/67b8dd02eaaf151d16ffe74fb0ee3c36742d00858406a873a1ee44518d0e9ddb.png

Spectral Plot (NIST 1.3.3.27)

The Lomb-Scargle periodogram estimates the power spectral density, identifying dominant frequencies even for unevenly-sampled data. Optional false alarm probability (FAP) levels flag statistically significant peaks.

fig, ax = spectral_plot(data)
plt.show()
/home/docs/checkouts/readthedocs.org/user_builds/drippy/envs/latest/lib/python3.12/site-packages/astropy/timeseries/periodograms/lombscargle/_statistics.py:140: RuntimeWarning: invalid value encountered in scalar power
  return (1 - z) ** (0.5 * Nk)
../_images/493fcd4ac0dc116e3bb4ea05a5f000beb2cb7b977e7d27520f911e8f7ea1752a.png

The dominant peak at 0.5 Hz recovers the known signal frequency. Without alarm levels:

fig, ax = spectral_plot(data, alarm_levels=False)
plt.show()
../_images/0f47820a0fc570b9a4240ce36c2b91c197c26aebf8f65baccc5471bfa03b5fb0.png

Autocorrelation Plot (NIST 1.3.3.1)

Plots the autocorrelation function (ACF) with 80%, 95%, and 99% confidence bands. Lags whose bars exceed the bands indicate significant autocorrelation — evidence of non-randomness at that lag.

fig, ax = autocorrelation_plot(data)
plt.show()
../_images/b9a52a566ebb96c335626e63faf041dedab51330dd892769190aff95c78507e3.png

Complex Demodulation Amplitude Plot (NIST 1.3.3.11)

Demodulates the signal at its dominant frequency and plots the instantaneous amplitude envelope. A flat envelope indicates a stationary amplitude; rising or falling envelopes reveal non-stationarity.

fig, ax = complex_demodulation_amplitude_plot(data)
plt.show()
../_images/24c9c8a23cb2b210a52b2850d8e3e98d7efe93d4ccfacd8f764ab283e00885cf.png

Complex Demodulation Phase Plot (NIST 1.3.3.12)

Plots the unwrapped instantaneous phase with a linear trend fit. Deviations from the trend indicate frequency modulation or phase noise in the signal.

fig, ax = complex_demodulation_phase_plot(data)
plt.show()
../_images/97e8d1acdce19b89ba5a66f38be7614871b0a0e72ca7dd64ca4f314dbb96caa4.png