| 1 |
# stereoAnalysis.praat |
| 2 |
# Paul Boersma, 31 December 2025 |
| 3 |
# |
| 4 |
# This script checks that analyses on stereo sounds make sense |
| 5 |
# as compared to each other and as compared to analyses on mono sounds. |
| 6 |
# |
| 7 |
# This script uses pre-2014 syntax, because we like to measure the history of Praat |
| 8 |
# since multi-channel sounds were introduced in 2007. |
| 9 |
# |
| 10 |
# We need Praat version 5 (from 2009) or up, though, |
| 11 |
# because version 4 didn't have objectsAreIdentical() yet. |
| 12 |
# Requiring version 5 or up also means that we can use praatVersion and object [] |
| 13 |
# and that we can be certain that stereo sounds were supported. |
| 14 |
|
| 15 |
# |
| 16 |
# CREATING STEREO SOUNDS |
| 17 |
# |
| 18 |
# Stereo sounds were supported since 2007, and the oldest version we are testing |
| 19 |
# is 5.1.12 from 2009. Therefore, the following code works from version 5.1.12 on. |
| 20 |
# |
| 21 |
|
| 22 |
# |
| 23 |
# Create a stereo sound with only the left channel filled. |
| 24 |
# |
| 25 |
chan1.Sound = Create Sound from formula... chan1 stereo 0.0 1.0 44100 |
| 26 |
... if row = 1 then 1/2 * sin(2*pi*377*x) + randomGauss(0,0.1) else 0.0 fi |
| 27 |
|
| 28 |
# |
| 29 |
# Create the mirror image of that sound. |
| 30 |
# |
| 31 |
chan2.Sound = Create Sound from formula... chan2 stereo 0.0 1.0 44100 |
| 32 |
... object [chan1.Sound, 3 - row, col] |
| 33 |
|
| 34 |
# |
| 35 |
# Create the sum sound. |
| 36 |
# |
| 37 |
sum.Sound = Create Sound from formula... sum stereo 0.0 1.0 44100 |
| 38 |
... object [chan1.Sound] + object [chan2.Sound] |
| 39 |
|
| 40 |
# |
| 41 |
# Create the difference sound. |
| 42 |
# |
| 43 |
difference.Sound = Create Sound from formula... difference stereo 0.0 1.0 44100 |
| 44 |
... object [chan1.Sound] - object [chan2.Sound] |
| 45 |
|
| 46 |
# |
| 47 |
# Create the average sound. |
| 48 |
# |
| 49 |
average.Sound = Create Sound from formula... average stereo 0.0 1.0 44100 |
| 50 |
... 0.5 * object [sum.Sound] |
| 51 |
|
| 52 |
# |
| 53 |
# PITCH ANALYSIS |
| 54 |
# |
| 55 |
# The pitch analysis should give the exact same result on all five sounds. |
| 56 |
# This is because channel averaging occurs late, namely at the autocorrelation level. |
| 57 |
# |
| 58 |
# The following code works from Praat version 5.1.12 on. |
| 59 |
# |
| 60 |
|
| 61 |
select Sound chan1 |
| 62 |
chan1.Pitch = To Pitch... 0.01 75 600 |
| 63 |
|
| 64 |
select Sound chan2 |
| 65 |
chan2.Pitch = To Pitch... 0.01 75 600 |
| 66 |
assert objectsAreIdentical (chan2.Pitch, chan1.Pitch) |
| 67 |
|
| 68 |
select Sound sum |
| 69 |
sum.Pitch = To Pitch... 0.01 75 600 |
| 70 |
assert objectsAreIdentical (sum.Pitch, chan1.Pitch) |
| 71 |
|
| 72 |
select Sound difference |
| 73 |
difference.Pitch = To Pitch... 0.01 75 600 |
| 74 |
assert objectsAreIdentical (difference.Pitch, chan1.Pitch) |
| 75 |
|
| 76 |
select Sound average |
| 77 |
average.Pitch = To Pitch... 0.01 75 600 |
| 78 |
assert objectsAreIdentical (average.Pitch, chan1.Pitch) |
| 79 |
|
| 80 |
select Pitch chan1 |
| 81 |
plus Pitch chan2 |
| 82 |
plus Pitch sum |
| 83 |
plus Pitch difference |
| 84 |
plus Pitch average |
| 85 |
Remove |
| 86 |
|
| 87 |
# |
| 88 |
# SPECTROGRAM ANALYSIS |
| 89 |
# |
| 90 |
# The spectrogram analysis should give the exact same result for the two channels, |
| 91 |
# because averaging is done at the level of the power spectral density. |
| 92 |
# |
| 93 |
# Also, the sum and difference sounds should give the exact same results as each other, |
| 94 |
# because averaging is done after squaring. |
| 95 |
# |
| 96 |
|
| 97 |
select Sound chan1 |
| 98 |
chan1.Spectrogram = To Spectrogram... 0.005 5000 0.002 20 Gaussian |
| 99 |
|
| 100 |
select Sound chan2 |
| 101 |
chan2.Spectrogram = To Spectrogram... 0.005 5000 0.002 20 Gaussian |
| 102 |
assert objectsAreIdentical (chan2.Spectrogram, chan1.Spectrogram) |
| 103 |
|
| 104 |
select Sound sum |
| 105 |
sum.Spectrogram = To Spectrogram... 0.005 5000 0.002 20 Gaussian |
| 106 |
assert not objectsAreIdentical (sum.Spectrogram, chan1.Spectrogram) ; more power |
| 107 |
|
| 108 |
select Sound difference |
| 109 |
difference.Spectrogram = To Spectrogram... 0.005 5000 0.002 20 Gaussian |
| 110 |
assert objectsAreIdentical (difference.Spectrogram, sum.Spectrogram) |
| 111 |
|
| 112 |
select Spectrogram sum |
| 113 |
Formula... 0.5 * self |
| 114 |
assert objectsAreIdentical (sum.Spectrogram, chan1.Spectrogram) ; halved square |
| 115 |
|
| 116 |
select Sound average |
| 117 |
average.Spectrogram = To Spectrogram... 0.005 5000 0.002 20 Gaussian |
| 118 |
assert not objectsAreIdentical (average.Spectrogram, chan1.Spectrogram) |
| 119 |
Formula... 2.0 * self |
| 120 |
assert objectsAreIdentical (average.Spectrogram, chan1.Spectrogram) ; doubled square |
| 121 |
|
| 122 |
select Spectrogram chan1 |
| 123 |
plus Spectrogram chan2 |
| 124 |
plus Spectrogram sum |
| 125 |
plus Spectrogram difference |
| 126 |
plus Spectrogram average |
| 127 |
Remove |
| 128 |
|
| 129 |
# |
| 130 |
# FORMANT ANALYSIS |
| 131 |
# |
| 132 |
# The formant analysis should give the exact same result for the two channels, |
| 133 |
# because the two channels are averaged before the LPC analysis is performed. |
| 134 |
# |
| 135 |
|
| 136 |
select Sound chan1 |
| 137 |
chan1.Formant = To Formant (burg)... 0.01 5 5500 0.025 50.0 |
| 138 |
|
| 139 |
select Sound chan2 |
| 140 |
chan2.Formant = To Formant (burg)... 0.01 5 5500 0.025 50.0 |
| 141 |
assert objectsAreIdentical (chan2.Formant, chan1.Formant) |
| 142 |
|
| 143 |
select Formant chan1 |
| 144 |
plus Formant chan2 |
| 145 |
Remove |
| 146 |
|
| 147 |
# |
| 148 |
# LPC ANALYSIS |
| 149 |
# |
| 150 |
# The LPC analysis should give the exact same result for the two channels, |
| 151 |
# because the two channels are averaged before the LPC analysis is performed. |
| 152 |
# |
| 153 |
# Before October 2025, the LPC algorithms took only channel 1 into account. |
| 154 |
# |
| 155 |
|
| 156 |
select Sound chan1 |
| 157 |
chan1.LPC = To LPC (burg)... 16 0.025 0.005 50.0 |
| 158 |
|
| 159 |
select Sound chan2 |
| 160 |
chan2.LPC = To LPC (burg)... 16 0.025 0.005 50.0 |
| 161 |
if praatVersion >= 6447 |
| 162 |
assert objectsAreIdentical (chan2.LPC, chan1.LPC) ; correct since October 2025 |
| 163 |
else |
| 164 |
assert not objectsAreIdentical (chan2.LPC, chan1.LPC) ; bug from 2009 to 2025 |
| 165 |
endif |
| 166 |
|
| 167 |
select LPC chan1 |
| 168 |
plus LPC chan2 |
| 169 |
Remove |
| 170 |
|
| 171 |
select Sound chan1 |
| 172 |
chan1.LPC = To LPC (autocorrelation)... 16 0.025 0.005 50.0 |
| 173 |
|
| 174 |
select Sound chan2 |
| 175 |
chan2.LPC = To LPC (autocorrelation)... 16 0.025 0.005 50.0 |
| 176 |
if praatVersion >= 6447 |
| 177 |
assert objectsAreIdentical (chan2.LPC, chan1.LPC) ; correct since October 2025 |
| 178 |
else |
| 179 |
assert not objectsAreIdentical (chan2.LPC, chan1.LPC) ; bug from 2009 to 2025 |
| 180 |
endif |
| 181 |
|
| 182 |
select LPC chan1 |
| 183 |
plus LPC chan2 |
| 184 |
Remove |
| 185 |
|
| 186 |
# |
| 187 |
# CEPSTROGRAM ANALYSIS |
| 188 |
# |
| 189 |
# The cepstrogram analysis should give the exact same result for the two channels, |
| 190 |
# because averaging is done at the level of the power spectral density. |
| 191 |
# |
| 192 |
# Also, the sum and difference sounds should give the exact same results as each other, |
| 193 |
# because averaging is done after squaring. |
| 194 |
# |
| 195 |
# Before December 2025, the algorithm took only channel 1 into account. |
| 196 |
# |
| 197 |
|
| 198 |
if praatVersion >= 5353 ; PowerCepstrogram available since July 2013 |
| 199 |
select Sound chan1 |
| 200 |
chan1.PowerCepstrogram = To PowerCepstrogram... 60.0 0.002 5000.0 50.0 |
| 201 |
|
| 202 |
select Sound chan2 |
| 203 |
chan2.PowerCepstrogram = To PowerCepstrogram... 60.0 0.002 5000.0 50.0 |
| 204 |
if praatVersion >= 6452 |
| 205 |
assert objectsAreIdentical (chan2.PowerCepstrogram, chan1.PowerCepstrogram) ; when will this happen? |
| 206 |
else |
| 207 |
assert not objectsAreIdentical (chan2.PowerCepstrogram, chan1.PowerCepstrogram) ; bug |
| 208 |
endif |
| 209 |
|
| 210 |
select Sound sum |
| 211 |
sum.PowerCepstrogram = To PowerCepstrogram... 60.0 0.002 5000.0 50.0 |
| 212 |
if praatVersion >= 6452 |
| 213 |
assert not objectsAreIdentical (sum.PowerCepstrogram, chan1.PowerCepstrogram) ; more power |
| 214 |
else |
| 215 |
assert objectsAreIdentical (sum.PowerCepstrogram, chan1.PowerCepstrogram) ; bug (only channel 1) |
| 216 |
endif |
| 217 |
|
| 218 |
select Sound difference |
| 219 |
difference.PowerCepstrogram = To PowerCepstrogram... 60.0 0.002 5000.0 50.0 |
| 220 |
assert objectsAreIdentical (difference.PowerCepstrogram, sum.PowerCepstrogram) |
| 221 |
|
| 222 |
select PowerCepstrogram sum |
| 223 |
Formula... 0.5 * self |
| 224 |
assert not objectsAreIdentical (sum.PowerCepstrogram, chan1.PowerCepstrogram) |
| 225 |
|
| 226 |
select Sound average |
| 227 |
average.PowerCepstrogram = To PowerCepstrogram... 60.0 0.002 5000.0 50.0 |
| 228 |
assert not objectsAreIdentical (average.PowerCepstrogram, chan1.PowerCepstrogram) |
| 229 |
Formula... 2.0 * self |
| 230 |
assert not objectsAreIdentical (average.PowerCepstrogram, chan1.PowerCepstrogram) |
| 231 |
|
| 232 |
select PowerCepstrogram chan1 |
| 233 |
plus PowerCepstrogram chan2 |
| 234 |
plus PowerCepstrogram sum |
| 235 |
plus PowerCepstrogram difference |
| 236 |
plus PowerCepstrogram average |
| 237 |
Remove |
| 238 |
endif |
| 239 |
|
| 240 |
# |
| 241 |
# CLEAN UP |
| 242 |
# |
| 243 |
|
| 244 |
select Sound chan1 |
| 245 |
plus Sound chan2 |
| 246 |
plus Sound sum |
| 247 |
plus Sound difference |
| 248 |
plus Sound average |
| 249 |
Remove |