β€Ί Autocorrelation Function Simulator Back
Signal Processing Simulator

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 type
Signal amplitude A 1.0
Signal frequency f₀ 0.050 / T=20
Noise std. deviation σ 0.5
Sample count N 512

The signal is generated by a fixed-seed pseudo-random generator, so identical parameters always give the same waveform. The animation sweeps lag k from 0 and builds the autocorrelation ρ[k] one lag at a time from the overlap of the shifted copy and the original.

Live readouts
0
Current lag k
1.000
R(k) normalized autocorrelation
-
Detected period T (peak position)
1.000
R(0) (reference, always 1)
Signal · lagged copy · autocorrelation build-up
Original x[n] Lagged copy x[n+k] Autocorrelation ρ[k] Detected period

Top: original signal (blue) and a copy shifted by lag k (orange) / Bottom: normalized autocorrelation ρ[k] (red) built one lag at a time, vertical line = detected period

Running self-check...

Theory & Key Formulas

The biased autocorrelation is defined by always dividing the inner product of the signal with its time-shifted copy by N:

$$R_{xx}[k] = \frac{1}{N}\sum_{n=0}^{N-k-1} x[n]\,x[n+k]$$

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.

How to Use

  1. Set signal amplitude A (0–5 V) using slider slA; typical industrial sensor signals use A = 2–3 V
  2. Adjust fundamental frequency F0 (0.1–5 Hz) to define the underlying periodic waveness; for rotating machinery, use F0 = shaft speed in Hz
  3. Add Gaussian noise via slSigma (0–2 V standard deviation) to simulate real-world measurement noise
  4. Configure sample count N (100–2000 samples) and observe autocorrelation R_xx[k]; SNR = (A/Οƒ)Β² is computed automatically
  5. Locate the dominant peak in the autocorrelation plot beyond lag 0; its position k_peak directly estimates period T_est = k_peak / sample_rate

Worked Example

A bearing vibration signal at A = 1.5 V, F0 = 10 Hz, Οƒ = 0.4 V, N = 800 samples produces SNR β‰ˆ 14 dB. The autocorrelation R(0) = 2.25 VΒ² (signal power). The first significant peak appears at lag k β‰ˆ 80 samples; at 800 Hz sampling rate, T_est = 80/800 = 0.1 s = 10 Hz period, matching F0. Normalized correlation ρ(T) β‰ˆ 0.87 confirms strong periodicity. Increasing Οƒ to 0.8 V reduces SNR to 3.5 dB and ρ(T) drops to 0.62, making period detection less reliable.

Practical Notes

  1. Peak detection requires SNR > 3 dB; below this threshold, noise peaks may mask true periodicityβ€”increase A or reduce Οƒ
  2. For machinery diagnostics, filter the autocorrelation output (moving average window = 5–10 lags) to suppress side lobes when N is small
  3. Multiple peaks indicate harmonic content; the fundamental period corresponds to the first non-zero-lag peak, not necessarily the absolute maximum
  4. Transient signals (e.g., impact events) show autocorrelation decay; use windowing (Hann or Tukey) on input data to improve stationarity assumption