How to use this calculator
Locate the strongest signed cross-correlation peak and convert its lag to a time offset.
- Enter Reference real sequence, Compared real sequence, Sample rate (Hz). Match the units shown beside each field and review the result together with the assumptions below.
- Read the worked example below to check the expected input format and result.
- Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Cross correlation lag and alignment explained
Cross-correlation tests relative sample shifts by summing products over the overlapping sequence region. The chosen convention treats a positive lag as the compared pattern occurring later. This page selects the largest signed raw correlation, which can differ from the strongest absolute anticorrelation.
Inputs, symbols, and units
a— Reference real sequence- Reference real-valued samples in time order; no mean subtraction is applied.
b— Compared real sequence- Compared real-valued samples in time order, sampled at the same rate as the reference.
fs— Sample rate (Hz)- Common positive sample rate in samples per second; lag seconds equals sample lag divided by this rate.
Formula and method
R[k]=Σ reference[n]·compared[n+k] over overlapping indices
For each signed lag, multiply overlapping reference and shifted compared samples and sum the products. Positive lag moves the compared sample index forward. The largest signed correlation is selected; this differs from choosing the largest absolute anticorrelation.
A worked scenario
Reference real sequence = 0, 1, 0, 0; Compared real sequence = 0, 0, 1, 0; Sample rate (Hz) = 1000.
- Peak correlation lag: 1 samples
- Time lag: 0.001 s
- Peak raw correlation: 1
The single nonzero compared sample appears one index after the reference impulse. Peak lag is therefore +1 sample, or 0.001 seconds at 1,000 samples per second.
Assumptions and edge cases
Raw correlation without mean subtraction or normalization. Positive lag means the compared pattern occurs later; equal maxima use the smallest lag.
Frequently asked questions
Can different sequence lengths be entered?
Yes.
Does positive lag mean the second signal is delayed?
Under the stated R[k] convention, yes.
Does a peak prove a causal delay?
No, offsets, periodicity, and background trends can affect it.
How do I use the Cross correlation lag and alignment calculator?
Enter Reference real sequence, Compared real sequence, Sample rate (Hz). Match the units shown beside each field and review the result together with the assumptions below.
What is a worked example of Cross correlation lag and alignment?
Reference real sequence = 0, 1, 0, 0; Compared real sequence = 0, 0, 1, 0; Sample rate (Hz) = 1000. Peak correlation lag: 1 samples Time lag: 0.001 s Peak raw correlation: 1 The single nonzero compared sample appears one index after the reference impulse. Peak lag is therefore +1 sample, or 0.001 seconds at 1,000 samples per second.
Read our calculation methodology.