Precedence-based cross-correlograms

Calculate cross-correlograms with a wide range of options
Updated 5 May 2018

NOTE: this function is now available from the IoSR Matlab Toolbox as iosr.auditory.chXcorr.
Calculate cross-correlograms with a wide range of options.
ccg = ch_xcorr(hc_L,hc_R,fs)
ccg = ch_xcorr(hc_L,hc_R,fs,'parameter',value)
[ccg,ic] = ch_xcorr(...)

ccg = ch_xcorr(hc_L,hc_R,fs) cross-correlates the input
2-D matrices hc_L and hc_R over 10ms frame with a
maximum lag of 1ms. It is assumed that the number of
frequency channels is min(size(hc_L)) and hence hc_L and
hc_R can be in either orientation. The
cross-correlograms consist of cross-correlations for
every frame and frequency channel. ccg has dimensions
[lag,frequency,frame]. The function calculates running
cross-correlations for every sample and integrates these
cross-correlations over each frame. The number of
frames frame_count is calculated thus:

frame_count = ...

The underlying cross-correlation algorithm is based on
that proposed by Faller & Merimaa [1]. In this
implmentation, the time constant of the backward
infinite exponential window is given by tau (in

ccg = ch_xcorr(hc_L,hc_R,fs,'parameter',value) allows a
number of options to be specified. The options are:

({} indicates the default value)

'frame_length' : {round(0.01*fs)} | scalar
The length of frames used to calculate for
integrating cross-correlations.
'noverlap' : {1} | scalar
The number of frames over which to integrate the
cross-correlations. Note that the frame count is
reduced accordingly.
'maxlag' : {round(0.001*fs)} | scalar
The maximum lag of the cross-correlation.
'tau' : {round(0.01*fs)} | scalar
The time constant of the exponential window used to
calculate running cross-correlations.
'inhib' : {[]} | array
Specificies an array with which to multiply the
cross-correlations before they are integrated. The
value defaults to an empty array, meaning that no
inhibition will be applied.
'ic_t' : {0} | scalar
Specifies the interaural coherence (IC) threshold.
Only samples for which the IC exceeds this threshold
will be used to integrate cross-correlations. The
algorithm calculates Interaural Coherence (IC)
according to [1]. The value should be in the range
'norm_flag' : {0} | scalar
Specifies whether the cross-correlograms are
calculated using normalised cross-correlations. A
non-zero value indicates that normalised
cross-correlations are used.
'inhib_mode' : {'subtract'} | 'multiply'
Specify how the inhibition is applied. The default
'subtract' will subtract inhib from the running
cross-correlations; 'multiply' will multiply inhib
with the running cross-correlations.

[ccg,ic] = ch_xcorr(...) returns the calculated IC to
the matrix IC. Although the matrix returned is the same
size as hc_L, IC is only calculated for samples
1:frame_count*frame_length, other values will be set to


See the enclosed documentation for more details on the
workings of the algorithm and an important caveat.


[1] C. Faller and J. Merimaa, "Source localization in
complex listening situations: Selection of binaural cues
based on interaural coherence", The Journal of the
Acoustical Society of America, vol. 116, pp.3075-3089,
Nov. 2004.

Further Reading

C. Hummersone, R. Mason, and T. Brookes, "A comparison
of computational precedence models for source separation
in reverberant environments", in 128th Audio Engineering
Society Convention, London, May 2010, paper 7981.

Cite As

Christopher Hummersone (2024). Precedence-based cross-correlograms (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes

Migrated to GitHub.
A few simplifications made to the C source code. Overhauled the interface: dramatically reduced the number of required arguments, and added other arguments as optional parameter/value pairs.
Corrected title.

Made many simplifications to the C source code, and added error checks to m code.

Output IC now reflects specified threshold.

Some bug fixes.

Fixed a bug whereby output IC would not be the same size as the input data. Added check to ensure that they are the same size and transposition. Updated help to include dims of output CCG.

Added updated check_mex_compiled.m

Updated documentation, added verbose comments through source code

Updated check for inhib matrix size and shape

removed need to framecount parameter input, now calculated automatically.

Fixed a bug that gave negative numbers when using the 'subtract' option. Updated the documentation accordingly.

Created additional documentation explaining the algorithm.

Added additional 'NOVERLAP' parameter for integrating over several frames. Added note to documentation on limitations for normalised cross-correlation.

Whoops, fixed another silly mistake, thanks to Lars Bramsløw

Fixed an issue with an un-specified max function. Thanks to Lars Bramsløw for pointing it out.

Updated the mex function

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.