This example shows how to filtering a white noise process introduces autocorrelation. The example also shows how the sample autocorrelation sequence does not agree perfectly with the known theoretical autocorrelation sequence. However, the sample autocorrelation sequence accurately represents the general form of the theoretical autocorrelation.
Create the impulse response for a 3-point moving average (MA) filter. Filter an N(0,1) white noise with the filter. Set the random number generator to the default settings for reproducible results.
h = 1/3*ones(3,1); rng default; x = randn(100,1); y = filter(h,1,x);
Obtain the biased sample autocorrelation out to 20 lags. Plot the sample autocorrelation along with the theoretical autocorrelation.
[xc,lags] = xcorr(y,20,'biased'); stem(lags,xc,'markerfacecolor',[0 0 1]); Xc = zeros(size(xc)); Xc([19 23]) = 1/9*var(x); Xc([20 22]) = 2/9*var(x); Xc(21) = 3/9*var(x); hold on; stem(lags,Xc,'color',[1 0 0],'marker','none','linewidth',2); legend('Sample Autocorrelation','Theoretical Autocorrelation',... 'Location','NorthEast');
The theoretical autocorrelation is zero outside of lags [-2,2], while the sample autocorrelation is not. However, the magnitudes (absolute values) of the sample autocorrelation decay quickly to zero outside of lags [-2,2].
The sample autocorrelation sequence is not in perfect agreement with the theoretical autocorrelation, but captures that the filter has introduced significant autocorrelation only over lags [-2,2].