## Understanding The Cross Correlation Function

To illustrate the use of the cross correlation function, a source location example is shown below. For this, it is assumed that there is a noise source at some unknown position between 2 microphones. A cross correlation technique and a transfer function like approach were used to determine the location.

To simulate the noise a broad band Gaussian signal was bandpass filtered from 500 to 1500Hz. This random signal, s(t), was generated at 10000 samples/second. Two delayed signals, p1(t) and p2(t), were then formed. Assuming the speed of sound in air is 1000ft/second then p1(t) was formed from s(t) with a 25 msec delay by ignoring the first 250 values. Similarly, p2(t) was formed with 14msec delay by ignoring the first 140 values. In order to represent dispersion and other specific path effects, two unrelated Gaussian broad band signals, n1(t) and n2(t), were also generated, each with approximately 20% of the overall energy of the original signal. The microphone simulation signals, x1(t) and x2(t), were then formed from

x1(t) = p1(t) + n1(t)

x2(t) = p2(t) + n2(t)

A section of x1(t) and x2(t) is shown below

Correlating x2 with x1 as reference gave a peak in the cross correlation at -11 msecs as shown below

The distance between the microphones was 39 feet. A delay of -11 msecs represents a distance of -11 feet.

Thus if we let the distance of the source from microphone one be d1 and from microphone two be d2 then we have

d1 + d2 = 39

d2 – d1 = -11

Solving gives d2 = 14 feet and d1 = 25 feet which are the correct results.

Note that if we correlate x1 with x2 as the reference then the delay is 11 msecs as shown below.

In this case, we have

d1 + d2 = 39

d1 – d2 = 11

Solving again gives d1 = 25 and d2 = 14.

An alternative approach is to carry out a form of transfer function analysis between the 2 microphones responses. This is not a strict transfer function which is normally an excitation and response to that excitation. However, the delay information is still contained in the signals. Now the transfer function H(f) is defined by $H(f) = \frac{G_{xy}(f)}{G_{xx}(f)}$

where Gxx is the auto spectrum of the “excitation” and Gxy is the cross spectrum of the response with respect to the excitation. Once H(f) is known then the impulse response function h(t) may be found by inverse Fourier transforming H(f). The way in which h(t) is formed means that positive time delays are from 0 time to the mid time point and negative delays are from the last time point back to the midpoint. An option is available to carry out the time shift automatically.

The graphs below show the two auto spectra, the cross spectrum, the pseudo transfer function, the coherence function and the impulse response function.

The two auto spectra above are very similar as would be expected but differences are discernable. Also, the broadband nature of the uncorrelated noise is evident at around the 62dB level.

The cross spectrum and the transfer function are also very similar except for scale. In both cases, the phase has been unwrapped which shows the effective linear delay.

For reference purposes, we have also shown the Coherence function.

As would be expected in this case the coherence outside the effective bandwidth of the signal is essentially zero. The coherence indicates that everything between about 500 to 1500 Hz is safe to believe but outside that region, there is little or no relationship.

Finally, the “Impulse Response” function was formed by calculating an inverse FFT of the “transfer function” and selecting the timeshift option to get positive and negative time shown.

The peak is just before zero. Showing an expanded view reveals the time delay as -11 msec as expected.

If we had just inverse transformed the cross spectrum we would have just got the correlation function. Dividing by the input auto spectrum is useful however because it effectively normalises the data. Another helpful scheme is to multiply the cross spectrum by the coherence as this effectively eliminates the unrelated parts. This is not necessary here as we have a sufficient signal to noise ratio.

The following two tabs change content below. #### Dr Colin Mercer

Chief Signal Processing Analyst (Retired) at Prosig
Dr Colin Mercer was formerly at the Institute of Sound and Vibration Research (ISVR), University of Southampton where he founded the Data Analysis Centre. He then went on to found Prosig in 1977. Colin retired as Chief Signal Processing Analyst at Prosig in December 2016. He is a Chartered Engineer and a Fellow of the British Computer Society. ## 10 thoughts on “Understanding The Cross Correlation Function”

1. liwei

good!

2. Lily Yu

Thank you!
How can i learn more detailed information about coherence analysis?

3. S.Sadasivan

Very nice introduction to rudiments of acoustic source localization. The ‘ylabel’ for coherence should be ‘coherence’ ( non dimensional) and I am sure it is shown otherwise in the figure by oversight.

Thanks again for a clear exposition.

4. vel murugan.R

Am going to do my Post graduate project regarding Flow measurement using cross correlation ultrasonic transreceivers… In my project, i have to find delay between the two signals using cross correlation.

I need some guidance of You all… could u please help me…..

5. Gordon Eden

What software is available to the analyses detailed above?

1. Prosig

Hello Gordon

The software used above (and in our other posts) is Prosig’s DATS package.

6. DURGA PRASAD

can we use this correlation concept to audio fingerprinting??

1. Dr Colin Mercer Post author

If you are wanting to see how alike one signal is to another one, the yes it can form the basis. However it would probably need to involve partial and multiple coherence factors. These are somewhat specialist. All depends on the accuracy/reliability of the match.

Colin

7. DURGA PRASAD

here this is my idea sir i need to shutdown the tap or valve depending on the sound coming from

container(bucket,glass,whatever it may be…). if we have prerecorded and processed database and

its metadata then we need to compare those to the real time sample. so if we keep the vessel under

the tap it should be automatically off to wherever quantity we require by just comparing its features

to the database. is it possible to include this correlation as a feature into the database?

sir can you help me on this problem please…

8. Danjuma

Dear Dr Colin,
I need some guidance on how to find similarity and cross-correlation between two gamma densitometer signal using Matlab.

Thanks for your time

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1. We welcome any feedback, questions or comments CLOSE
Optimization WordPress Plugins & Solutions by W3 EDGE