Estimate the coefficients of an autoregressive process given by
a = [1 0.1 -0.8 -0.27];
Generate a realization of the process by filtering white noise of variance 0.4.
v = 0.4; w = sqrt(v)*randn(15000,1); x = filter(1,a,w);
Estimate the correlation function. Discard the correlation values at negative lags. Use the Levinson-Durbin recursion to estimate the model coefficients. Verify that the prediction error corresponds to the variance of the input.
[r,lg] = xcorr(x,'biased'); r(lg<0) = ; [ar,e] = levinson(r,numel(a)-1)
ar = 1×4 1.0000 0.0772 -0.7954 -0.2493
e = 0.3909
Estimate the reflection coefficients for a 16th-order model. Verify that the only reflection coefficients that lie outside the 95% confidence bounds are the ones that correspond to the correct model order. See AR Order Selection with Partial Autocorrelation Sequence for more details.
[~,~,k] = levinson(r,16); stem(k,'filled') conf = sqrt(2)*erfinv(0.95)/sqrt(15000); hold on [X,Y] = ndgrid(xlim,conf*[-1 1]); plot(X,Y,'--r') hold off
Generate the coefficients of an autoregressive process given by
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)
v = 1×5 0.8147 0.9058 0.1270 0.9134 0.6324
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)
e = 5×1 0.7957 0.9045 0.1255 0.9290 0.6291
r— Autocorrelation sequence
Autocorrelation sequence, specified as a vector or matrix. If
is a matrix, the function finds the coefficients for each column of
r and returns them in the rows of
[r,lg] = xcorr(randn(1000,1),'biased'); r(lg<0) = 
estimates the autocorrelation sequence of a 1000-sample random signal for positive
Complex Number Support: Yes
n— Model order
r) – 1 (default) | positive integer scalar
Model order, specified as a positive integer scalar.
a— Autoregressive linear process coefficients
Autoregressive linear process coefficients, returned as a row vector or matrix. The filter coefficients are ordered in descending powers of z–1:
r is a matrix, then each row of
a corresponds to a column of
e— Prediction error
Prediction error, returned as a scalar or column vector. If
is a matrix, then each element of
e corresponds to a column of
k— Reflection coefficients
The Levinson-Durbin recursion is an algorithm for finding an all-pole IIR filter with a
prescribed deterministic autocorrelation sequence. It has applications in filter design,
coding, and spectral estimation. The filter that
levinson produces is
levinson solves the symmetric Toeplitz system of linear
r = [r(1) ... r(n + 1)
is the input autocorrelation vector, and
r(i)* denotes the complex
conjugate of r(i). The input
typically a vector of autocorrelation coefficients where lag 0 is the first element,
r is not a valid autocorrelation sequence, the
levinson function might return
NaNs even if the
The algorithm requires O(n2) flops and is thus much more efficient than the MATLAB® backslash command for large
n. However, the
levinson function uses
\ for low orders to provide
the fastest possible execution.
 Ljung, Lennart. System Identification: Theory for the User. 2nd Ed. Upper Saddle River, NJ: Prentice Hall, 1999.
Usage notes and limitations:
Code generation for this function requires the DSP System Toolbox™ software.
n, when specified, must be a scalar.