Autocorrelation Function Calculator
Find the autocorrelation of a sinusoidal signal at any time lag, and see where it repeats its own pattern.
🌀 What is the Autocorrelation Function?
The autocorrelation function measures how well a signal matches a time-shifted (lagged) copy of itself, as a function of the lag amount. It always peaks at zero lag, where a signal is compared to an identical, unshifted copy, and for a truly periodic signal it peaks again at every multiple of the signal's fundamental period, making it one of the most direct ways to measure periodicity in a signal.
Speech and music software use autocorrelation as the core of classic pitch-detection algorithms, since the lag of the first strong peak away from zero directly reveals the fundamental period of a voice or instrument. Radar and sonar engineers use the closely related concept for pulse-compression matched filtering, comparing a received echo to the original transmitted waveform. Statisticians and econometricians use autocorrelation to detect repeating patterns and seasonality in time-series data, from stock prices to weather records.
A common misconception is that autocorrelation only makes sense for noisy or random signals. It applies just as directly, and in fact has a simple closed-form answer, for a pure deterministic sinusoid: the autocorrelation of a sine wave is itself a cosine wave at the same frequency, with the original phase completely canceled out.
This calculator computes that exact closed-form autocorrelation for a sinusoid at any lag you choose, reports the fundamental period where it next peaks, and plots the full periodic curve so you can see the pattern pitch-detection algorithms are built to find.
📐 Formula
📖 How to Use This Calculator
Steps
💡 Example Calculations
Example 1 — Zero Lag (Peak Value)
A = 2, f0 = 50 Hz, fs = 8,000 Hz, τ = 0 samples
Example 2 — Half-Period Lag (Minimum Value)
A = 1, f0 = 1,000 Hz, fs = 48,000 Hz, τ = 24 samples (half of a 48-sample period)
Example 3 — Quarter-Period Lag (Zero Crossing)
A = 3, f0 = 1,000 Hz, fs = 48,000 Hz, τ = 12 samples (quarter of a 48-sample period)
❓ Frequently Asked Questions
🔗 Related Calculators
What is the autocorrelation function?
The autocorrelation function measures how similar a signal is to a time-shifted (lagged) copy of itself, as a function of that lag (tau). It always peaks at tau = 0, where the signal is compared to an unshifted copy of itself, the strongest possible match.
What is the autocorrelation of a sine wave?
For a sinusoid x(t) = A sin(2*pi*f0*t + phi), the time-average autocorrelation is Rxx(tau) = (A^2/2) cos(2*pi*f0*tau), a cosine at the same frequency as the original signal, with the phase phi cancelling out entirely and the amplitude fixed at A^2/2 at zero lag.
Why does the phase of the original sinusoid not appear in the autocorrelation?
Autocorrelation compares a signal against a delayed version of itself, and any constant phase offset present in the original signal is present equally in both copies, so it cancels out in the comparison. This is why Rxx(tau) depends only on frequency and amplitude, never on the sinusoid's starting phase.
How is autocorrelation used for pitch detection?
A pitch-detection algorithm computes a signal's autocorrelation and searches for the first strong peak away from tau = 0. The lag of that peak is the signal's fundamental period, and its reciprocal (scaled by sampling rate) gives the fundamental frequency, the pitch, directly.
What is the difference between autocorrelation and cross-correlation?
Autocorrelation compares a signal against a lagged copy of itself. Cross-correlation compares two different signals against each other at varying lags, commonly used to measure time delay between a transmitted and received signal, as in the Cross-Correlation and Time Delay Estimator on this site.
Why does autocorrelation peak again at multiples of the period?
A periodic signal repeats its exact waveform every period, so shifting it by exactly one period (or any whole multiple) lines the waveform back up with an unshifted copy, reproducing the same maximum correlation value seen at tau = 0. This is the defining signature of periodicity in the autocorrelation domain.
What does a normalized autocorrelation value mean?
The normalized autocorrelation, Rxx(tau) divided by Rxx(0), always ranges from -1 to 1 regardless of the signal's amplitude. A value of 1 means perfect positive correlation (the same phase), -1 means perfect negative correlation (exactly opposite phase), and 0 means no linear correlation at that lag.
Does real-world (noisy) autocorrelation look like this ideal cosine curve?
Not exactly. Real signals contain noise, harmonics, and finite duration, which add a decaying envelope on top of the ideal periodic pattern shown here. The peaks still occur near multiples of the true period, but their heights gradually shrink with increasing lag rather than repeating forever at full amplitude.
What lag value gives zero autocorrelation for a sinusoid?
Zero autocorrelation occurs whenever the lag corresponds to a quarter-period phase shift (tau = period/4, 3*period/4, and so on), where the cosine term crosses zero. At those lags, the shifted and unshifted copies of the sinusoid are exactly 90 degrees out of phase and have no linear correlation.
Can autocorrelation be negative?
Yes. Whenever the lag shifts the sinusoid by more than a quarter period but less than three-quarters of a period (within each cycle), the shifted copy is closer to the negative of the original than to a match, producing a negative Rxx(tau) value, down to a minimum of -A^2/2 at exactly half a period.
How does sampling rate affect the autocorrelation lag axis?
The lag axis is measured in samples, so the same physical time delay corresponds to a larger lag value at a higher sampling rate. The underlying autocorrelation shape and the fundamental period in real time (seconds) do not change, only how many samples that period spans.