Autocorrelation of white noise should have a strong peak at "0" and absolutely zero for all other $\tau$ according to this. Then why is output of this code a cone shape (with the expected of strong peak at "0" instead of being flat elsewhere except at "0")

y = ones(1,1000);
z = awgn(y,1);
[m l] = xcorr(z);
  • $\begingroup$ Please indicate the programming language or data analysis tool for which your code sample is written. $\endgroup$
    – DanielSank
    Jul 9 '14 at 16:38

Problem 1:

As pointed by learner, awgn adds noise to the sequence y. So you are not plotting the autocorrelation of white gaussian noise, but the autocorrelation of white gaussian noise plus a constant.

Use zeros instead of ones ; or analyze the difference $z - y$ ; or since $y$ is a constant signal, remove the mean of $z$.

Problem 2:

Once point 1 is solved, and since your sequence is of finite length, you will be plotting the autocorrelation of white noise multiplied by a square window. What you will see is thus the autocorrelation of white noise convolved by the autocorrelation of a square window. The autocorrelation of a square window has a triangular shape.

Another way to look at it: the further you move from 0, the less data is present in your input vector. For example, in the sequence:

$-1, 4, 5, 6, -2$

There are 4 pairs of samples distant by a lag of 1, 3 pairs of samples distant by a lag of 2 (-1 and 5 ; 4 and 6 ; 5 and -2), and only two pairs of samples distant by a lag of 3 (-1 and 6, 4 and -2). Thus, there won't be as much data to estimate correctly the autocorrelation function for the larger values of the lag.

You can artificially compensate for the windowing by providing the 'unbiased' argument to xcorr.

Problem 3:

Keep in mind that the theory is about infinite length sequences (or for finite length sequences, about the expected value of the result).

  • $\begingroup$ @pinchenettes Should it be added with square window, since awgn takes the first argument as the signal and adds noise to it. $\endgroup$
    – learner
    Jul 8 '14 at 7:31
  • $\begingroup$ Indeed, edited the answer... If one wants to generate only noise, then the first argument to awgn must be zeros. $\endgroup$ Jul 8 '14 at 7:51

The {aperiodic}autocorrelation function of a sequence of real numbers $$x_0,x_1, x_2, \ldots, x_{N-1}$$

can be defined as $$R_x(k) = \begin{cases}\displaystyle\sum_{i=0}^{N-1-k}x_ix_{i+k}, & 0 \leq k \leq N-1,\\ \displaystyle\sum_{i=0}^{N-1+k}x_ix_{i-k}, & 1-N \leq k < 0,\\ 0, & |k|\geq N.\end{cases}$$

It should be obvious that $R_x(k)$ cannot be $0$ for all $k\neq 0$ as the OP desires except un the trivial case when exactly one of the $N$ numbers $x_0,x_1, x_2, \ldots, x_{N-1}$ is nonzero, that is, the sequence is a possibly scaled and/or delayed copy of the unit pulse. About the closest that one can get to the white noise ideal is with Huffman's impulse-equivalent sequences which are complex-valued in general.

On the other hand, a discrete-time white noise is defined as a sequence of independent random variables with finite variance $\sigma^2$. Since the autocorrelation function of a wide-sense-stationary discrete-time random process is defined as $R_X(k) = E[X_iX_{i+k}]$, we have that the white-noise process has an autocorrelation function given by $\sigma^2\delta[k]$ where $\delta[k]$ is the unit pulse (a.k.a. discrete-time impulse) function.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.