How this calculation works
Lagged cross-correlation compares two real sequences while shifting their relative alignment. At each integer lag it sums products only where the shifted samples overlap. Unlike a single Pearson coefficient, it returns a full lag profile and can compare unequal sequence lengths. Autocorrelation reuses x as both inputs on this page. Optional global mean removal and whole-sequence energy normalization are explicit choices rather than hidden assumptions.
rxy[k] = Σj x[j+k]y[j], with zeros outside the entered ranges; k runs from −(M−1) to N−1.A worked example
For x = [1,2,3] and y = [4,5], the lag values −1, 0, 1 and 2 produce raw sums 5, 14, 23 and 12. At lag one the overlap pairs are 2×4 and 3×5, giving 23. That is the strongest absolute correlation in this example, so the reported lag is one under the stated convention.
Good to know
Each real sequence has 1–512 samples and values within ±10¹². Sample spacing is treated as uniform but no physical time unit is inferred. Energy normalization uses complete sequences rather than recomputing Pearson correlation on each overlap. Zero-energy normalized inputs are rejected. Raw correlation can reflect offsets and amplitudes; its peak does not by itself prove causation or a unique physical delay.
Reference: SciPy — full correlation definition and lag orientation (opens in a new tab) ↗
The sign of a lag depends on the declared convention
This page uses x[j+k] times y[j]. A positive lag therefore advances the index used from x relative to y. Another program may define the opposite convention, so comparing only the signed peak number can be misleading. The displayed formula and overlap counts provide an unambiguous check. Swapping x and y reverses the lag profile for real data.
For unequal lengths N and M, the full zero-padded result has N + M − 1 lags. At either extreme only one pair overlaps. The table records that overlap count so a large edge-lag value can be interpreted in context rather than treated as supported by the same number of pairs as a central lag. Equal absolute peaks choose the lag nearest zero, then the smaller signed lag.
The Discrete Fourier transform calculator for complex sequences shows frequency-bin coefficients rather than overlap-wise lag scores.
Global energy scaling is not overlap-wise Pearson correlation
Normalized mode divides all lag sums by √Σx² times √Σy² after any optional centering. This keeps the same denominator across the entire profile. It does not subtract a separate mean or recompute an energy denominator for each overlap, and it is not an unbiased autocovariance estimator. Those alternative definitions can produce different peak sizes, particularly near the edges.
Autocorrelation at zero lag equals total energy in raw mode and one in energy-normalized mode for a nonzero sequence. A constant sequence becomes zero-energy after global mean removal, so its normalized result is undefined and rejected. The existing Pearson and Spearman calculators answer different paired-observation questions. The discrete Fourier transform calculator instead changes a sequence’s representation into frequency bins; it is not a substitute for deciding which lag convention and scaling match a comparison task.
A few questions, answered
Can correlation values be negative?
Yes. Opposing sample signs can produce a negative product sum. The headline selects the largest absolute correlation and retains its signed value.
Does a lag of three mean three seconds?
Only if samples are one second apart. Multiply lag by the actual sample spacing to obtain a physical duration.