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

AI Thread Summary
The discussion centers on the use of MATLAB for exploring autocorrelation functions, specifically regarding the confusion between different lag notations and the appropriate functions to use. Users clarify that MATLAB's autocorr function computes sampled autocorrelation values, while the xcorr function is intended for cross-correlation, which can lead to redundancy in results. The distinction between autocorrelation at various lags is emphasized, with the suggestion to utilize the autocorr function for clarity. Additionally, there is a note on MATLAB's indexing starting at 1, which affects how lag values are accessed. Overall, the conversation aims to clarify the correct approach to calculating and interpreting autocorrelation in MATLAB.
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
3
Views
2K
Replies
1
Views
8K
Replies
1
Views
4K
Replies
3
Views
3K
Back
Top