discrete cross correlation calculator
Discrete Cross Correlation Calculator guide
Cross-correlation compares a reference pattern with an observed sequence at different relative shifts. Paste each record in chronological order. A positive lag means the matching feature appears later in the observed record. The headline identifies the earliest lag having the largest signed sum and the table exposes negative values and other candidate alignments.
Play the instrument ↑- Default result
- 6 peak at lag 1
Calculation and units
At lag k, sum x at index j multiplied by y at j plus k, using zero for positions outside the observed record. The possible lag range starts at one minus the reference length and ends at the observed length minus one. Unequal sequence lengths are therefore supported without trimming either input to fit the other.
Worked examples
Select a named case in the Worked example control to load these values. You can then edit any input to compare the result.
Observed record delayed
Reference sequence x = 1 2 -1 · Observed sequence y = 0 1 2 -1.
6 peak at lag 1. Positive lag places the observed features later than the reference. The first largest signed sum is reported, with 1 matching peak(s). Table readings (Lag, Raw cross-correlation): -2, 0; -1, -1; 0, 0; 1, 6; 2, 0; 3, -1.
The observed record begins with an extra zero. Under the displayed sign convention the matching pattern appears at a positive lag.
Swap the records
Reference sequence x = 0 1 2 -1 · Observed sequence y = 1 2 -1.
6 peak at lag -1. Positive lag places the observed features later than the reference. The first largest signed sum is reported, with 1 matching peak(s). Table readings (Lag, Raw cross-correlation): -3, -1; -2, 0; -1, 6; 0, 0; 1, -1; 2, 0.
Interchanging reference and observation mirrors the lag axis. This paired example helps check sign conventions when comparing external software.
Aligned impulse
Reference sequence x = 0 1 0 · Observed sequence y = 0 1 0.
1 peak at lag 0. Positive lag places the observed features later than the reference. The first largest signed sum is reported, with 1 matching peak(s). Table readings (Lag, Raw cross-correlation): -2, 0; -1, 0; 0, 1; 1, 0; 2, 0.
The sharp matching feature sits at the same index in both records. Its largest signed product sum appears at zero lag.
Repeated reference
Reference sequence x = 1 · Observed sequence y = 1 0 1.
1 peak at lag 0. Positive lag places the observed features later than the reference. The first largest signed sum is reported, with 2 matching peak(s). Table readings (Lag, Raw cross-correlation): 0, 1; 1, 0; 2, 1.
Two positions give the same largest sum. The result headline names the earliest winning lag and reports how many times it occurs.
Unequal unipolar records
Reference sequence x = 1 1 · Observed sequence y = 1 1 1.
2 peak at lag 0. Positive lag places the observed features later than the reference. The first largest signed sum is reported, with 2 matching peak(s). Table readings (Lag, Raw cross-correlation): -1, 1; 0, 2; 1, 2; 2, 1.
Full overlap occurs at two offsets. Equal-height peaks can represent ambiguous alignment even when the signal is perfectly clean.
Opposite polarity
Reference sequence x = 1 -1 · Observed sequence y = -1 1.
1 peak at lag -1. Positive lag places the observed features later than the reference. The first largest signed sum is reported, with 2 matching peak(s). Table readings (Lag, Raw cross-correlation): -1, 1; 0, -2; 1, 1.
The central match after inversion has a negative value. Inspect the entire table if you need the strongest absolute match or inverted polarity.
Interpreting the result
A delayed copy is a good way to check interpretation before aligning a real recording. Place a zero at the start of the observation and look for the strongest sum at positive one. Then swap the two lists and inspect the mirrored lag. For delays in seconds, divide the winning lag by the sample rate shared by both records.
Measurement and model limits
The raw result depends on amplitudes, offsets and overlap length. The largest signed sum can miss a strongly inverted match; inspect negative rows if polarity might be reversed. Repeated motifs can create ties. This calculator reports their number and preserves every candidate row, without choosing among repeated features based on an external time reference.
Answers before you play
Common questions
Does this subtract either mean?
Both sequences enter exactly as provided. Center each record before entry if a DC offset should be excluded from alignment.
Does a negative lag mean a negative score?
Lag describes a relative time shift while score describes a product sum. Either score sign can occur on either side of zero lag.
Can I use signals recorded at different rates?
Resample onto a common time grid before treating a lag as a delay. A changing clock ratio can smear or move correlation peaks across a longer recording.
Why does another library give the opposite lag?
Libraries differ in which list they shift and in argument order. Compare the formula and try the observed-delay example before interpreting signs.