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

Click For Summary
SUMMARY

This discussion centers on exploring autocorrelation functions for different lags using MATLAB. Users express confusion regarding the notation and functionality of the autocorr and xcorr functions. It is established that MATLAB's autocorr function returns a vector of autocorrelation values, while the xcorr function computes cross-correlation, which can also yield autocorrelation results under certain conditions. The distinction between these functions is crucial for correctly interpreting the results and constructing the desired autocorrelation matrix.

PREREQUISITES
  • Understanding of autocorrelation and cross-correlation concepts
  • Familiarity with MATLAB functions, specifically autocorr and xcorr
  • Knowledge of wide-sense stationary (WSS) processes
  • Basic matrix operations and properties, particularly Toeplitz matrices
NEXT STEPS
  • Research the MATLAB autocorr function and its parameters
  • Explore the xcorr function in MATLAB for cross-correlation analysis
  • Study the properties of Toeplitz matrices in the context of autocorrelation
  • Learn about wide-sense stationary (WSS) processes and their implications in time series analysis
USEFUL FOR

Data analysts, statisticians, and engineers working with time series data in MATLAB, particularly those interested in autocorrelation and cross-correlation analysis.

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
8K
  • · 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