LOMBSCARGLE

The Lomb-Scargle periodogram estimates spectral power for data sampled at uneven time intervals. It computes a least-squares fit of sinusoidal components across a set of angular frequencies, making it useful when standard FFT assumptions of uniform sampling are not met.

For observations (x_i, y_i) and angular frequency \omega, the method estimates power by fitting sinusoidal terms and evaluating the fit quality over the supplied frequency grid.

Excel Usage

=LOMBSCARGLE(x, y, freqs, precenter, normalize)
  • x (list[list], required): Sample times (Excel range).
  • y (list[list], required): Observed signal values (Excel range).
  • freqs (list[list], required): Angular frequency grid (radians per unit time) (Excel range).
  • precenter (bool, optional, default: false): If True, subtract the mean of y before computing the periodogram.
  • normalize (bool, optional, default: false): If True, normalize periodogram values by the residual variance.

Returns (list[list]): A 2D array where the first row is angular frequencies and the second row is Lomb-Scargle power values.

Example 1: Unevenly sampled signal periodogram

Inputs:

x y freqs
0 0.8 1.9 3.1 4.7 6 0 0.7 1 0.2 -0.8 -0.3 0.5 1 1.5 2

Excel formula:

=LOMBSCARGLE({0,0.8,1.9,3.1,4.7,6}, {0,0.7,1,0.2,-0.8,-0.3}, {0.5,1,1.5,2})

Expected output:

Result
0.5 1 1.5 2
0.662122 1.1068 0.156344 0.0138262
Example 2: Periodogram with precentering

Inputs:

x y freqs precenter
0 1.3 2 3.8 5.2 1.2 1.4 0.2 -0.6 -0.3 0.4 0.9 1.4 true

Excel formula:

=LOMBSCARGLE({0,1.3,2,3.8,5.2}, {1.2,1.4,0.2,-0.6,-0.3}, {0.4,0.9,1.4}, TRUE)

Expected output:

Result
0.4 0.9 1.4
1.24138 1.44547 0.278972
Example 3: Periodogram with normalization

Inputs:

x y freqs normalize
0 1 2 4 7 0.2 0.9 0.1 -0.5 -0.1 0.3 0.7 1.1 true

Excel formula:

=LOMBSCARGLE({0,1,2,4,7}, {0.2,0.9,0.1,-0.5,-0.1}, {0.3,0.7,1.1}, TRUE)

Expected output:

Result
0.3 0.7 1.1
0.403186 0.748432 0.589561
Example 4: Single angular frequency input

Inputs:

x y freqs
0 1 2 3 1 0.5 -0.2 -0.8 1.2

Excel formula:

=LOMBSCARGLE({0,1,2,3}, {1,0.5,-0.2,-0.8}, 1.2)

Expected output:

Result
1.2
0.924347

Python Code

Show Code
import numpy as np
from scipy.signal import lombscargle as scipy_lombscargle

def lombscargle(x, y, freqs, precenter=False, normalize=False):
    """
    Estimate a Lomb-Scargle periodogram for unevenly sampled data.

    See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.lombscargle.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        x (list[list]): Sample times (Excel range).
        y (list[list]): Observed signal values (Excel range).
        freqs (list[list]): Angular frequency grid (radians per unit time) (Excel range).
        precenter (bool, optional): If True, subtract the mean of y before computing the periodogram. Default is False.
        normalize (bool, optional): If True, normalize periodogram values by the residual variance. Default is False.

    Returns:
        list[list]: A 2D array where the first row is angular frequencies and the second row is Lomb-Scargle power values.
    """
    try:
        def to_1d(v):
            if isinstance(v, list):
                if all(isinstance(row, list) for row in v):
                    return np.array([float(x) for row in v for x in row], dtype=float)
                return np.array([float(x) for x in v], dtype=float)
            return np.array([float(v)], dtype=float)

        x_arr = to_1d(x)
        y_arr = to_1d(y)
        freqs_arr = to_1d(freqs)

        if x_arr.size != y_arr.size:
            return "Error: x and y must contain the same number of elements"
        if freqs_arr.size == 0:
            return "Error: freqs must contain at least one value"

        pgram = scipy_lombscargle(
            x_arr,
            y_arr,
            freqs_arr,
            precenter=bool(precenter),
            normalize=bool(normalize)
        )

        return [freqs_arr.tolist(), pgram.tolist()]
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Sample times (Excel range).
Observed signal values (Excel range).
Angular frequency grid (radians per unit time) (Excel range).
If True, subtract the mean of y before computing the periodogram.
If True, normalize periodogram values by the residual variance.