# 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, p_{1}(t) and p_{2}(t), were then formed. Assuming the speed of sound in air is 1000ft/second then p_{1}(t) was formed from s(t) with a 25 msec delay by ignoring the first 250 values. Similarly, p_{2}(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, n_{1}(t) and n_{2}(t), were also generated, each with approximately 20% of the overall energy of the original signal. The microphone simulation signals, x_{1}(t) and x_{2}(t), were then formed from

x_{1}(t) = p_{1}(t) + n_{1}(t)

x_{2}(t) = p_{2}(t) + n_{2}(t)

A section of x_{1}(t) and x_{2}(t) is shown below

Correlating x_{2} with x_{1} 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 d_{1} and from microphone two be d_{2} then we have

d_{1} + d_{2} = 39

d_{2} – d_{1} = -11

Solving gives d_{2} = 14 feet and d_{1} = 25 feet which are the correct results.

Note that if we correlate x_{1} with x_{2} as the reference then the delay is 11 msecs as shown below.

In this case, we have

d_{1} + d_{2} = 39

d_{1} – d_{2} = 11

Solving again gives d_{1} = 25 and d_{2} = 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

where G_{xx} is the auto spectrum of the “excitation” and G_{xy} 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.

#### Dr Colin Mercer

#### Latest posts by Dr Colin Mercer (see all)

- Is That Tone Significant? – The Prominence Ratio - September 18, 2013
- A Guide To Digital Filtering - June 4, 2013
- Wide Band Integrators – What Are They? - June 15, 2012

good!

Thank you!

How can i learn more detailed information about coherence analysis?

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.

S.Sadasivan

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…..

What software is available to the analyses detailed above?

Hello Gordon

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

can we use this correlation concept to audio fingerprinting??

please help me on this topic…

Prasad

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

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…

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