%% Estimate Model order Using Decay of Reflection Coefficients
% Use a vector of polynomial coefficients to generate an AR(2) process by filtering 1024 samples of white noise. Reset the random number generator for reproducible results.

rng default

y = filter(1,[1 -0.75 0.5],0.2*randn(1024,1));

%
% Use the Yule-Walker method to fit an AR(10) model to the process. Output and plot the reflection coefficients. Only the first two coefficients lie outside the 95% confidence bounds, indicating that an AR(10) model significantly overestimates the time dependence in the data. See AR Order Selection with Partial Autocorrelation Sequence for more details.

[ar,nvar,rc] = aryule(y,10);

stem(rc)
xlim([0 11])
conf95 = sqrt(2)*erfinv(0.95)/sqrt(1024);
[X,Y] = ndgrid(xlim,conf95*[-1 1]);
hold on
plot(X,Y,'--r')
hold off
title('Reflection Coefficients')

% Copyright 2015 The MathWorks, Inc.