How Can You Explore Autocorrelation Functions for Different Lags in Matlab?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 3K views
MikeSv
Messages
34
Reaction score
0
Hello everyone.

Iam a little bit confused about the autocorrelation and using Matlab so I hope someone can help me out.

As far as understand Matlab computes the sampled autocorrelation where the lag between the samples is given by x(n)* x(n-l).

Buy what if the autocorrelation depends on the following lag

x(n-l) *x(n-k)

Does Matlab has a function of that?

Thanks in advance,

Best Regards,

Mike
 
Physics news on Phys.org
The 'l' in x(n)* x(n-l) just indicates the fixed number of samples from the x value x(n) and the x value x(n-l) while n goes through all values. Your x(n-l) *x(n-k) is the same as x(n) *x(n-(k-l)). So you are just asking for the autocorrelation at a different lag, which the MATLAB routine also gives.
 
Hi and thanks for the quick reply!
I think Iam just confused about the notation.

When I look at the Matrix forms of rx(k, l) and rx(k) my book says:

Rx(k,l) = Rx(0,0) Rx(0,1)... Rx(0,p)
Rx(1,0) Rx(1,1)... Rx(1,p)
...
Rx(p,0) Rx(p,1)... Rx(p,p)

If x is a WSS process

Rx(k) = Rx(0) Rx(1)... Rx(p)
Rx(1) Rx(0)... Rx(p-1)
...
Rx(p) Rx(p-1)... Rx(0)

Matlab gives me the first Matrix but
I can't really see a difference between the two as l in the second Matrix is stationary and so is k in the first.

Thanks again,

Best Regards,

Mike
 
I'm not sure what you mean. If you call the MATLAB autocorr function, it returns a vector, acf, of lag autocorrelation values.(see https://www.mathworks.com/help/econ/autocorr.html#outputarg_acf )

So the (l-k) lag value is the in position acf(n+1) where n=l-k. acf(1) = 1 is the 0-lag value.

PS. I'm not familiar with MATLAB allowing matrix indices of 0. I think they start at 1, which is why you have to add 1 to the lag number (autocorrelation of lag=1 is at acf(2).)
 
Hi and thanks again.

Sorry that my previous post was a Little bit confusing.
Iam using the xcorr() function and from what I understand, xcorr gives me the lags (for both plus and minus)

rx(0,0), rx(0,1), rx(0,2)...,rx(0,N)

When I compute the autocorrelation Matrix with these values I'll get a Toeplitz Matrix.

My problem is that I want to find the lags:

rx(1,1) rx(1,2) rx(1,3)...rx(1,N)
rx(2,1) rx(2,2) rx(2,3)... rx(2,N)
...
Michael
 
I don't understand the reason to use a cross correlation algorithm for an autocorrelation. I guess that means that many elements of the matrix are identical.
For instance, rx(2,1) = rx(3,2)=rx(4,3)=... since those all are the autocorrelations of lag 1.
Although I am not sure that all the cross correlations that represent autocorrelations of lag 1 are calculated using the same number of data points.

There is no such thing as an autocorrelation of lags rx(l,k) as you suggest. There is only a vector of autocorrelations of lags acv(l).

I suggest that you use the autocorr function to avoid confusion.