Autocorrelation Function Simulator — Period Detection
Use the biased autocorrelation R_xx[k] to detect the period of a sinusoid buried in noise. Adjust amplitude, frequency, noise and sample count to learn how period estimation works.
Parameters
Signal amplitude A
—
Signal frequency f_0
cyc/smp
Noise std. deviation σ
—
Sample count N
sample
The signal is generated by a deterministic pseudo-random generator with a fixed seed, so the same parameters always produce the same waveform.
Results
—
Estimated period T_est (peak position)
—
rho(T) normalized correlation at period lag
—
SNR = (A/sigma)^2
—
R(0) signal power
Signal and Autocorrelation
Top: signal x[n] (blue) / Bottom: normalized autocorrelation rho[k] (red), vertical line = peak position k
Theory & Key Formulas
The biased autocorrelation is defined by always dividing the inner product of the signal with its time-shifted copy by N:
Normalized autocorrelation rho[k] (range -1 to +1, with rho[0] = 1):
$$\rho[k] = \frac{R_{xx}[k]}{R_{xx}[0]}$$
The signal x[n] is a sinusoid of period T = 1/f_0 plus Gaussian noise:
$$x[n] = A\sin(2\pi f_0 n) + \sigma\,\eta[n]$$
A periodic signal leaves large autocorrelation values at k = T, so the position of the largest peak for k > 0 is the estimated period T_est. The signal-to-noise ratio is defined as (A/sigma)^2.
What is the Autocorrelation Function Simulator
🙋
My sensor data is so noisy I cannot even tell by eye whether a period is there. How do I actually find the period?
🎓
For exactly this you use the autocorrelation function. Roughly speaking, it measures "how similar" a signal is to itself when shifted along the time axis. The formula is $R_{xx}[k]=\frac{1}{N}\sum x[n]\,x[n+k]$. Look at the simulator with its default settings — the red curve in the bottom pane has a clear bump at k = 20. That bump is the signature of the period T = 20 samples.
🙋
But there is noise mixed in too. Why does only the period come out so cleanly?
🎓
Because noise is temporally uncorrelated, its positive and negative contributions cancel out for k > 0 and the value collapses near zero. The periodic part, on the other hand, returns to the same phase every T samples, so clean peaks survive at k = T, 2T, 3T and so on. Try setting "noise sigma" to 0 in the simulator — the autocorrelation of a pure sine is an undamped oscillating curve. Then crank sigma up, and only the value at k = 0 grows large: that is the noise concentrating itself at k = 0.
🙋
What changes when I increase "sample count N"?
🎓
A larger N averages out more noise, so the peak stays stable even at low SNR. Try N = 128 versus N = 1024 with sigma around 2, and you will see the period peak is much sharper for the longer record. In practice this is exactly the empirical rule "take a longer measurement and you can detect weaker periods".
🙋
The "SNR" card is shown in dB. What does that mean?
🎓
SNR is the ratio of signal power to noise power; here it is defined as $\text{SNR}=(A/\sigma)^2$. In decibels it is $10\log_{10}(\text{SNR})$, which for the default A = 1, sigma = 0.5 gives 6.02 dB. As SNR drops, the height of the period peak rho(T) drops too — comparing them gives you a feel for "how low you can still detect a period". A rough rule of thumb is that detection becomes hard once rho(T) falls below about 0.1.
Frequently Asked Questions
At k = 0 you take the inner product of the signal with an exact copy of itself, so R[0] = (1/N) * sum(x[n]^2) is always at least as large as any R[k]. This value corresponds to the mean power of the signal (close to the variance) and is the reference that makes rho[0] = 1 after normalization. Noise also correlates perfectly with itself at k = 0, so a noisier signal gives a larger R[0].
Yes. Shifting a sine wave by half a period (k = T/2) flips the sign, so rho[T/2] is about -rho[0]. With the default settings you should see a large negative dip around k = 10 (half of T = 20). This sign alternation is a typical feature of periodic signals; square and triangle waves show similar alternating positive and negative peaks.
Because the denominator is always N, while only N - k terms actually contribute to the inner product. At k = N/2 only half the samples are used, but you still divide by N, so the value is compressed by about a factor of two. The unbiased estimator (divide by N - k) fixes this on average, but its variance explodes as k approaches N. For period detection the stable biased shape is usually preferred.
This tool computes the autocorrelation directly from the definition in O(N^2). In practice, the Wiener-Khinchin theorem lets you compute it via the inverse FFT of the power spectral density in O(N log N), which is the production standard. The results agree, but care is needed for zero padding and window functions. For learning the definition, the direct method is clearer, so it is what we use here.
Real-World Applications
Pitch detection and speech analysis: Estimating the fundamental frequency (pitch) of human voice or musical instruments is one of the most basic uses of autocorrelation. You compute the autocorrelation of a recorded sound, find the largest peak, and take the reciprocal of that lag as the pitch frequency. The technique is everywhere in signal processing: telephony quality enhancement, karaoke scoring, speech synthesis formant extraction, and so on.
Vibration analysis and machinery diagnostics: Vibration sensor signals from rotating machines contain shaft rotation periods and gear-mesh periods. Extracting periodic components with autocorrelation reveals characteristic frequencies of specific failure modes (inner-race spalling, outer-race spalling, raceway defects). Combined with spectral analysis, it is a key tool for condition-based maintenance and predictive maintenance.
Correlation detection in radar and sonar: Distance to a target is measured by cross-correlating (the same calculation as autocorrelation) the transmitted pulse with the received signal. Even when the reflected echo is buried in noise, correlation processing provides a processing gain of roughly sqrt(N), dramatically improving detection sensitivity. GPS C/A-code correlation, UWB radar and medical ultrasound echo all build on this idea.
Financial time series and weather data: Autocorrelation is used to detect periodicity in stock returns and temperature data (intraday patterns, seasonality, business cycles). It is also a fundamental tool — together with the partial autocorrelation function (PACF) — for choosing the order of AR models and identifying ARIMA models.
Common Misconceptions and Cautions
The most common misconception is to think that "if you see a peak in the autocorrelation, a periodic signal must be present". In fact, when N is small, pure noise alone can produce spurious peaks that look meaningful. Try A = 0, sigma = 1, N = 128 in the simulator — even with no real period, some peak will sit somewhere at k > 0. In practice you should check whether the same lag shows a peak across multiple trials, or apply a statistical test (such as the +/- 2/sqrt(N) confidence interval) to confirm significance.
The next most common error is the assumption that "raising A makes the period easier to find". Yes, the SNR (A/sigma)^2 goes up, but because autocorrelation is normalized as rho[k], amplitude cancels between numerator and denominator, and the relative peak height does not change. What matters is the ratio of A to sigma, not A alone. Compare A = 2, sigma = 1 with A = 4, sigma = 2 in the simulator — both give 6 dB of SNR, and the peak shapes are essentially identical.
Finally, be careful not to assume that "the largest peak position equals the true period". At very low SNR the largest peak can land on a noise-driven spurious lag. Also, strong harmonics in the periodic signal can produce extra peaks at T/2 or T/3 as well as at T. The standard practice is to combine the absolute peak height, the gap to the next-largest peak, and an expected range for the period to make the final judgment.