Engee documentation

levinson

Levinson—Durbin recursion.

Library

EngeeDSP

Syntax

Function call

  • a,e,k = levinson(r,n) — returns coefficients of the linear autoregression process of the order n, the autocorrelation sequence of which is r. It also returns a prediction error. e and reflection coefficients k.

Arguments

Input arguments

# r is an autocorrelation sequence

+ vector | the matrix

Details

An autocorrelation sequence defined as a vector or matrix. If r is a matrix, then the function finds the coefficients for each column r and returns them in strings a.

Типы данных

Float32 | Float64

Support for complex numbers

Yes

# n is the order of the model

+ length(r)−1 (by default) | a positive integer scalar

Details

The order of the model, given as a positive integer scalar.

Типы данных

Float32 | Float64

Output arguments

# a — coefficients of the linear autoregression process

+ vector string | the matrix

Details

Coefficients of the linear autoregression process, returned as a row vector or matrix. The filter coefficients are ordered in descending order of degrees :

If r — the matrix, then each row a corresponds to the column r.

# e — prediction error

+ scalar | column vector

Details

The prediction error returned as a scalar or column vector. If r — the matrix, then for each element e corresponds to the column r.

# k — reflection coefficients

+ column vector | the matrix

Details

Reflection coefficients returned as a column vector of length n. If r — the matrix, then for each column k corresponds to the column r.

Argument k calculated inside the matrix during the calculation a coefficients, so the simultaneous return k more efficient than conversion a in k using the function tf2latc.

Examples

Coefficients of the autoregression process

Details

We will generate the coefficients of the autoregressive process given by the expression

import EngeeDSP.Functions: randn,filter,xcorr,levinson

a = [1 0.1 -0.8 -0.27]

Let’s generate an implementation of the process by filtering out white noise with variance. 0.4.

v = 0.4
w = sqrt(v)*randn(15000,1)
x = filter(1,a,w)

Let’s evaluate the correlation function. Let’s discard the correlation values for negative lag intervals. We use Levinson—Durbin recursion to estimate the coefficients of the model. Let’s make sure that the prediction error corresponds to the variance of the input data.

r, lg = xcorr(x,"biased")
r = r[lg[:] .>= 0]
ar,e,k = levinson(r,numel(a)-1)
println("ar: ", ar)
println("e: ", e)
ar: [1.0 0.09735638301626465 -0.7977574280493284 -0.2697747348725144]
e: 0.39925318400516796

Let’s estimate the reflection coefficients for the model 16- th order. Let’s make sure that the only reflection coefficients that lie outside the 95% of confidence bounds correspond to the correct order of the model.

ar,e,k = levinson(r,16)

stem(1:length(k[:]), k[:],
     marker=:circle,
     markercolor=:blue,
     linecolor=:blue)

conf = sqrt(2) * erfinv(0.95) / sqrt(15000)
x_limits = xlims()

X = [x_limits[1], x_limits[2]]
Y1 = [conf, conf]
Y2 = [-conf, -conf]

plot!(X, Y1, linestyle=:dash, color=:red, label="")
plot!(X, Y2, linestyle=:dash, color=:red, label="")

levinson 1

Prediction errors for multiple implementations

Details

We will generate the coefficients of the autoregressive process given by the expression

import EngeeDSP.Functions: randn,filter,xcorr,levinson

a = [1 0.1 -0.8 -0.27]

We will generate five process implementations by filtering out white noise with different variances.

nr = 5
v = rand(1,nr)
1×5 Matrix{Float64}:
 0.264731  0.244259  0.401966  0.184345  0.070915
w = sqrt.(v[:])' .* randn(15000, nr)
x = filter(1,a,w)

Let’s evaluate the correlation function. Let’s discard the cross-correlation terms and correlation values for negative lag intervals. We use Levinson—Durbin recursion to estimate prediction errors for the correct model order and make sure that the prediction errors correspond to the variances of the input noise signals.

r, lg = xcorr(x,"biased")

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

println("e: ", e)
e: [0.26082618781928835; 0.24091448115262645; 0.40999877779431343; 0.18019545485810384; 0.07090107526341564;;]

Algorithms

Levinson—Durbin recursion is an algorithm for finding an all—pole IIR filter with a given deterministic autocorrelation sequence. It finds applications in filter design, coding, and spectral analysis. The filter that uses levinson, is a minimum phase filter.

Function levinson solves a symmetric system of linear equations Greenhouse:

where r is the input autocorrelation vector, and denotes a complex conjugation . The input vector r It is usually a vector of autocorrelation coefficients, where is the lag interval 0 is the first element .

If r if there is no correct autocorrelation sequence, then the function levinson It can return values NaN even if a solution exists.

The algorithm requires operations and is therefore much more efficient than the operator \ for large values n. However, the function levinson uses \ for low orders, to ensure the fastest possible execution.

Literature

  1. Ljung, Lennart. System Identification: Theory for the User. 2nd Ed. Upper Saddle River, NJ: Prentice Hall, 1999.