Understanding Autocorrelation in Matlab: Exploring Functions for Different Lags

In summary: The 'xcorr' function calculates the cross correlations between two variables. The function returns a vector of lag cross correlations, acv(l). The 'rx' function in your question returns the autocorrelation of lag 1.
  • #1
MikeSv
35
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
  • #2
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.
 
  • #3
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
 
  • #4
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).)
 
  • #5
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
 
  • #6
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.
 

What is autocorrelation and why is it important?

Autocorrelation refers to the correlation of a signal with a delayed version of itself. It is important in signal processing and time series analysis as it allows us to identify patterns and relationships within a signal over time.

How do I calculate autocorrelation in Matlab?

In Matlab, you can use the autocorr function to calculate autocorrelation. This function takes in a signal as input and returns the autocorrelation coefficients for different lags.

What are the different types of autocorrelation functions?

The two main types of autocorrelation functions are the sample autocorrelation function (ACF) and the partial autocorrelation function (PACF). The ACF measures the correlation between a signal and its lagged versions, while the PACF measures the correlation between a signal and its lagged versions, while controlling for the effects of other lags.

How can I visualize autocorrelation in Matlab?

You can use the autocorr function to plot the autocorrelation coefficients against different lags. Additionally, you can use the xcorr function to plot the cross-correlation between two signals.

What are some common applications of autocorrelation analysis?

Autocorrelation analysis is commonly used in fields such as finance, economics, and engineering to analyze time series data and identify patterns and trends. It is also used in noise reduction techniques and signal processing applications.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
856
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
936
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Replies
1
Views
954
  • Calculus and Beyond Homework Help
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
710
Back
Top