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

Cross correlation time histories

Figure 1: Cross correlation time histories

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

Cross correlation of x2 with x1 as reference

Figure 2: Cross correlation of x2 with x1 as reference

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.

Cross correlation of x1 with x2 as reference

Figure 3: Cross correlation of x1 with x2 as reference

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.

Auto-spectrum of x1

Figure 4: Auto-spectrum of x1

Auto-spectrum of x2

Figure 5: Auto-spectrum of x2

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.

Cross spectrum of x1 with x2 as reference

Figure 6: Cross spectrum of x1 with x2 as reference

Transfer function

Figure 7: Transfer function

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

Coherence function for x1 and x2

Figure 8: Coherence function for x1 and x2

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.

Impulse response function

Figure 9: Impulse response function

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

Impulse response function (expanded view)

Figure 10: Impulse response function (expanded view)

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.

Latest posts by Dr Colin Mercer (see all)

10 thoughts on “Understanding The Cross Correlation Function

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

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

    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.



    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…

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

Leave a Reply

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

  1. We welcome any feedback, questions or comments
Optimization WordPress Plugins & Solutions by W3 EDGE
%d bloggers like this: