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
- 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.
- 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
| Variable | Typical range | Lowest result | Highest result | Swing (V²) | Local step | Change in result |
|---|---|---|---|---|---|---|
| x2 Sample of x 2 | −10 to 10 V | −19 | 21 | 40 | +0.4 V | +16 % |
| y1 Sample of y 1 | −10 to 10 V | −19 | 21 | 40 | +0.4 V | +16 % |
| x1 Sample of x 1 | −10 to 10 V | −6 | 14 | 20 | +0.4 V | +8 % |
| y0 Sample of y 0 | −10 to 10 V | −6 | 14 | 20 | +0.4 V | +8 % |
| ℓ Lag | −5 to 5 samples | 0 | 5 | 5 | +1 samples | −60 % |
| x0 Sample of x 0 | −10 to 10 V | 5 | 5 | 0 | +0.4 V | 0 % |
| x3 Sample of x 3 | −10 to 10 V | 5 | 5 | 0 | +0.4 V | 0 % |
| x4 Sample of x 4 | −10 to 10 V | 5 | 5 | 0 | +0.4 V | 0 % |
| x5 Sample of x 5 | −10 to 10 V | 5 | 5 | 0 | +0.4 V | 0 % |
| y2 Sample of y 2 | −10 to 10 V | 5 | 5 | 0 | +0.4 V | 0 % |
| y3 Sample of y 3 | −10 to 10 V | 5 | 5 | 0 | +0.4 V | 0 % |
| y4 Sample of y 4 | −10 to 10 V | 5 | 5 | 0 | +0.4 V | 0 % |
| y5 Sample of y 5 | −10 to 10 V | 5 | 5 | 0 | +0.4 V | 0 % |
Sweep of Lag
| Lag (samples) | Cross-correlation (V²) |
|---|---|
| −5 | 0 |
| −3.75 | 0 |
| −2.5 | 0 |
| −1.25 | 0 |
| 0 | 2 |
| 1.25 | 5 |
| 2.5 | 0 |
| 3.75 | 0 |
| 5 | 0 |
Sweep one variable
Variables and how each one contributes
Cross-correlation
What the equation gives you. Everything else feeds it.
Lag
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².
Sample of x 0
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².
Sample of x 1
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².
Sample of x 2
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².
Sample of x 3
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².
Sample of x 4
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².
Sample of x 5
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².
Sample of y 0
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².
Sample of y 1
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².
Sample of y 2
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².
Sample of y 3
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².
Sample of y 4
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².
Sample of y 5
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
- Pairs (n, n − ℓ) with ℓ = 1, both inside the stored samples.
- Nonzero terms: x[1]·y[0] = 1 × 1; x[2]·y[1] = 2 × 2.
- 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