Your Equation

Library / Signal processing and digital filters / DSP-23

Signal processing and digital filters

Cross-correlation at a signed lag

Unnormalised cross-correlation of two real sequences (up to 6 samples each, zero outside) at lag ℓ.

Ref
DSP-23
Rev
v1
Field
Signal processing and digital filters
Result
rxy [V²]

The unnormalised cross-correlation r_xy[ℓ] = Σ x[n]y[n − ℓ] slides y past x and sums the products. A positive peak lag means x is a delayed copy of y. For different signals, the units are the product of their units. For complex data, conjugate y. Normalise by √(Ex·Ey) to compare across signals.

Unnormalised cross-correlation of two real sequences (up to 6 samples each, zero outside) at lag ℓ. A positive peak lag means x is delayed relative to y. For different signal units, the output has the product of the units. For complex data, conjugate y.

Calculator

Solve for
V²
samples
−55
V
−1010
V
−1010
V
−1010
V
−1010
V
−1010
V
−1010
V
−1010
V
−1010
V
−1010
V
−1010
V
−1010
V
−1010
  • Energy of x, Σx²5 V²
  • Energy of y, Σy²5 V²
  • Normalised correlation, r/√(ExEy)1

What drives the result

Each variable is moved across its typical range while the others stay at the values above. The longest bar is the key driver.

Cross-correlation (V²) current value 5 V²
x2Sample of x 2Key driver
−1921
y1Sample of y 1
−1921
x1Sample of x 1
−614
y0Sample of y 0
−614
ℓLag
0
x0Sample of x 0
x3Sample of x 3
x4Sample of x 4
x5Sample of x 5
y2Sample of y 2
y3Sample of y 3
y4Sample of y 4
y5Sample of y 5
  • At lag 1 the correlation is 5 V², a normalised value of 1.
  • A normalised value near 1 means the two sequences match at this lag; sweep the lag to find where it peaks, which gives the delay in samples.
Chart data as tables

Ranked variables

VariableTypical rangeLowest resultHighest resultSwing (V²)Local stepChange in result
x2 Sample of x 2−10 to 10 V−192140+0.4 V+16 %
y1 Sample of y 1−10 to 10 V−192140+0.4 V+16 %
x1 Sample of x 1−10 to 10 V−61420+0.4 V+8 %
y0 Sample of y 0−10 to 10 V−61420+0.4 V+8 %
ℓ Lag−5 to 5 samples055+1 samples−60 %
x0 Sample of x 0−10 to 10 V550+0.4 V0 %
x3 Sample of x 3−10 to 10 V550+0.4 V0 %
x4 Sample of x 4−10 to 10 V550+0.4 V0 %
x5 Sample of x 5−10 to 10 V550+0.4 V0 %
y2 Sample of y 2−10 to 10 V550+0.4 V0 %
y3 Sample of y 3−10 to 10 V550+0.4 V0 %
y4 Sample of y 4−10 to 10 V550+0.4 V0 %
y5 Sample of y 5−10 to 10 V550+0.4 V0 %

Sweep of Lag

Lag (samples)Cross-correlation (V²)
−50
−3.750
−2.50
−1.250
02
1.255
2.50
3.750
50

Sweep one variable

Cross-correlation (V²)Hover, touch, or use the arrow keys on the chart
012345 −4−2024 Lag (samples) now 5

Variables and how each one contributes

rxy

Cross-correlation

Result · V²

What the equation gives you. Everything else feeds it.

ℓ

Lag

samples · typical −5 to 5

The lag, in samples. Slides y relative to x; the value peaks where they align best. Raising it by 10 % (to 1.1) moves the result by +0 %, from 5 to 5 V².

x0

Sample of x 0

V · typical −10 to 10

The sample x[0], in V. Is multiplied by y[0 − ℓ] if that index exists. Raising it by 10 % (to 0) moves the result by +0 %, from 5 to 5 V².

x1

Sample of x 1

V · typical −10 to 10

The sample x[1], in V. Is multiplied by y[1 − ℓ] if that index exists. Raising it by 10 % (to 1.1) moves the result by +2 %, from 5 to 5.1 V².

x2

Sample of x 2

V · typical −10 to 10

The sample x[2], in V. Is multiplied by y[2 − ℓ] if that index exists. Raising it by 10 % (to 2.2) moves the result by +8 %, from 5 to 5.4 V².

x3

Sample of x 3

V · typical −10 to 10

The sample x[3], in V. Is multiplied by y[3 − ℓ] if that index exists. Raising it by 10 % (to 0) moves the result by +0 %, from 5 to 5 V².

x4

Sample of x 4

V · typical −10 to 10

The sample x[4], in V. Is multiplied by y[4 − ℓ] if that index exists. Raising it by 10 % (to 0) moves the result by +0 %, from 5 to 5 V².

x5

Sample of x 5

V · typical −10 to 10

The sample x[5], in V. Is multiplied by y[5 − ℓ] if that index exists. Raising it by 10 % (to 0) moves the result by +0 %, from 5 to 5 V².

y0

Sample of y 0

V · typical −10 to 10

The sample y[0], in V. Is multiplied by x[0 + ℓ] if that index exists. Raising it by 10 % (to 1.1) moves the result by +2 %, from 5 to 5.1 V².

y1

Sample of y 1

V · typical −10 to 10

The sample y[1], in V. Is multiplied by x[1 + ℓ] if that index exists. Raising it by 10 % (to 2.2) moves the result by +8 %, from 5 to 5.4 V².

y2

Sample of y 2

V · typical −10 to 10

The sample y[2], in V. Is multiplied by x[2 + ℓ] if that index exists. Raising it by 10 % (to 0) moves the result by +0 %, from 5 to 5 V².

y3

Sample of y 3

V · typical −10 to 10

The sample y[3], in V. Is multiplied by x[3 + ℓ] if that index exists. Raising it by 10 % (to 0) moves the result by +0 %, from 5 to 5 V².

y4

Sample of y 4

V · typical −10 to 10

The sample y[4], in V. Is multiplied by x[4 + ℓ] if that index exists. Raising it by 10 % (to 0) moves the result by +0 %, from 5 to 5 V².

y5

Sample of y 5

V · typical −10 to 10

The sample y[5], in V. Is multiplied by x[5 + ℓ] if that index exists. Raising it by 10 % (to 0) moves the result by +0 %, from 5 to 5 V².

Worked example with the values above

  1. Pairs (n, n − ℓ) with ℓ = 1, both inside the stored samples.
  2. Nonzero terms: x[1]·y[0] = 1 × 1; x[2]·y[1] = 2 × 2.
  3. r[1] = 5 V².

Assumptions and limits

  • Finite real sequences indexed from zero and taken as zero outside their stored length.
  • Equally spaced samples, and for the circular forms, periodic extension of both sequences.

Common mistakes

  • Mixing up the linear and circular forms when an FFT is used.
  • Reversing the lag convention for correlation.
  • Dividing by N − ℓ where the biased form divides by N.

Statistics and uncertainty

Convolution and correlation sums are exact, so errors come from the data; a delay found from a correlation peak is limited to the sampling interval unless interpolated, and finite records bias the autocovariance by a factor of (N − ℓ)/N.

Where it is used

  • Computing filter outputs, delays and covariance by hand for checks.
  • Choosing block sizes for fast FFT-based filtering.

Maths you need

  • Linear convolution: y[n] = Σ h[j] x[n − j]
  • Circular convolution: the same sum with indices wrapped modulo N
  • Correlation: a sliding product that measures similarity at each lag

Related formulas

Practise this formula