Cross-Correlation Calculator
What this cross-correlation calculator measures
Cross-correlation answers a very specific question: how similar are two sequences if you slide one of them left and right and measure the overlap at each shift? That idea shows up in signal processing, image analysis, econometrics, seismology, finance, control systems, and everyday data work. If two sampled signals contain the same pattern but one arrives later, cross-correlation helps reveal the lag. If a reference pattern is hidden inside a noisy measurement, cross-correlation can help you spot where the match is strongest. This calculator focuses on the discrete case, which means you enter finite lists of numbers and the page computes the raw cross-correlation value for every integer lag that produces some overlap.
That detail matters because this tool is not a generic similarity score and it is not the same thing as the Pearson correlation coefficient. A Pearson correlation coefficient is normalized and usually falls between -1 and 1. Raw discrete cross-correlation is different. Its magnitude depends on the actual values in the sequences, the amount of overlap at each lag, and whether matching terms reinforce or cancel one another. In plain language, the calculator adds up many pairwise products. When large values line up with large values of the same sign, the total grows. When positive values line up with negative values, the total can shrink or even become negative.
When to use it and what the output means
Use this page when you already have two ordered sequences sampled on the same grid and you want to compare them across shifts. The sequences might be audio amplitudes sampled every millisecond, hourly demand measurements, daily returns, vibration sensor readings, counts per interval, or any other equally spaced measurements. The output is a list of numbers rather than a single answer because the underlying question changes with lag. One lag might represent no shift, another might represent one sample earlier, and another might represent several samples later. The strongest lag is often the one with the largest cross-correlation value, but you should still inspect the full list and relate the lag order to your domain.
On this page, if Sequence 1 has length m and Sequence 2 has length n, the output contains m + n - 1 values. They are listed in order from lag -(n - 1) through m - 1. That ordering comes directly from the implementation in the page script. Many textbooks and software libraries use equivalent formulas with the opposite sign convention, so do not assume every package labels lags the same way. The safest interpretation is practical rather than symbolic: find the lag where the overlap score peaks, then translate that lag into your own time, distance, or sample units.
- A large positive peak usually means the two sequences share a strong aligned pattern at that lag.
- A smaller or flatter curve suggests weaker alignment, heavier noise, or no clear shift between the sequences.
- Negative values can appear when positive parts of one sequence overlap negative parts of the other, which indicates opposition or inversion rather than reinforcement.
- A peak away from zero often signals that one sequence is delayed or advanced relative to the other.
How to enter the sequences correctly
The two text areas accept numbers separated by commas, spaces, or line breaks. That makes it easy to paste data directly from a spreadsheet column, a code notebook, or a plain-text log. Sequence lengths do not need to be the same. The script automatically ignores nonnumeric fragments after splitting the text, then computes the overlap sum wherever the indices are valid. Values outside the overlap are effectively treated as absent rather than forcing you to pad the sequences manually.
- Enter Sequence 1 as the first ordered list of sampled values.
- Enter Sequence 2 as the second ordered list using the same sampling interval and compatible units.
- Click Compute Correlation to generate the full list of lag values.
- Read the result from left to right, remembering that the first number corresponds to lag -(n - 1) and the final number corresponds to lag m - 1.
The biggest practical requirement is consistency. If one sequence is sampled every second and the other is sampled every minute, the lag positions will not mean the same thing. If one series is in volts and the other is in millivolts, the result will be numerically distorted unless you convert units first. If your data contain missing values, categorical labels, or timestamps mixed into the field, clean them before relying on the output. This calculator expects numeric sequences and does not perform mean-centering, detrending, or normalization for you.
Formula and lag convention
The discrete cross-correlation computed here follows the same indexing pattern used in the page script. For each lag k, the calculator multiplies values from Sequence 1 by shifted values from Sequence 2 and adds the products over the valid overlap. Written in mathematical form, the calculation is:
Here, x represents Sequence 1 and y represents Sequence 2. When the shifted entries of Sequence 2 line up with strong features in Sequence 1, the sum becomes large. Because the code only adds terms for valid indices, partial overlap near the edges produces smaller sums than full overlap unless the matching values are especially strong. That edge behavior is normal for raw cross-correlation and is one reason why interpretation should consider both the peak location and the changing amount of overlap.
It can also help to remember that every calculator is still just a function that maps inputs to outputs. The page includes the general notation below, which is useful if you want to think of the result list as a function of the sequence values rather than as a black box:
And because each lag value is built from a sum of many contributions, the weighted-sum form below is also a useful mental model. In cross-correlation, the weights are effectively created by the lag and overlap pattern rather than by a separate user-entered field:
Those two general formulas do not replace the cross-correlation equation above; they simply remind you that the calculator is assembling a result from many component products. That perspective is helpful when you are debugging an unexpected answer. If the numbers look too large, check units or amplitude scaling. If the peak is shifted farther than expected, check whether one sequence starts later or whether another source uses the opposite lag sign convention.
Worked example
Suppose you enter Sequence 1 as 1, 2, 1 and Sequence 2 as 0, 1, 2. The calculator will produce five outputs because 3 + 3 - 1 = 5. On this page the lags run from -2 to 2. If you work through the overlap manually, the correlation values are:
- Lag -2: 2
- Lag -1: 5
- Lag 0: 4
- Lag 1: 1
- Lag 2: 0
So the result list is 2.0000, 5.0000, 4.0000, 1.0000, 0.0000. The largest value occurs at lag -1, which means the strongest overlap happens there under this page's sign convention. In practical terms, one of the sequences lines up best after a one-sample shift. If you use the built-in example button below, the calculator will load these sequences and compute that same output for you. This is a good sanity check because it shows three important facts at once: the result list length depends on both sequence lengths, the peak does not have to occur at lag 0, and raw values can remain positive even when the overlap is only partial.
How to read the result wisely
After calculation, do not focus only on the single largest value. First, confirm that the output length makes sense for your sequence sizes. Next, identify whether the curve appears to have one dominant peak or several competing peaks. Multiple peaks can happen when the data contain repeating patterns, seasonal cycles, or evenly spaced pulses. In those cases, the largest lag is still mathematically important, but it may not be the only meaningful one. You should also think about scale. Because this calculator returns raw sums, doubling the amplitude of one sequence can roughly double the cross-correlation values even if the shape similarity stays the same. That is why raw cross-correlation is excellent for locating alignment, but not always the best standalone measure for comparing similarity across differently scaled datasets.
| Pattern between the two sequences | Typical cross-correlation behavior | Interpretation |
|---|---|---|
| Same shape and already aligned | Large positive value near lag 0 | The strongest overlap occurs without much shifting. |
| Same shape but delayed | Peak moves away from lag 0 | The peak lag estimates the sample shift between the signals. |
| Opposite sign or inverted pattern | Values can shrink or become negative | Features oppose rather than reinforce each other at that lag. |
A second interpretive question is whether you need preprocessing. In many real applications, users subtract the mean, normalize by energy, or window the data before comparing signals. This page does none of those steps automatically. That is intentional because raw cross-correlation is often the clearest starting point and it matches the code directly. Just remember what the output represents: the sum of pairwise products at each lag, not a fully normalized statistic. If your goal is shape matching independent of amplitude, you may want to preprocess the data elsewhere and then paste the cleaned sequences into this calculator.
Assumptions and limitations
No calculator is completely context-free, and cross-correlation is especially sensitive to data preparation. The most important assumption is that the two sequences are meaningfully comparable sample by sample. If they were recorded on different time grids, if one series contains a trend that dominates the local variation, or if the values use incompatible units, the raw output may be mathematically correct but practically misleading. Another limitation is that edge effects are unavoidable: near the largest positive and negative lags, only a small part of the sequences overlap, so the sums are built from fewer products than in the middle.
- Same spacing required: each step in Sequence 1 should correspond to the same time or distance step as each step in Sequence 2.
- Raw, not normalized: larger amplitudes can create larger totals even when the underlying shape similarity is unchanged.
- Sign convention matters: another software package may report the same peak at the opposite lag sign.
- Missing data are not modeled: the parser ignores invalid tokens but does not impute or specially mark missing observations.
- Finite overlap matters: values near the ends reflect partial overlap and should be interpreted with that in mind.
In short, this tool is excellent for quick lag exploration, spot checks, classroom demonstrations, and practical sequence comparison. It is not a full signal-analysis pipeline. If you need normalized cross-correlation, FFT-based acceleration for very long sequences, statistical confidence intervals, or domain-specific preprocessing, use this calculator as the first inspection step and then move to a more specialized workflow.
Practical tips for getting better answers
Start with a small known example before pasting a long real dataset. That confirms your separators, sign expectations, and lag ordering. If the result is surprising, try swapping the two sequences with the button below and see how the peak moves. That quick experiment is often the fastest way to understand how the lag convention interacts with your data. If your sequences are long and noisy, also try a shorter segment that contains a distinctive feature such as a spike, pulse, or local burst. Distinctive features usually create cleaner peaks than flat or slowly drifting regions.
Finally, remember that a calculator is most useful when it supports a decision. For a sensor problem, the decision might be estimating delay. For a trading or forecasting problem, it might be finding whether one series tends to lead another. For a pattern-matching problem, it might be locating the best alignment before a more detailed fit. Use the copy button to save the current result list, compare scenarios, and document the lag that matters in your own units. If you want a more intuitive feel for why the peak moves, the optional mini-game below lets you play with the same concept in real time by shifting one signal until the overlap surges.
