| 1 |
<html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 |
<title>Sounds: Cross-correlate...</title> |
| 3 |
<style> |
| 4 |
td { padding-left: 5pt; padding-right: 5pt; } |
| 5 |
th { padding-left: 5pt; padding-right: 5pt; } |
| 6 |
code { white-space: pre-wrap; } |
| 7 |
dd { white-space: pre-wrap; } |
| 8 |
</style> |
| 9 |
</head><body bgcolor="#FFFFFF"> |
| 10 |
|
| 11 |
<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b> |
| 12 |
Sounds: Cross-correlate... |
| 13 |
</b></font></table></table> |
| 14 |
<p>A command available in the <b>Combine</b> menu when you select two <a href="Sound.html">Sound</a> objects. This command cross-correlates two selected <a href="Sound.html">Sound</a> objects with each other. As a result, a new Sound will appear in the list of objects; this new Sound is the <i>cross</i>-correlation of the two original Sounds.</p> |
| 15 |
<h2>Settings</h2> |
| 16 |
<dl> |
| 17 |
<dt><b>Amplitude scaling</b> |
| 18 |
<dd>Here you can choose between the “principled” options <b>integral</b>, <b>sum</b>, and <b>normalize</b>, which are explained in 1, 2 and 3 below. There is also a “pragmatic” option, namely <b>peak 0.99</b>, which scales the resulting sound in such a way that its absolute peak becomes 0.99, so that the sound tends to be clearly audible without distortion when you play it (see <a href="Sound__Scale_peak___.html">Sound: Scale peak...</a>).</dd> |
| 19 |
<dt><b>Signal outside time domain is...</b> |
| 20 |
<dd>Here you can choose whether outside their time domains the sounds are considered to be <b>zero</b> (the standard value), or <b>similar</b> to the sounds within the time domains. This is explained in 4 below.</dd> |
| 21 |
</dl> |
| 22 |
<h2>1. Cross-correlation as an integral</h2> |
| 23 |
<p>The cross-correlation of two continuous time signals <i>f</i>(<i>t</i>) and <i>g</i>(<i>t</i>) is a function of the lag time <i></i> a, and defined as the <b>integral</b></p> |
| 24 |
<table width="100%" style="white-space:pre-wrap"><tr><td align=middle>cross-corr (<i>f</i>, <i>g</i>) (<i>τ</i>) ≡ ∫ <i>f</i>(<i>t</i>) <i>g</i>(<i>t</i>+<i>τ</i>) <i>dt</i></table> |
| 25 |
<p>If <i>f</i> and <i>g</i> are sampled signals (as Sounds are in Praat), with the same <a href="sampling_period.html">sampling period</a> <i> et</i>, the definition is discretized as</p> |
| 26 |
<table width="100%" style="white-space:pre-wrap"><tr><td align=middle>cross-corr (<i>f</i>, <i>g</i>) [<i>τ</i>] ≡ ∑<sub><i>t</i></sub> <i>f</i>[<i>t</i>] <i>g</i>[<i>t</i>+<i>τ</i>] <i>Δt</i></table> |
| 27 |
<p>where <i>τ</i> and <i>t</i>+<i>τ</i> are the discrete times at which <i>f</i> and <i>g</i> are defined, respectively.</p> |
| 28 |
<p>Cross-correlation is not a commutative operation, i.e. cross-corr (<i>g</i>, <i>f</i>) equals the time reversal of cross-corr (<i>f</i>, <i>g</i>). This means that the order in which you put the two Sounds in the object list does matter: the two results are each other's time reversals.</p> |
| 29 |
<h2>2. Cross-correlation as a sum</h2> |
| 30 |
<p>You can see in the formula above that if both input Sounds are expressed in units of Pa, the resulting Sound should ideally be expressed in Pa<sup>2</sup>s. Nevertheless, Praat will express it in Pa, because Sounds cannot be expressed otherwise.</p> |
| 31 |
<p>This basically means that it is impossible to get the amplitude of the resulting Sound correct for all purposes. For this reason, Praat considers a different definition of cross-correlation as well, namely as the <b>sum</b></p> |
| 32 |
<table width="100%" style="white-space:pre-wrap"><tr><td align=middle>cross-corr (<i>f</i>, <i>g</i>) [<i>τ</i>] ≡ ∑<sub><i>t</i></sub> <i>f</i>[<i>t</i>] <i>g</i>[<i>t</i>+<i>τ</i>]</table> |
| 33 |
<p>The difference between the integral and sum definitions is that in the sum definition the resulting sound is divided by <i>Δt</i>.</p> |
| 34 |
<h2>3. Normalized cross-correlation</h2> |
| 35 |
<p>The <i>normalized cross-correlation</i> is defined as</p> |
| 36 |
<table width="100%" style="white-space:pre-wrap"><tr><td align=middle>norm-cross-corr (<i>f</i>, <i>g</i>) (<i>τ</i>) ≡ ∫ <i>f</i>(<i>t</i>) <i>g</i>(<i>t</i>+<i>τ</i>) <i>dt</i> / √ (∫ <i>f</i><sup>2</sup>(<i>t</i>) <i>dt</i> ∫ <i>g</i><sup>2</sup>(<i>t</i>) <i>dt</i>)</table> |
| 37 |
<h2>4. Shape scaling</h2> |
| 38 |
<p>The boundaries of the integral in 1 are −∞ and +∞. However, <i>f</i> and <i>g</i> are Sound objects in Praat and therefore have finite time domains. If <i>f</i> runs from <i>t</i><sub>1</sub> to <i>t</i><sub>2</sub> and is assumed to be <b>zero</b> before <i>t</i><sub>1</sub> and after <i>t</i><sub>2</sub>, and <i>g</i> runs from <i>t</i><sub>3</sub> to <i>t</i><sub>4</sub> and is assumed to be zero outside that domain, then the cross-correlation will be zero before <i>t</i><sub>3</sub>−<i>t</i><sub>2</sub> and after <i>t</i><sub>4</sub>−<i>t</i><sub>1</sub>, while between <i>t</i><sub>3</sub>−<i>t</i><sub>2</sub> and <i>t</i><sub>4</sub>−<i>t</i><sub>1</sub> it is</p> |
| 39 |
<table width="100%" style="white-space:pre-wrap"><tr><td align=middle>cross-corr (<i>f</i>, <i>g</i>) (<i>τ</i>) = ∫<sub><i>t1</i></sub><sup><i>t2</i></sup> <i>f</i>(<i>t</i>) <i>g</i>(<i>t</i>+<i>τ</i>) <i>dt</i></table> |
| 40 |
<p>In this formula, the argument of <i>f</i> runs from <i>t</i><sub>1</sub> to <i>t</i><sub>2</sub>, but the argument of <i>g</i> runs from <i>t</i><sub>1</sub>+(<i>t</i><sub>3</sub>−<i>t</i><sub>2</sub>) to <i>t</i><sub>2</sub>+(<i>t</i><sub>4</sub>−<i>t</i><sub>1</sub>), i.e. from <i>t</i><sub>3</sub>−(<i>t</i><sub>2</sub>−<i>t</i><sub>1</sub>) to <i>t</i><sub>4</sub>+(<i>t</i><sub>2</sub>−<i>t</i><sub>1</sub>). This means that the integration is performed over two equal stretches of time during which <i>g</i> must be taken zero, namely a time stretch before <i>t</i><sub>3</sub> and a time stretch after <i>t</i><sub>4</sub>, both of duration <i>t</i><sub>2</sub>−<i>t</i><sub>1</sub> (equivalent equations can be formulated that rely on two stretches of <i>t</i><sub>4</sub>−<i>t</i><sub>3</sub> of zeroes in <i>f</i> rather than in <i>g</i>, or on a stretch of <i>t</i><sub>2</sub>−<i>t</i><sub>1</sub> of zeroes in <i>g</i> and a stretch of <i>t</i><sub>4</sub>−<i>t</i><sub>3</sub> of zeroes in <i>f</i>.</p> |
| 41 |
<p>If you consider the sounds outside their time domains as <b>similar</b> to what they are within their time domains, instead of <b>zero</b>, the discretized formula in 1 should be based on the average over the jointly defined values of <i>f</i>[<i>τ</i>] and <i>g</i>[<i>t</i>−<i>τ</i>], without counting any multiplications of values outside the time domains. Suppose that <i>f</i> is defined on the time domain [0, 1.2] with the value of 1 everywhere, and <i>g</i> is defined on the time domain [0, 3] with the value 1 everywhere. Their cross-correlation under the assumption that they are <b>zero</b> elsewhere is then</p> |
| 42 |
<code> short = Create Sound from formula: "short", 1, 0.0, 1.2, 1000, ~ 1<br></code> |
| 43 |
<code> long = Create Sound from formula: "long", 1, 0.0, 3.0, 1000, ~ 1<br></code> |
| 44 |
<code> plusObject: short<br></code> |
| 45 |
<code> Cross-correlate: "integral", "zero"<br></code> |
| 46 |
<code> Draw: 0, 0, 0.0, 1.5, "yes", "curve"<br></code> |
| 47 |
<code> One mark left: 1.2, "yes", "yes", "yes", ""<br></code> |
| 48 |
<p align=middle><img height=300 width=500 src=Sounds__Cross-correlate____1.png></p><p>but under the assumption that the sounds are <b>similar</b> (i.e. 1) elsewhere, their cross-correlation should be</p> |
| 49 |
<code> selectObject: short, long<br></code> |
| 50 |
<code> Cross-correlate: "integral", "similar"<br></code> |
| 51 |
<code> Draw: 0, 0, 0.0, 1.5, "yes", "curve"<br></code> |
| 52 |
<code> One mark left: 1.2, "yes", "yes", "yes", ""<br></code> |
| 53 |
<p align=middle><img height=300 width=500 src=Sounds__Cross-correlate____2.png></p><p>i.e. a constant value of 1.2. This is what you get by choosing the <b>similar</b> option; if <i>f</i> is shorter than <i>g</i>, the first and last parts of the cross-correlation will be divided by a straight line of duration <i>t</i><sub>2</sub>−<i>t</i><sub>1</sub> to compensate for the fact that the cross-correlation has been computed over fewer values of <i>f</i> and <i>g</i> there.</p> |
| 54 |
<h2>5. Behaviour</h2> |
| 55 |
<p>The start time of the resulting Sound will be the start time of <i>f</i> minus the end time of <i>g</i>, the end time of the resulting Sound will be the end time of <i>f</i> minus the start time of <i>g</i>, the time of the first sample of the resulting Sound will be the first sample of <i>f</i> minus the last sample of <i>g</i>, the time of the last sample of the resulting Sound will be the last sample of <i>f</i> minus the first sample of <i>g</i>, and the number of samples in the resulting Sound will be the sum of the numbers of samples of <i>f</i> and <i>g</i> minus 1.</p> |
| 56 |
<h2>6. Behaviour for stereo and other multi-channel sounds</h2> |
| 57 |
<p>You can cross-correlate e.g. a 10-channel sound either with another 10-channel sound or with a 1-channel (mono) sound.</p> |
| 58 |
<p>If both Sounds have more than one channel, the two Sounds have to have the same number of channels; each channel of the resulting Sound is then computed as the cross-correlation of the corresponding channels of the original Sounds. For instance, if you cross-correlate two 10-channel sounds, the resulting sound will have 10 channels, and its 9th channel will be the cross-correlation of the 9th channels of the two original sounds.</p> |
| 59 |
<p>If one of the original Sounds has multiple channels and the other Sound has only one channel, the resulting Sound will have multiple channels; each of these is computed as the cross-correlation of the corresponding channel of the multiple-channel original and the single channel of the single-channel original. For instance, if you cross-correlate a 10-channel sound with a mono sound, the resulting sound will have 10 channels, and its 9th channel will be the cross-correlation of the mono sound with the 9th channel of the original 10-channel sound.</p> |
| 60 |
<p>The amplitude scaling factor will be the same for all channels, so that the relative amplitude of the channels will be preserved in the resulting sound. For the <b>normalize</b> scaling, for instance, the norm of <i>f</i> in the formula above is taken over all channels of <i>f</i>. For the <b>peak 0.99</b> scaling, the resulting sound will typically have an absolute peak of 0.99 in only one channel, and lower absolute peaks in the other channels.</p> |
| 61 |
<h2>7. Algorithm</h2> |
| 62 |
<p>The computation makes use of the fact that cross-correlation in the time domain corresponds to multiplication of the time-reversal of <i>f</i> with <i>g</i> in the frequency domain: we first pad <i>f</i> with a stretch of <i>t</i><sub>4</sub>−<i>t</i><sub>3</sub> of zeroes and <i>g</i> with a stretch of <i>t</i><sub>2</sub>−<i>t</i><sub>1</sub> of zeroes (see 4 above), so that both sounds obtain a duration of (<i>t</i><sub>2</sub>−<i>t</i><sub>1</sub>) + (<i>t</i><sub>4</sub>−<i>t</i><sub>3</sub>); we then calculate the spectra of the two zero-padded sounds by Fourier transformation, then multiply the complex conjugate of the spectrum of <i>f</i> with the spectrum of <i>g</i>, and finally Fourier-transform the result of this multiplication back to the time domain; the result will again have a duration of (<i>t</i><sub>2</sub>−<i>t</i><sub>1</sub>) + (<i>t</i><sub>4</sub>−<i>t</i><sub>3</sub>).</p> |
| 63 |
<h3>Links to this page</h3> |
| 64 |
<ul> |
| 65 |
<li><a href="Sound__Autocorrelate___.html">Sound: Autocorrelate...</a> |
| 66 |
<li><a href="What_was_new_in_5_2_.html">What was new in 5.2?</a> |
| 67 |
</ul> |
| 68 |
<hr> |
| 69 |
<address> |
| 70 |
<p>© David Weenink & Paul Boersma 2010-04-04,2024</p> |
| 71 |
</address> |
| 72 |
</body> |
| 73 |
</html> |