stats.spectral.compute_periodogram

stats.spectral.compute_periodogram(
    y,
    *,
    max_peaks=5,
    scaling='spectrum',
    fs=None,
)

Compute the periodogram of a time series.

Wraps scipy.signal.periodogram with a boxcar window to match the reference implementation.

Parameters

Name Type Description Default
y pd.Series Series to analyse. Must be a non-empty pandas Series without missing values (validated via check_y). required
max_peaks int Number of top peaks to surface. 5
scaling str Spectrum scaling forwarded to scipy. 'spectrum'
fs Optional[float] Sampling frequency. Defaults to 1.0 (cycles per sample). None

Returns

Name Type Description
PeriodogramResult A PeriodogramResult with the full spectrum and the
PeriodogramResult top-max_peaks periods.

Raises

Name Type Description
TypeError If y is not a pandas Series.
ValueError If y contains missing values.

Examples

import numpy as np
import pandas as pd

from spotforecast2_safe.stats.spectral import compute_periodogram

t = np.arange(512)
y = pd.Series(np.sin(2 * np.pi * t / 32))
result = compute_periodogram(y, max_peaks=1)
print(int(round(result.top_periods.index[0])))
32