ENع
→Autocorrelation
الدرس 50 · Multirate and random signals

Autocorrelation

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

15 دقيقة11 خطوة5 أسئلةAdvanced
عن هذا الدرس

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.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 50 · تفاعلي
01 / 11

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
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. 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
  2. Compare 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 instead
  3. Lag 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 line
  4. Lag 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 = 0
  5. All 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.02
  6. Smooth 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 average
  7. Lag 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.76
  8. All 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 0
  9. Two 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 = 0
  10. Autocorrelation 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)
  11. 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

اختبار يتاح بعد الخطوة الأخيرة.