Autocorrelation
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
You cannot predict the next sample of noise, but you can measure how much a sample has in common with its neighbours. Autocorrelation does that: pair each sample x[n] with the one l places later, multiply, and average, R[l] = E{x[n]·x[n+l]}. A correlator on the table runs it on 2000 samples of white noise (one spike at lag 0) and of 4-tap smoothed noise (a triangle 1, 0.75, 0.5, 0.25, 0), and a scatter of pairs shows the cloud tilt when neighbours are alike. You will see why R is even and largest at 0, compute it with np.correlate, and meet the link to the power spectral density. It builds on the lessons on random signals and noise, correlation, and the moving average, and on the Maths lessons on probability, random variables and distributions.
Noise you cannot predict
A noise source makes a new random number every sample: w[n]. Each one is drawn on its own, with mean 0 and variance 1. Knowing w[5] tells you nothing about w[6]. We cannot predict noise, but we can describe it.
w[n]: Gaussian, mean 0, variance σ² = 1
a fresh, independent draw each sample
w[0] = −0.50 w[1] = −0.60 ...
the delay line holds x[n] .. x[n+6]
and shifts one place every sample
random signals and noise: see the previous lessonاقرأ الدرس خطوة بخطوة
Noise you cannot predict
A noise source makes a new random number every sample: w[n]. Each one is drawn on its own, with mean 0 and variance 1. Knowing w[5] tells you nothing about w[6]. We cannot predict noise, but we can describe it.
w[n]: Gaussian, mean 0, variance σ² = 1 a fresh, independent draw each sample w[0] = −0.50 w[1] = −0.60 ... the delay line holds x[n] .. x[n+6] and shifts one place every sample random signals and noise: see the previous lessonCompare the signal with itself, shifted
Pick a lag l: a whole number of samples. Pair each sample x[n] with the one l places later, x[n+l]. Two taps on the delay line read each pair. Autocorrelation asks: are such pairs alike, on average?
lag l = 1: pairs (x[0], x[1]), (x[1], x[2]) ... autocorrelation of a stationary signal: R[l] = E{ x[n]·x[n+l] } E{ } = average over all possible draws stationary: the statistics do not change with n, so R depends on the lag l only. one long record: average over n insteadLag 0: the average power
At lag 0 each sample meets itself. Multiply, x[n]·x[n] = x[n]², and average over N = 2000 samples: R[0] = 1.00. That is the mean power of the noise, which equals its variance because the mean is 0.
R̂[0] = (1/N) · Σ x[n]² = 1.00 (theory: σ² = 1) R[0] = mean power = E{x²} = variance + mean² = 1 + 0 scatter: every pair (x[n], x[n]) sits on the diagonal lineLag 1: white noise forgets
At lag 1 the neighbours are independent. Their product is as often negative as positive, so the average heads to zero: R[1] = 0.00. The scatter of pairs is a round cloud: x[n] says nothing about x[n+1].
R̂[1] = (1/(N−1)) · Σ x[n]·x[n+1] = 0.00 (theory: 0) independent, mean 0: E{x[n]·x[n+1]} = E{x[n]}·E{x[n+1]} = 0 · 0 = 0All lags: one spike
Repeat for every lag. White noise gives one spike at 0 and about zero elsewhere: R[l] = σ²·δ[l], where δ[l] is 1 at l = 0, else 0. The small wiggles, at most 0.01, come from averaging only 2000 samples.
l R̂[l] theory 0 1.00 1 1 0.00 0 2 0.00 0 3 0.00 0 4 0.01 0 5 0.01 0 6 0.01 0 δ[l] = 1 at l = 0, else 0 white-noise estimates scatter by about 1/√N ≈ 0.02Smooth the noise
Switch on a smoothing filter: y[n] = (w[n] + w[n−1] + w[n−2] + w[n−3]) / 2. Each output adds four independent inputs, so its variance is 4 × ¼ = 1 again. Same power, but the wave now wanders smoothly.
y[n] = ½·(w[n] + w[n−1] + w[n−2] + w[n−3]) var y = 4 · (½)² · 1 = 1 a 4-tap moving average (an FIR filter), see the lesson on the moving averageLag 1: neighbours share inputs
y[n] and y[n+1] share three of their four inputs, so they tend to agree. Most products are positive. Theory says R[1] = ¾ = 0.75; the averager measures 0.76. The scatter cloud tilts along the diagonal.
y[n] = ½(w[n] + w[n−1] + w[n−2] + w[n−3]) y[n+1] = ½(w[n+1] + w[n] + w[n−1] + w[n−2]) shared: w[n], w[n−1], w[n−2] R[1] = ¼ · 3 · σ² = 0.75 R̂[1] = 0.76All lags: a triangle
Sweep the lags. Shared inputs drop 4, 3, 2, 1, 0, so R[l] = (4 − l)/4 falls 1, 0.75, 0.5, 0.25, then 0. After four samples the filter has forgotten. How wide R is tells how long a signal remembers.
l shared theory R̂[l] 0 4 1.00 1.01 1 3 0.75 0.76 2 2 0.50 0.51 3 1 0.25 0.27 4 0 0.00 0.02 5 0 0.00 0.03 6 0 0.00 0.03 R[l] = (4 − |l|)/4 for |l| < 4, else 0Two rules: even, and largest at 0
R[−l] = R[l]: pairing x[n] with x[n−l] uses the same pairs, read the other way. And |R[l]| ≤ R[0]: nothing matches a signal better than itself. So the plot is mirror-symmetric with its peak at 0.
even: R[−l] = E{x[n]·x[n−l]} = E{x[m+l]·x[m]} = R[l] (m = n − l) bounded: |R[l]| ≤ R[0] (Cauchy–Schwarz) both curves: the peak is at l = 0Autocorrelation in Python
np.correlate(x, x, "full") forms every lagged sum at once. Slicing from index N−1 keeps lags 0, 1, 2 ..., and dividing by N averages. For white noise numpy prints about 1, then values near 0. (Python 3, numpy.)
import numpy as np N = 2000 rng = np.random.default_rng(1) x = rng.standard_normal(N) r = np.correlate(x, x, "full") R = r[N-1:] / N >>> R[:4].round(2) [ 1.01 0. -0.01 0.02] smoothed: y = np.convolve(x, np.ones(4)/2)[:N] Ry = np.correlate(y, y, "full")[N-1:] / N >>> Ry[:6].round(2) [ 1.01 0.76 0.5 0.25 -0. -0.02] (numpy's own random draw: close to, not equal to, the figure's numbers)Next: the spectrum of white noise
A narrow R means a wide spectrum. The power spectral density is the Fourier transform of R (Wiener–Khinchin), so white noise's single spike gives equal power at every frequency. The next lesson builds on this.
S(ω) = Σ_l R[l]·e^(−jωl) white: R[l] = σ²·δ[l] -> S(ω) = σ² flat: every frequency equal smoothed: triangle R -> S(ω) falls at high frequency used next: power spectral density, then the matched filter's SNR
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01Zero-mean noise has variance 4. What is its autocorrelation at lag 0?
R[0] = E{x²} = variance + mean² = 4 + 0 = 4. Lag 0 is the mean power.
02For white noise with variance σ², what is R[3]?
White noise samples are uncorrelated, so E{x[n]·x[n+3]} = 0 for any lag other than 0: R[l] = σ²·δ[l].
03y[n] = (w[n] + w[n−1] + w[n−2] + w[n−3]) / 2 with white w of variance 1. What is R_y[2]?
y[n] and y[n+2] share two of the four inputs, each weighted ½·½ = ¼, so R[2] = 2 × ¼ = 0.5.
04A real signal has R[3] = 0.4. What is R[−3]?
The autocorrelation of a real stationary signal is even: R[−l] = R[l]. The pairs are the same, read the other way.
05Which value can NOT be the autocorrelation at lag 5 of a signal whose R[0] = 2?
|R[l]| ≤ R[0] for every lag: nothing matches a signal better than itself. 2.5 is larger than R[0] = 2.
المسرد
- Lag (l)
- The shift, in whole samples, between the two copies of a signal being compared.
- Autocorrelation R[l]
- The average of x[n]·x[n+l]: how alike a signal is to itself l samples later. R[l] = E{x[n]·x[n+l]} for a stationary signal.
- Stationary (wide-sense)
- A random signal whose mean and autocorrelation do not change with time n, so R depends on the lag only.
- Ergodic
- A random signal whose time averages over one long record equal the averages over many draws; it lets one recording estimate R.
- White noise
- Zero-mean noise whose samples are uncorrelated: R[l] = σ²·δ[l], a single spike at lag 0, and a flat power spectrum.
- Mean power
- R[0] = E{x²}, the average of the squared signal; for zero-mean noise it equals the variance σ².
- Estimator
- A formula that guesses a true value from data, here the average of the N − l lagged products; it scatters by about 1/√N around the truth for white noise, more when samples are correlated.
- Power spectral density
- How a random signal's power spreads over frequency; the Fourier transform of R (the Wiener–Khinchin theorem).
الملاحظات والمصادر
- The noise in the figure is one pseudo-random draw of N = 2000 Gaussian samples (seed 9). A different draw moves each estimate by a few hundredths; the theory values do not move.
- The averager divides each lagged sum by the number of products, N − l. numpy's line divides by N instead (a biased estimate); for lags up to 6 the two differ by at most 0.3 %.
- R[l] = E{x[n]·x[n+l]} assumes a (wide-sense) stationary signal. Averaging one long record over n instead of over many draws also assumes the noise is ergodic, which holds for these examples.
- A. V. Oppenheim, R. W. Schafer, J. R. Buck, Discrete-Time Signal Processing (course text listed on MIT OCW 6.341 readings; App. A, random signals)
- MIT OpenCourseWare 6.011 Introduction to Communication, Control, and Signal Processing (A. V. Oppenheim, G. Verghese): stochastic processes, correlation functions, power spectra
- MIT OpenCourseWare 6.450 Principles of Digital Communications I (R. Gallager, L. Zheng), lecture notes ch. 7: Random processes and noise
- Autocorrelation (Wikipedia): R(−τ) = R(τ) for real stationary processes, |R(τ)| ≤ R(0), estimators
- White noise (Wikipedia): discrete-time white noise, R_W(n) = σ²δ(n)
- Wiener–Khinchin theorem (Wikipedia): power spectral density = Fourier transform of the autocorrelation
- NumPy documentation: numpy.correlate (c_k = Σ a[n+k]·v[n], mode "full")
- NumPy documentation: numpy.random.Generator.standard_normal (mean 0, standard deviation 1)
اختبار يتاح بعد الخطوة الأخيرة.