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

Click For Summary

Discussion Overview

The discussion revolves around exploring autocorrelation functions in MATLAB, particularly focusing on how to compute autocorrelation for different lags and the differences between various MATLAB functions like autocorr and xcorr. Participants express confusion regarding notation and the implications of using different functions for autocorrelation.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • Mike expresses confusion about the definition of autocorrelation in MATLAB, particularly regarding the notation x(n-l) * x(n-k) and whether MATLAB can compute this.
  • One participant clarifies that x(n-l) * x(n-k) can be expressed as x(n) * x(n-(k-l)), suggesting that MATLAB routines can handle this by providing autocorrelation at different lags.
  • Mike references matrix forms of autocorrelation and questions the differences between the two representations provided in his book, noting that both matrices seem to describe stationary processes.
  • Another participant explains that the MATLAB autocorr function returns a vector of lag autocorrelation values and points out the indexing differences in MATLAB, where indices start at 1.
  • Mike mentions using the xcorr() function and describes how it provides values for a Toeplitz matrix, but he is seeking specific lags that are not directly provided by this function.
  • A participant questions the use of cross-correlation for autocorrelation, suggesting that many elements in the matrix may be identical and expressing uncertainty about the calculation of these values.
  • This participant also asserts that there is no concept of autocorrelation for lags rx(l,k) as proposed by Mike, recommending the use of the autocorr function instead.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to compute autocorrelation for different lags, with some advocating for the use of the autocorr function while others discuss the implications of using xcorr. There is ongoing confusion and debate regarding the notation and the interpretation of results.

Contextual Notes

There are unresolved questions regarding the differences between the autocorrelation matrices described in the literature and the outputs from MATLAB functions. Additionally, the implications of using cross-correlation in the context of autocorrelation remain unclear.

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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K