# Cross- and auto-correlation

1. Apr 24, 2016

### balanto

The problem statement, all variables and given/known data

1. Given two vectors
x = [0 0 1 0 0 ] and y = [0 0 0 0 1] find the cross correlation and the time difference between the pulses if the sampling frequency is 1kHz?

2. Given this vector calculate the auto correlation and if the signals is sampled at a frequency of 1MHz what does the signal correspond to in frequency
1. x = {0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1}
The attempt at a solution
Cross correlation for problem 1:
[0 0 1 0 0 0 0 0 0]

Auto correlation for problem 2:
[0 0 1 2 1 0 2 4 2 0 3 6 3 0 2 4 2 0 1 2 1 0 0]

The thing I'm having a hard time about is finding the time difference for problem 1 and the corresponding frequency in problem 2. How do I approach that?

2. Apr 24, 2016

### marcusl

1. What is the lag (offset from zero) of the non-zero entry in the xcorr? (You can also easily see the same time difference directly in the raw signals x and y.)
2. What theorem relates the autocorrelation function to the power spectral density?

3. Apr 24, 2016

### balanto

1. Okey, then the lag should be 2 in this case? Because there are two zero values before the first non-zero? And since the sampling time is 1ms then the time difference would be 2ms?
2. That would be integral of [f(t)*e^(-jwt) dt] where f(t) is the correlation function. Although I'm not sure what to do here. Since our autocorrelation have 15 values, from 0 - 14, then the limits of integrations would be 0 --> 14, but that would only result in 0. Im not quite sure I understand cross/autocorrelation and its applications

4. Apr 24, 2016

### marcusl

Number one is correct.
For number two, why do you think it is zero? In general, there will be an infinite number of omega frequencies to evaluate. In practice, you can assume a discrete Fourier transform, and just evaluate integer values k such that omega runs from 0 to 14 * 2*pi.
As for the meaning of autocorrelation, it gives the extent to which each point in a sequence is related to its nearest neighbors, next nearest neighbors, and so on.

Last edited: Apr 24, 2016
5. Apr 24, 2016

### marcusl

I think my last post could have been clearer. The exponential for a discrete FT looks like $$exp\left(\frac{-j2\pi nk}{N}\right)$$ with the indices n and k running from 0 to N-1. Here n indexes time and k indexes frequency. Also I just counted the number of values in your cross correlation and there are 23, not 14.

Last edited: Apr 24, 2016