%% Prediction Errors for Multiple Realizations
% Generate the coefficients of an autoregressive process given by
%  x(n) = 0.1\,x(n-1)-0.8\,x(n-2)-0.27\,x(n-3) + w(n).

a = [1 0.1 -0.8 -0.27];

%
% Generate five realizations of the process by filtering white noise with different variances.

nr = 5;
v = rand(1,nr)
w = sqrt(v).*randn(15000,nr);
x = filter(1,a,w);

% Estimate the correlation function. Discard cross-correlation terms and correlation values at negative lags. Use the Levinson-Durbin recursion to estimate the prediction errors for the correct model order and verify that the prediction errors correspond to the variances of the input noise signals.

[r,lg] = xcorr(x,'biased');

[~,e] = levinson(r(lg>=0,1:nr+1:end),numel(a)-1)

% Copyright 2019 The MathWorks, Inc.