Self-correlation function xcorr of Matlab

Source: Internet
Author: User

Self-correlation function xcorr of Matlab
Recently, matlab was used as a tool for data statistics because of the work relationship. One of the keys was to use its self-correlation function to obtain data estimates. I learned a little matlab only when I was a bachelor. This time, I quickly passed the required matlab syntax on the basis of C/C ++, it turns out that this language is similar to a script. It is weak in the same way as Python, and its syntax is not strict. After learning about the syntax, I am now at Help? The xcorr function is described as follows:

It seems that the syntax is not difficult. Isn't the direct operation good? However, I don't understand the calculated results. Because I don't have much statistics, I went to Bala's mathematical materials and wanted to understand the principles or formulas of the xcorr function. Finally, I found the answer I was looking for at the matlab Forum. Here I will analyze the cross-correlation function xcorr of matlab.
Parameters in matlab are stored as arrays. scalar values can be considered as one-dimensional arrays. We use sequence x = [1, 3, 5] as the experimental object. After xcorr () function operation, the analysis results are as follows:
1. xcorr ()

 
 
  1. >> x = [1 3 5]

  2. x =

  3. 1 3 5

  4. >> [a,b] = xcorr(x)

  5. a =

  6. 5 18 35 18 5


  7. b =

  8. -2 -1 0 1 2

  9. >>
Maybe you are confused about the result. Wait for me to come. During calculation, B is first calculated, and the sequence numbers of the elements in sequence x are subtracted from each other. The possible set of all values can be obtained, which is sorted in ascending order and B is obtained; then calculate the sequence a based on the "difference" of the serial number:
When B (1) =-2, only the difference between data (1, 5) can be obtained, that is, the difference between sequence 1 and sequence 3. Therefore, a (1) is calculated) = 1*5 = 5;
When B (2) =-1, the sequence numbers (3, 1) and the sequence numbers (5, 3) are involved. Therefore, a (2) is calculated) = 3*1 + 5*3 = 18;
When B (3) = 0, the corresponding numbers (1, 1), (3, 3) and (5, 5) are involved. Therefore, a (3) is calculated) = 1*1 + 3*3 + 5*5 = 35;
When B (4) = 1, the values (3, 1) and (5, 3) corresponding to the sequence numbers are involved, and a (4) is calculated) = 3*1 + 5*3 = 18;
When B (5) = 2, the corresponding sequence number (5, 1) is involved (the sequence number of the subsequent data minus the sequence number of the previous data is exactly 2), and a (5) is calculated) = 5*1 = 5

2. xcorr (x, 'unbiased ')
The 'unbiased' parameter is used to calculate the result based on the default parameter. The calculation of each group is based on the number of sequence groups in the group. For example, when B (1) is used, the number of groups is 1, if it is recorded as N = 1, a (1) = 1*5/N = 5; B (2) is a (2) = 18/N = 18/2 = 9; similar;

 
 
  1. >> [a, b] = xcorr(x, 'unbiased')

  2. a =

  3. 5.0000 9.0000 11.6667 9.0000 5.0000


  4. b =

  5. -2 -1 0 1 2

  6. >>
3. xcorr (x, 'biased ')
The 'biased' parameter is used to divide the default parameter by the length of sequence x, that is, a (1) = 5/3. For example:

 
 
  1. >> [a, b] = xcorr(x, 'biased')

  2. a =

  3. 1.6667 6.0000 11.6667 6.0000 1.6667


  4. b =

  5. -2 -1 0 1 2

  6. >>
4. xcorr (x, 'coeff ')
In this case, it is used to find the auto-correlation sequence of sequence x. The result is normalized based on the condition of 'biased', so that when B = 0, the Intermediate Value a (3) = 1, therefore, a (1) = 5/11. 6667. All group data is normalized by 11.6667 Based on 'biased:

 
 
  1. >> [a, b] = xcorr(x, 'coeff')

  2. a =

  3. 0.1429 0.5143 1.0000 0.5143 0.1429


  4. b =

  5. -2 -1 0 1 2

  6. >>

Because xcorr is mostly used for engineering time signal sampling, but the collected data is sent to matlab together during calculation, matlab itself does not know the time interval, we can use dt = 0.1, t = B * dt, plot (t, a) for plotting, the first half is ahead, and the second half is lagging, such:





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.