Cross-correlation is a fundamental operation in signal processing that measures how closely two sequences resemble each other as one is shifted in time relative to the other. For two discrete-time sequences and , the cross-correlation at lag is defined by . In practice we evaluate a finite version of this sum using the available samples. By sliding one sequence past the other and summing the elementwise products, we can determine where the sequences align most strongly.
Engineers and scientists apply cross-correlation when comparing signals in a wide range of contexts. In communications, it helps synchronize receivers by locating known patterns within noisy transmissions. Seismologists use cross-correlation to match waveforms recorded at different locations, allowing them to pinpoint earthquake epicenters. In image processing, correlating templates with a larger picture reveals where specific features occur. Even financial analysts examine cross-correlations between markets to identify leading indicators. Because it highlights similarity regardless of absolute magnitude, the technique is invaluable for detecting patterns buried in complex data.
The cross-correlation operation is closely related to convolution, with one crucial difference: in convolution we reverse one sequence before shifting and summing, whereas in correlation we slide the second sequence in its original order. This distinction matters when analyzing systems that depend on the direction of time. Convolution models how an input drives a system, while correlation measures the similarity between two signals as they currently stand. Understanding how these operations differ clarifies why one might be preferred over the other in a given application.
The raw cross-correlation values depend on the scale of the sequences. If one sequence contains large numbers, the correlation will likewise be large even if the underlying shapes barely match. To compensate, we often normalize by the sequence lengths or variances, yielding a correlation coefficient between -1 and 1. A value near 1 indicates strong similarity at that lag, while a value near -1 suggests one sequence is the negative of the other. Values near zero mean the sequences are largely unrelated for that shift. This calculator computes the unnormalized correlation so you can see the raw sums directly.
Computing the cross-correlation numerically is straightforward. Suppose and have length . The correlation for lag can be approximated by , where samples outside the sequence are taken as zero. Implementing this sum for each integer from to produces a correlation sequence twice as long as the originals minus one.
Consider and . The correlation at lag zero sums matching indices to yield . At lag one we shift right so only and overlap with , giving . Negative lags shift left. Working through all lags reveals where the sequences best align.
The script in this calculator parses each sequence into an array of numbers. It then forms an output array with length equal to the sum of the input lengths minus one. For every possible shift, it multiplies overlapping samples and accumulates the total. The algorithm mirrors the mathematical formula and runs quickly even for moderately long sequences. Because the computation occurs in your browser, you can experiment with different lists instantly without sending any data to a server.
Using cross-correlation effectively requires attention to detail. If your sequences contain trends or offsets, these can dominate the correlation and obscure subtle features. Often it helps to subtract the mean from each sequence first, a process called demeaning. Additionally, when signals are periodic, the correlation will also exhibit periodic structure. Analyzing these patterns offers clues about hidden frequencies or repeating events. This calculator encourages you to explore such effects and build intuition for how cross-correlation responds to various inputs.
Cross-correlation lays the foundation for more advanced signal analysis methods. The fast Fourier transform can accelerate correlation computations through the convolution theorem, making it feasible to correlate extremely long sequences. In statistics, the correlogram—correlation as a function of lag—helps identify dependencies in time series data, guiding the choice of models. By experimenting with this simple tool, you gain a stepping stone toward these sophisticated techniques that underpin modern science and engineering.
Convert between Cartesian and spherical coordinates for points in three dimensions.
Expand rational functions into a Laurent series around a point.
Compute the dot product and angle between two 3D vectors.