| 1 |
/* manual_sound.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1992-2008,2010-2012,2014-2025 Paul Boersma |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
* See the GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "ManPagesM.h" |
| 20 |
|
| 21 |
#include "Sound.h" |
| 22 |
#include "../kar/UnicodeData.h" |
| 23 |
|
| 24 |
void manual_sound_init (ManPages me); |
| 25 |
void manual_sound_init (ManPages me) { |
| 26 |
|
| 27 |
MAN_PAGES_BEGIN |
| 28 |
R"~~~( |
| 29 |
################################################################################ |
| 30 |
"Sounds: Combine to stereo" |
| 31 |
© Paul Boersma 2007,2008,2012,2023 |
| 32 |
|
| 33 |
To combine two (or more) mono @Sound objects into one single stereo (i.e. multi-channel) Sound, |
| 34 |
select those Sounds in the list and choose ##Combine to stereo# from the #Combine menu. |
| 35 |
A new stereo Sound will appear in the list. |
| 36 |
|
| 37 |
Of the two original mono Sounds, the one that is higher in the list will become the left channel |
| 38 |
of the new stereo Sound, and the one that is lower in the list will become the right channel of the new Sound. |
| 39 |
|
| 40 |
You can also create Sounds with e.g. 3 or 5 or 100 channels in this way. The topmost selected mono Sound |
| 41 |
will become channel 1, and the bottommost selected mono Sound will become the last channel. |
| 42 |
|
| 43 |
################################################################################ |
| 44 |
"Create Sound as pure tone..." |
| 45 |
© Paul Boersma 2023 |
| 46 |
|
| 47 |
A command in the #Sound submenu of the @@New menu@, to create a sine wave. |
| 48 |
|
| 49 |
A new Sound object will appear in the list, |
| 50 |
with the specified sine frequency and the specified amplitude. |
| 51 |
You can also specify the number of channels, the start and end times, and the sampling frequency. |
| 52 |
In order to prevent hearing clicks at the beginning and end, |
| 53 |
you can specify a fade-in duration and a fade-out duration. |
| 54 |
|
| 55 |
################################################################################ |
| 56 |
"Create Sound from formula..." |
| 57 |
© Paul Boersma 2007-02-25 |
| 58 |
|
| 59 |
A command in the @@New menu@ to create a @Sound with a specified duration and sampling frequency, |
| 60 |
filled with values from a formula. |
| 61 |
|
| 62 |
See the @Formulas tutorial for explanations and examples. |
| 63 |
{-; |
| 64 |
Create Sound from formula... blok Mono 0 1 44100 if round(x*377*2) mod 2 then 0.9 else -0.9 fi |
| 65 |
|
| 66 |
Je kunt dus heel veel maken met een scriptje: |
| 67 |
|
| 68 |
form Blokgolf |
| 69 |
word Naam blok |
| 70 |
real Begintijd_(s) 0.0 |
| 71 |
real Eindtijd_(s) 1.0 |
| 72 |
positive Samplefrequentie_(Hz) 22050 |
| 73 |
positive Frequentie_(Hz) 377 |
| 74 |
real Amplitude 0.9 |
| 75 |
endform |
| 76 |
Create Sound from formula... 'Naam' Mono begintijd eindtijd samplefrequentie |
| 77 |
... if round(x*frequentie*2) mod 2 then amplitude else -amplitude fi |
| 78 |
} |
| 79 |
|
| 80 |
################################################################################ |
| 81 |
"Create Sound as tone complex..." |
| 82 |
© Paul Boersma 2022-01-22 |
| 83 |
|
| 84 |
A command in the @@New menu@ to create a @Sound as the sum of a number of sine waves |
| 85 |
with equidistant frequencies. |
| 86 |
|
| 87 |
Settings |
| 88 |
======== |
| 89 |
|
| 90 |
##Name |
| 91 |
: the name of the resulting Sound object. |
| 92 |
|
| 93 |
##Start time (s) |
| 94 |
|
| 95 |
##End time (s) |
| 96 |
: the time domain of the resulting Sound. |
| 97 |
|
| 98 |
##Sampling frequency (Hz) |
| 99 |
: the sampling frequency of the resulting Sound. |
| 100 |
|
| 101 |
##Phase |
| 102 |
: determines whether the result is a sum of %sines or a sum of %cosines, |
| 103 |
i.e., whether the zero crossings or the maxima of the components are synchronized. |
| 104 |
This choice has little perceptual consequences. |
| 105 |
|
| 106 |
##Frequency step (Hz) |
| 107 |
: the distance between the components. In first approximation, |
| 108 |
this is the perceived fundamental frequency. |
| 109 |
|
| 110 |
##First frequency (Hz) |
| 111 |
: the lowest frequency component. If you supply a value of 0, |
| 112 |
##First frequency# is taken equal to ##Frequency step#. |
| 113 |
|
| 114 |
##Ceiling (Hz) |
| 115 |
: the frequency above which no components are used. If you supply a value of 0 |
| 116 |
or a value above the Sound's @@Nyquist frequency@, %ceiling is taken equal to |
| 117 |
the Nyquist frequency. |
| 118 |
|
| 119 |
##Number of components |
| 120 |
: determines how many sinusoids are used. If you supply a value of 0 |
| 121 |
or a very high value, the maximum number of components is used, |
| 122 |
limited by #Ceiling. |
| 123 |
|
| 124 |
Example 1: a pulse train |
| 125 |
======================== |
| 126 |
|
| 127 |
A series of pulses at regular intervals, |
| 128 |
sampled after low-pass filtering at the Nyquist frequency, |
| 129 |
can be regarded as a sum of cosine waves. For instance, a 100-Hz pulse train, |
| 130 |
sampled at 44100 Hz, can be created with: |
| 131 |
{; |
| 132 |
Create Sound as tone complex: "train", 0, 1, 44100, "cosine", 100, 0, 0, 0 |
| 133 |
} |
| 134 |
Supplying the value 0 for %firstFrequency yields an unshifted harmonic complex. |
| 135 |
|
| 136 |
Example 2: a shifted harmonic complex |
| 137 |
===================================== |
| 138 |
|
| 139 |
Some experiments on human pitch perception (%%residue pitch%) use |
| 140 |
a number of sinusoidal components with harmonically |
| 141 |
related frequencies that are all shifted by a constant amount. |
| 142 |
|
| 143 |
For instance, to get a sum of sine waves with frequencies 105 Hz, 205 Hz, and 305 Hz, |
| 144 |
you would use: |
| 145 |
{; |
| 146 |
Create Sound as tone complex: "train", 0.3, 1, 44100, "sine", 100, 105, 0, 3 |
| 147 |
} |
| 148 |
or |
| 149 |
{; |
| 150 |
Create Sound as tone complex: "train", 0.3, 1, 44100, "sine", 100, 105, 350, 0 |
| 151 |
} |
| 152 |
whichever you prefer. |
| 153 |
|
| 154 |
Some of these experiments are described in @@Plomp (1967)@ and @@Patterson & Wightman (1976)@. |
| 155 |
|
| 156 |
Algorithm |
| 157 |
========= |
| 158 |
|
| 159 |
For the “sine” phase, the resulting Sound is given by the following formula: |
| 160 |
|
| 161 |
~ %x(%t) = \su__%i=1..%numberOfComponents_ sin (2%\pi·(%firstFrequency + (%i−1)·%frequencyStep)·%t) |
| 162 |
|
| 163 |
More flexibility? |
| 164 |
================= |
| 165 |
|
| 166 |
Suppose you wanted to vary the relative strengths of the frequency components. |
| 167 |
You could achieve this by creating a Sound with the command discussed here, |
| 168 |
take its Fourier transform, run a formula on the resulting Spectrum, |
| 169 |
and take the inverse Fourier transform. |
| 170 |
|
| 171 |
A more general approach is described shortly. |
| 172 |
|
| 173 |
Suppose you need a sum of sine waves with frequencies 105, 205, 305, ..., 1905 Hz, |
| 174 |
and with relative amplitudes 1, 1/2, 1/3, ..., 1/19. You could build a script that computes |
| 175 |
the various components, and add them to each other as you go along. Instead of calling 19 |
| 176 |
scripts, however, you can achieve this with the following more general script: |
| 177 |
{; |
| 178 |
form: "Add waves with decreasing amplitudes" |
| 179 |
natural: "Number of components", "19" |
| 180 |
endform |
| 181 |
# Create a Matrix with frequency and amplitude information in each row: |
| 182 |
Create simple Matrix: "freqAndGain", number_of_components, 2, ~ 0 |
| 183 |
Formula: ~ if col = 1 then row * 100 + 5 else 1 / row fi |
| 184 |
# Create a large Matrix with all the component sine waves: |
| 185 |
Create Matrix: "components", 0, 1, 10000, 1e-4, 0.5e-4, 1, number_of_components, number_of_components, 1, 1, ~ 0 |
| 186 |
Formula: ~ object ["Matrix freqAndGain", 2] * sin (2 * pi * object ["Matrix freqAndGain", 1] * x) |
| 187 |
# Integrate: |
| 188 |
Formula: ~ self + self [row - 1, col] |
| 189 |
# Publish last row: |
| 190 |
To Sound (slice): number_of_components |
| 191 |
Scale amplitudes: 0.99 |
| 192 |
} |
| 193 |
|
| 194 |
################################################################################ |
| 195 |
"Extract one channel..." |
| 196 |
© Paul Boersma 2011-01-29 |
| 197 |
|
| 198 |
To extract the left channel of an existing stereo @Sound as a new mono Sound, |
| 199 |
select that stereo Sound in the list and choose ##Extract one channel...# from the #Convert menu, |
| 200 |
Then set the #Channel to 1 and click OK. |
| 201 |
A new mono Sound will appear in the list. For the right channel, set #Channel to 2. |
| 202 |
|
| 203 |
Details |
| 204 |
======= |
| 205 |
|
| 206 |
The name of the new mono Sound will be based on the name of the original stereo Sound. |
| 207 |
For instance, if the original Sound is called `hello` and you extract channel 2, the new Sound will be called `hello_ch2`. |
| 208 |
|
| 209 |
This command also works if you select more than one stereo Sound. |
| 210 |
For each of them, Praat creates a new mono Sound. |
| 211 |
|
| 212 |
################################################################################ |
| 213 |
"Read separate channels from sound file..." |
| 214 |
© Paul Boersma 2011-10-10 |
| 215 |
|
| 216 |
A command in the @@Open menu@ of the #Objects window. |
| 217 |
You use this if you want to get the channels of a @stereo (or multi-channel) sound file |
| 218 |
as two (or more) separate @Sound objects in the list. |
| 219 |
If the file name is `hello.wav`, Praat will name the channels `hello_ch1`, `hello_ch2`, and so on. |
| 220 |
|
| 221 |
################################################################################ |
| 222 |
"Record mono Sound..." |
| 223 |
© Paul Boersma 2020-11-20 |
| 224 |
|
| 225 |
A command in the @@New menu@ to record a @Sound. Creates a @SoundRecorder window. |
| 226 |
|
| 227 |
################################################################################ |
| 228 |
"Record stereo Sound..." |
| 229 |
© Paul Boersma 2002-12-12 |
| 230 |
|
| 231 |
A command in the @@New menu@ to record a @Sound. Creates a @SoundRecorder window. |
| 232 |
|
| 233 |
################################################################################ |
| 234 |
"Record Sound (fixed time)..." |
| 235 |
© Paul Boersma 2002-12-12 |
| 236 |
|
| 237 |
A usually hidden command in the @@New menu@ to record a @Sound. |
| 238 |
|
| 239 |
################################################################################ |
| 240 |
"Sound" |
| 241 |
© Paul Boersma 2016-10-13 |
| 242 |
|
| 243 |
One of the @@types of objects@ in Praat. For tutorial information, see all of the @Intro. |
| 244 |
|
| 245 |
Commands |
| 246 |
======== |
| 247 |
|
| 248 |
Creation: |
| 249 |
- @@Record mono Sound...@ (from microphone or line input, with the @SoundRecorder) |
| 250 |
- @@Record stereo Sound...@ |
| 251 |
- @@Create Sound from formula...@ |
| 252 |
- @@Create Sound as tone complex... |
| 253 |
- @@Create Sound as gammatone... |
| 254 |
- @@Create Sound as Shepard tone... |
| 255 |
|
| 256 |
Opening and saving: |
| 257 |
- @@Sound files |
| 258 |
|
| 259 |
You can also use the text and binary (real-valued) formats for Sounds, like for any other class: |
| 260 |
- @@Save as text file... |
| 261 |
- @@Save as binary file... |
| 262 |
|
| 263 |
Viewing and editing: |
| 264 |
- @SoundEditor, @ManipulationEditor, @TextGridEditor, @PointEditor, @PitchTierEditor, @SpectrumEditor |
| 265 |
|
| 266 |
Playing: |
| 267 |
- @@Sound: Play |
| 268 |
- @@PointProcess: Hum |
| 269 |
- @@PointProcess: Play |
| 270 |
|
| 271 |
Drawing: |
| 272 |
- @@Sound: Draw... |
| 273 |
- @@Sound: Draw where... |
| 274 |
- @@Sound: Paint where... |
| 275 |
- @@Sounds: Paint enclosed... |
| 276 |
|
| 277 |
Queries: |
| 278 |
, structure: |
| 279 |
- @@time domain |
| 280 |
- @@Get number of samples |
| 281 |
- @@Get sampling period |
| 282 |
- @@Get sampling frequency |
| 283 |
- @@Get time from sample number... |
| 284 |
- @@Get sample number from time... |
| 285 |
, content: |
| 286 |
- @@Sound: Get value at time... |
| 287 |
- @@Sound: Get value at sample number... |
| 288 |
, shape: |
| 289 |
- @@Sound: Get minimum... |
| 290 |
- @@Sound: Get time of minimum... |
| 291 |
- @@Sound: Get maximum... |
| 292 |
- @@Sound: Get time of maximum... |
| 293 |
- @@Sound: Get absolute extremum... |
| 294 |
- @@Sound: Get nearest zero crossing... |
| 295 |
, statistics: |
| 296 |
- @@Sound: Get mean... |
| 297 |
- @@Sound: Get root-mean-square... |
| 298 |
- @@Sound: Get standard deviation... |
| 299 |
, energy: |
| 300 |
- @@Sound: Get energy... |
| 301 |
- @@Sound: Get power... |
| 302 |
, in air: |
| 303 |
- @@Sound: Get energy in air |
| 304 |
- @@Sound: Get power in air |
| 305 |
- @@Sound: Get intensity (dB) |
| 306 |
|
| 307 |
Modification: |
| 308 |
- @@Matrix: Formula... |
| 309 |
- @@Sound: Set value at sample number... |
| 310 |
- @@Sound: Filter with one formant (in-place)... |
| 311 |
- @@Sound: Pre-emphasize (in-place)... |
| 312 |
- @@Sound: De-emphasize (in-place)... |
| 313 |
|
| 314 |
Annotation (see @@Intro 7. Annotation@): |
| 315 |
- @@Sound: To TextGrid... |
| 316 |
|
| 317 |
Periodicity analysis: |
| 318 |
- @@Sound: To Pitch (filtered autocorrelation)... |
| 319 |
- @@Sound: To Pitch (raw cross-correlation)... |
| 320 |
- @@Sound: To Pitch (raw autocorrelation)... |
| 321 |
- @@Sound: To Pitch (filtered cross-correlation)... |
| 322 |
- @@Sound: To Pitch (shs)... |
| 323 |
- @@Sound: To Harmonicity (ac)... |
| 324 |
- @@Sound: To Harmonicity (cc)... |
| 325 |
- @@Sound: To PointProcess (periodic, cc)... |
| 326 |
- @@Sound: To PointProcess (periodic, peaks)... |
| 327 |
- @@Sound & Pitch: To PointProcess (cc) |
| 328 |
- @@Sound & Pitch: To PointProcess (peaks)... |
| 329 |
- @@Sound: To Intensity... |
| 330 |
|
| 331 |
Spectral analysis: |
| 332 |
- @@Sound: To Spectrum... |
| 333 |
- @@Sound: To Spectrogram... |
| 334 |
- @@Sound: To Formant (burg)... |
| 335 |
- @@Sound: To Formant (sl)... |
| 336 |
- @@Sound: LPC analysis |
| 337 |
- @@Sound: To LPC (autocorrelation)... |
| 338 |
- @@Sound: To LPC (covariance)... |
| 339 |
- @@Sound: To LPC (burg)... |
| 340 |
- @@Sound: To LPC (marple)... |
| 341 |
|
| 342 |
Filtering (see @Filtering tutorial): |
| 343 |
- @@Sound: Filter (pass Hann band)... |
| 344 |
- @@Sound: Filter (stop Hann band)... |
| 345 |
- @@Sound: Filter (formula)... |
| 346 |
- @@Sound: Filter (one formant)... |
| 347 |
- @@Sound: Filter (pre-emphasis)... |
| 348 |
- @@Sound: Filter (de-emphasis)... |
| 349 |
- @@LPC & Sound: Filter... |
| 350 |
- @@LPC & Sound: Filter (inverse) |
| 351 |
- @@Sound & Formant: Filter |
| 352 |
- @@Sound & FormantGrid: Filter |
| 353 |
|
| 354 |
Conversion: |
| 355 |
- @@Sound: Resample... |
| 356 |
|
| 357 |
Enhancement: |
| 358 |
- @@Sound: Lengthen (overlap-add)...@: lengthen by a constant factor |
| 359 |
- @@Sound: Deepen band modulation...@: strenghten intensity modulations in each critical band |
| 360 |
|
| 361 |
Combination: |
| 362 |
- @@Sounds: Convolve... |
| 363 |
- @@Sounds: Cross-correlate... |
| 364 |
- @@Sound: Autocorrelate... |
| 365 |
- @@Sounds: Concatenate |
| 366 |
|
| 367 |
Synthesis |
| 368 |
- @@Source-filter synthesis@ tutorial |
| 369 |
- @Manipulation (@@overlap-add@ etc.) |
| 370 |
- @@Spectrum: To Sound |
| 371 |
- ##Pitch: To Sound... |
| 372 |
- @@PointProcess: To Sound (pulse train)... |
| 373 |
- @@PointProcess: To Sound (hum)... |
| 374 |
- ##Pitch & PointProcess: To Sound... |
| 375 |
- @@Articulatory synthesis@ tutorial |
| 376 |
- @@Artword & Speaker: To Sound... |
| 377 |
|
| 378 |
Inside a Sound |
| 379 |
============== |
| 380 |
|
| 381 |
With @Inspect, you will see that a Sound contains the following data: |
| 382 |
|
| 383 |
%x__%min_ |
| 384 |
: start time, in seconds. |
| 385 |
|
| 386 |
%x__%max_ > %x__%min_ |
| 387 |
: end time, in seconds. |
| 388 |
|
| 389 |
%n_%x |
| 390 |
: the number of samples (\\>_ 1). |
| 391 |
|
| 392 |
%dx |
| 393 |
: sample period, in seconds. The inverse of the sampling frequency (in Hz). |
| 394 |
|
| 395 |
%x_1 |
| 396 |
: the time associated with the first sample (in seconds). |
| 397 |
This will normally be in the range [%xmin, %xmax]. |
| 398 |
The time associated with the last sample (i.e., %x_1 + (%nx \-m 1) %dx)) |
| 399 |
will also normally be in that range. Mostly, the sound starts at %t = 0 seconds |
| 400 |
and %x_1 = %dx / 2. Also, usually, %x__%max_ = %n_%x %dx. |
| 401 |
|
| 402 |
%z [1] [1..%n_%x] |
| 403 |
: the amplitude of the sound (stored as single-precision floating-point numbers). |
| 404 |
For the most common applications (playing and file I-O), Praat assumes that |
| 405 |
the amplitude is greater than -1 and less than +1. |
| 406 |
For some applications (modelling of the inner ear; |
| 407 |
articulatory synthesis), Praat assumes that the amplitude is expressed in Pascal units. |
| 408 |
If these interpretations are combined, we see that the maximum peak amplitude of |
| 409 |
a calibrated sound is 1 Pascal; for a sine wave, this means 91 dB SPL. |
| 410 |
|
| 411 |
Limitations |
| 412 |
=========== |
| 413 |
|
| 414 |
Since the Sound object completely resides in memory, its size is limited |
| 415 |
to the amount of RAM in your computer. For sounds longer than a few minutes, |
| 416 |
you could use the @LongSound object instead, which you can view in the @LongSoundEditor. |
| 417 |
|
| 418 |
################################################################################ |
| 419 |
"Sound: De-emphasize (in-place)..." |
| 420 |
© Paul Boersma 2017-11-14 |
| 421 |
|
| 422 |
A command to change the spectral slope of every selected @Sound object. |
| 423 |
|
| 424 |
The reverse of @@Sound: Pre-emphasize (in-place)...@. For an example, see @@Source-filter synthesis@. |
| 425 |
|
| 426 |
This is the in-place version of @@Sound: Filter (de-emphasis)...@, |
| 427 |
i.e., it does not create a new Sound object but modifies an existing object. |
| 428 |
|
| 429 |
Setting |
| 430 |
======= |
| 431 |
|
| 432 |
##From frequency (Hz) |
| 433 |
: the frequency %F above which the spectral slope will decrease by 6 dB/octave. |
| 434 |
|
| 435 |
Algorithm |
| 436 |
========= |
| 437 |
|
| 438 |
The de-emphasis factor %\\al is computed as |
| 439 |
~ %\al = exp (-2 %\pi %F %\Det) |
| 440 |
|
| 441 |
where %\Det is the sampling period of the sound. Every sample %x_%i of the sound, |
| 442 |
except %x_1, is then changed, going up from the second sample: |
| 443 |
~ %x_%i = %x_%i + %\al %x__%i−1_ |
| 444 |
|
| 445 |
################################################################################ |
| 446 |
"Sound: Deepen band modulation..." |
| 447 |
© Paul Boersma 2010-10-26 |
| 448 |
|
| 449 |
A command to enhance the fast spectral changes, like %F_2 movements, in each selected @Sound object. |
| 450 |
|
| 451 |
Settings |
| 452 |
======== |
| 453 |
|
| 454 |
##Enhancement (dB) |
| 455 |
: the maximum increase in the level within each critical band. The standard value is 20 dB. |
| 456 |
|
| 457 |
##From frequency (Hz) |
| 458 |
: the lowest frequency that shall be manipulated. The bottom frequency of the first critical band that is to be enhanced. |
| 459 |
The standard value is 300 Hertz. |
| 460 |
|
| 461 |
##To frequency (Hz) |
| 462 |
: the highest frequency that shall be manipulated (the last critical band may be narrower than the others). The standard value is 8000 Hz. |
| 463 |
|
| 464 |
##Slow modulation (Hz) |
| 465 |
: the frequency %f__%slow_ below which the intensity modulations in the bands should not be expanded. The standard value is 3 Hz. |
| 466 |
|
| 467 |
##Fast modulation (Hz) |
| 468 |
: the frequency %f__%fast_ above which the intensity modulations in the bands should not be expanded. The standard value is 30 Hz. |
| 469 |
|
| 470 |
##Band smoothing (Hz) |
| 471 |
: the degree of overlap of each band into its adjacent bands. Prevents %ringing. The standard value is 100 Hz. |
| 472 |
|
| 473 |
Algorithm |
| 474 |
========= |
| 475 |
|
| 476 |
This algorithm was inspired by @@Nagarajan, Wang, Merzenich, Schreiner, Johnston, Jenkins, Miller & Tallal (1998)@, |
| 477 |
but not identical to it. Now follows the description. |
| 478 |
|
| 479 |
Suppose the settings have their standard values. The resulting sound will composed of the unfiltered part of the original sound, |
| 480 |
plus all manipulated bands. |
| 481 |
|
| 482 |
First, the resulting sound becomes the original sound, stop-band filtered between 300 and 8000 Hz: |
| 483 |
after a forward Fourier transform, all values in the @Spectrum at frequencies between 0 and 200 Hz and |
| 484 |
between 8100 Hz and the Nyquist frequency of the sound are retained unchanged. |
| 485 |
The spectral values at frequencies between 400 and 7900 Hz are set to zero. |
| 486 |
Between 200 and 400 Hz and between 7900 and 8100 Hz, the values are multiplied by a raised sine, |
| 487 |
so as to give a smooth transition without ringing in the time domain (the raised sine also allows us to view |
| 488 |
the spectrum as a sum of spectral bands). Finally, a backward Fourier transform gives us the filtered sound. |
| 489 |
|
| 490 |
The remaining part of the spectrum is divided into %%critical bands%, i.e. frequency bands one Bark wide. |
| 491 |
For instance, the first critical band run from 300 to 406 Hz, the second from 406 to 520 Hz, and so on. |
| 492 |
Each critical band is converted to a pass-band filtered sound by means of the backward Fourier transform. |
| 493 |
|
| 494 |
Each filtered sound will be manipulated, and the resulting manipulated sounds are added to the stop-band filtered sound |
| 495 |
we created earlier. If the manipulation is the identity transformation, the resulting sound will be equal to the original sound. |
| 496 |
But, of course, the manipulation does something different. Here are the steps. |
| 497 |
|
| 498 |
First, we compute the local intensity of the filtered sound %x (%t): |
| 499 |
~ %intensity (%t) = 10 log__10_ (%x^2 (%t) + 10^^-6^) |
| 500 |
|
| 501 |
This intensity is subjected to a forward Fourier transform. In the frequency domain, we administer a band filter. |
| 502 |
We want to enhance the intensity modulation in the range between 3 and 30 Hz. |
| 503 |
We can achieve this by comparing the very smooth intensity contour, low-pass filtered at %f__%slow_ = 3 Hz, |
| 504 |
with the intensity contour that has enough temporal resolution to see the place-discriminating %F_2 movements, |
| 505 |
which is low-pass filtered at %f__%fast_ = 30 Hz. In the frequency domain, the filter is |
| 506 |
~ %H (%f) = exp (- (%\al%f / %f__%fast_)^2) - exp (- (%\al%f / %f__%slow_)^2) |
| 507 |
|
| 508 |
where %\al equals \Vrln 2 \~~ 1 / 1.2011224, so that %H (%f) has its -6 dB points at %f__%slow_ and %f__%fast_: |
| 509 |
{ 5x3 |
| 510 |
alpha = sqrt (ln (2)) |
| 511 |
filter = Create Sound from formula: "filter", 1, 0.0, 100.0, 10.0, |
| 512 |
... ~ exp (- (alpha * x / 30.0) ^ 2) - exp (- (alpha * x / 3.0) ^ 2) |
| 513 |
Red |
| 514 |
Draw: 0, 0, 0.0, 1.0, "no", "curve" |
| 515 |
Black |
| 516 |
Draw inner box |
| 517 |
Text bottom: "yes", "Frequency %f (Hz)" |
| 518 |
Text left: "yes", "Amplitude filter %H (%f)" |
| 519 |
One mark left: 0.0, "yes", "yes", "no", "" |
| 520 |
One mark left: 0.5, "yes", "yes", "yes", "" |
| 521 |
One mark left: 1.0, "yes", "yes", "no", "" |
| 522 |
One mark right: 1.0, "no", "yes", "no", "0 dB" |
| 523 |
One mark right: 0.5, "no", "yes", "no", "\-m6 dB" |
| 524 |
One mark bottom: 3.0, "yes", "yes", "yes", "" |
| 525 |
One mark bottom: 30.0, "yes", "yes", "yes", "" |
| 526 |
} |
| 527 |
|
| 528 |
Now, why do we use such a flat filter? Because a steep filter would show ringing effects in the time domain, |
| 529 |
dividing the sound into 30-ms chunks. If our filter is a sum of exponentials in the frequency domain, it will also |
| 530 |
be a sum of exponentials in the time domain. The backward Fourier transform of the frequency response %H (%f) |
| 531 |
is the impulse response %h (%t). It is given by |
| 532 |
~ %h (%t) = 2%\pi\Vr%\pi %f__%fast_/%\al exp (-(%\pi%t%f__%fast_/%\al)^2) - |
| 533 |
2%\pi\Vr%\pi %f__%slow_/%\\al exp (-(%\pi%t%f__%slow_/%\al)^2) |
| 534 |
|
| 535 |
This impulse response behaves well: |
| 536 |
{ 5x3 |
| 537 |
impulseResponse = Create Sound from formula: "impulseResponse", 1, |
| 538 |
... -0.2, 0.2, 2500, ~ 2 * pi * sqrt (pi) / alpha * |
| 539 |
... (30.0 * exp (- (pi * 30.0 / alpha * x) ^ 2) - |
| 540 |
... 3.0 * exp (- (pi * 3.0 / alpha * x) ^ 2)) |
| 541 |
Red |
| 542 |
Draw: 0, 0, -100.0, 400.0, "no", "curve" |
| 543 |
Black |
| 544 |
Draw inner box |
| 545 |
Text bottom: "yes", "Time %t (s)" |
| 546 |
Text left: "yes", "Intensity impulse response %h (%t)" |
| 547 |
One mark bottom: -0.2, "yes", "yes", "no", "" |
| 548 |
One mark bottom: 0.0, "yes", "yes", "yes", "" |
| 549 |
One mark bottom: 0.2, "yes", "yes", "no", "" |
| 550 |
One mark left: 0.0, "yes", "yes", "yes", "" |
| 551 |
} |
| 552 |
|
| 553 |
We see that any short intensity peak will be enhanced, and that this enhancement will suppress the intensity |
| 554 |
around 30 milliseconds from the peak. Non-Gaussian frequency-domain filters would have given several maxima and minima |
| 555 |
in the impulse response, clearly an undesirable phenomenon. |
| 556 |
|
| 557 |
After the filtered band is subjected to a backward Fourier transform, we convert it into power again: |
| 558 |
~ %power (%t) = 10^^%filtered / 2^ |
| 559 |
|
| 560 |
The relative enhancement has a maximum that is smoothly related to the basilar place: |
| 561 |
~ %ceiling = 1 + (10^^%enhancement / 20^ - 1) \\.c (1/2 - 1/2 cos (%\pi %f__%midbark_ / 13)) |
| 562 |
|
| 563 |
where %f__%midbark_ is the mid frequency of the band. Clipping is implemented as |
| 564 |
~ %factor (%t) = 1 / (1 / %power (%t) + 1 / %ceiling) |
| 565 |
|
| 566 |
Finally, the original filtered sound %x (%t), multiplied by this factor, is added to the output. |
| 567 |
{-; |
| 568 |
form Consonantversterker |
| 569 |
positive Enhancement_(dB) 20 |
| 570 |
choice Algoritme: 3 |
| 571 |
button (1) Luide stukken spreiden in de tijd |
| 572 |
button (2) Versterken bij beweging |
| 573 |
button (3) Intensiteitscontour filteren |
| 574 |
comment Al deze algoritmen werken binnen alle frequentiebanden! |
| 575 |
endform |
| 576 |
smooth = 100 |
| 577 |
low = 300 |
| 578 |
high = 8000 |
| 579 |
maximumFactor = 10^(Enhancement/20) |
| 580 |
|
| 581 |
Copy... original |
| 582 |
|
| 583 |
# Remove filter bands. |
| 584 |
To Spectrum (fft) |
| 585 |
Formula... if x<'low'-'smooth' then self else |
| 586 |
... if x<'low'+'smooth' then self*(0.5+0.5*cos(pi*(x-('low'-'smooth'))/(2*'smooth'))) else |
| 587 |
... if x<'high'-'smooth' then 0 else |
| 588 |
... if x<'high'+'smooth' then self*(0.5-0.5*cos(pi*(x-('high'-'smooth'))/(2*'smooth'))) else |
| 589 |
... self fi fi fi fi |
| 590 |
To Sound (fft) |
| 591 |
Rename... enhanced |
| 592 |
|
| 593 |
min = low |
| 594 |
while min < high |
| 595 |
mid_bark = hertzToBark (min) + 0.5 |
| 596 |
max = round (barkToHertz (hertzToBark (min) + 1)) |
| 597 |
if max > high |
| 598 |
max = high |
| 599 |
endif |
| 600 |
call enhance_one_band |
| 601 |
min = max |
| 602 |
endwhile |
| 603 |
|
| 604 |
select Spectrum original |
| 605 |
plus Sound original |
| 606 |
Remove |
| 607 |
|
| 608 |
select Sound enhanced |
| 609 |
Rename... 'Algoritme'_'Enhancement' |
| 610 |
Scale... 0.99 |
| 611 |
|
| 612 |
procedure enhance_one_band |
| 613 |
select Sound original |
| 614 |
To Spectrum (fft) |
| 615 |
Formula... if x<'min'-'smooth'then 0 else |
| 616 |
... if x<'min'+'smooth' then self*(0.5-0.5*cos(pi*(x-('min'-'smooth'))/(2*'smooth'))) else |
| 617 |
... if x<'max'-'smooth' then self else |
| 618 |
... if x<'max'+'smooth' then self*(0.5+0.5*cos(pi*(x-('max'-'smooth'))/(2*'smooth'))) else |
| 619 |
... 0 fi fi fi fi |
| 620 |
Rename... band |
| 621 |
To Sound (fft) |
| 622 |
if Algoritme = 1 |
| 623 |
To Intensity... 120 0.01 |
| 624 |
select Intensity band |
| 625 |
Erase all |
| 626 |
Viewport... 0 6 0 4 |
| 627 |
Draw... 0 5 0 80 yes |
| 628 |
Down to Matrix |
| 629 |
Rename... factor |
| 630 |
Formula... if Intensity_band [col-2] > self then Intensity_band [col-2] else self fi |
| 631 |
Formula... if Intensity_band [col-1] > self then Intensity_band [col-1] else self fi |
| 632 |
Formula... if Intensity_band [col+1] > self then Intensity_band [col+1] else self fi |
| 633 |
Formula... if Intensity_band [col+2] > self then Intensity_band [col+2] else self fi |
| 634 |
Red |
| 635 |
Draw rows... 0 5 0 0 0 80 |
| 636 |
Black |
| 637 |
Formula... self - Intensity_band [] |
| 638 |
Formula... if self > 'Enhancement' then 'Enhancement' else self fi |
| 639 |
Formula... 10^(self/20) |
| 640 |
Viewport... 0 6 4 8 |
| 641 |
Draw rows... 0 5 0 0 0 Enhancement |
| 642 |
Draw inner box |
| 643 |
Text top... yes Band from 'min' to 'max' Hertz |
| 644 |
Marks bottom... 2 yes yes no |
| 645 |
Marks left every... 1 5 yes yes yes |
| 646 |
select Intensity band |
| 647 |
Remove |
| 648 |
elsif Algoritme = 2 |
| 649 |
To Intensity... 120 0.01 |
| 650 |
# Enhance contour |
| 651 |
Erase all |
| 652 |
Viewport... 0 6 0 4 |
| 653 |
Draw... 0 5 0 80 yes |
| 654 |
Down to Matrix |
| 655 |
Rename... factor |
| 656 |
Formula... if col = 1 or col = ncol then 1 else |
| 657 |
... (abs (Intensity_band [col-1] - Intensity_band []) + |
| 658 |
... abs (Intensity_band [col+1] - Intensity_band []))*0.5 fi |
| 659 |
Formula... if self < 1 then 1 else if self > 'maximumFactor' then 'maximumFactor' else self fi fi |
| 660 |
Red |
| 661 |
Draw rows... 0 5 0 0 1 maximumFactor |
| 662 |
Black |
| 663 |
Text top... yes Band from 'min' to 'max' Hertz |
| 664 |
Marks right every... 1 1 yes yes yes |
| 665 |
select Intensity band |
| 666 |
Remove |
| 667 |
elsif Algoritme = 3 |
| 668 |
Copy... intensity |
| 669 |
Formula... self^2+1e-6 |
| 670 |
Formula... 10*log10(self) |
| 671 |
To Spectrum (fft) |
| 672 |
Rename... intensityfilt |
| 673 |
Formula... self*exp(-(x/35)^2)-self*exp(-(x/3.5)^2); if x<3 or x>30 then 0 else self fi; |
| 674 |
To Sound (fft) |
| 675 |
Erase all |
| 676 |
Viewport... 0 6 0 4 |
| 677 |
Text top... no Band van 'min' tot 'max' Hertz |
| 678 |
Draw... 0 5 -10 10 yes |
| 679 |
Down to Matrix |
| 680 |
Rename... factor |
| 681 |
Formula... 10^(Sound_intensityfilt[]/2) |
| 682 |
ceiling = 1+(maximumFactor -1)*(0.5-0.5*cos(pi*mid_bark/13)) |
| 683 |
Formula... 1/(1/self+1/'ceiling') |
| 684 |
Viewport... 0 6 4 8 |
| 685 |
Draw rows... 0 5 0 0 0 ceiling |
| 686 |
Draw inner box |
| 687 |
Marks bottom... 2 yes yes no |
| 688 |
Marks left every... 1 1 yes yes yes |
| 689 |
select Sound intensity |
| 690 |
plus Spectrum intensityfilt |
| 691 |
plus Sound intensityfilt |
| 692 |
Remove |
| 693 |
endif |
| 694 |
select Sound band |
| 695 |
Formula... self*Matrix_factor() |
| 696 |
|
| 697 |
select Sound enhanced |
| 698 |
Formula... self+Sound_band[] |
| 699 |
|
| 700 |
select Matrix factor |
| 701 |
plus Spectrum band |
| 702 |
plus Sound band |
| 703 |
Remove |
| 704 |
endproc |
| 705 |
} |
| 706 |
|
| 707 |
{-; |
| 708 |
Sound: Filter (freq. domain): |
| 709 |
>> Nog iets anders. Ik heb het een tijdje geleden met jou gehad over 'troep' |
| 710 |
>> die met jouw eenvoudige filtertechniek in geluidsfiles terechtkomt. In de |
| 711 |
>> attachment zit een (synthetische) spraakuiting met hier en daar een (echte) |
| 712 |
>> stilte erin. Filter die maar eens met een 'telefoonfilter'(alles 0 voor |
| 713 |
>> x<300 or x>3400). Hier in Nijmegen krijg ik er dan een hele vieze zoemtoon |
| 714 |
>> in, die ook duidelijk te zien is in de stilten van het signaal. |
| 715 |
> |
| 716 |
>Je bedoelt met de formule if x<300 or x>3400 then 0 else self fi ? |
| 717 |
|
| 718 |
Ja |
| 719 |
|
| 720 |
|
| 721 |
>De top van de 300-Hz-ringing is bij mij -40 dB bij 0.54 seconde, |
| 722 |
>en -46 dB bij 1.89 seconde. Hoort dat niet? |
| 723 |
} |
| 724 |
|
| 725 |
################################################################################ |
| 726 |
"Sound: Extract part..." |
| 727 |
© Paul Boersma 2024 |
| 728 |
|
| 729 |
A command to copy a part of each selected @Sound object to the Objects window. |
| 730 |
|
| 731 |
Settings |
| 732 |
======== |
| 733 |
|
| 734 |
##Time range (s) |
| 735 |
: the time range (%t_1, %t_2) of the part that has to be extracted. |
| 736 |
|
| 737 |
##Window shape# (standard: “rectangular”) |
| 738 |
: one of 12 possible window shapes; see below. |
| 739 |
|
| 740 |
##Relative width# (standard: 1.0) |
| 741 |
: the relative width of the extracted part, as compared to the duration %t_2 \-m %t_1. |
| 742 |
If the relative width is 1.0, then the part from %t_1 to %t_2 will be extracted. |
| 743 |
If the relative width is 2.0, then the part from %t_1 \-m 0.5 %dur to %t_2 + 0.5 %dur will be extracted, |
| 744 |
where %dur is %t_2 \-m %t_1. See below for when and why this is useful. |
| 745 |
|
| 746 |
##Preserve times# (standard: off) |
| 747 |
: if %on, then the time domain of the resulting extracted Sound object will run from %t_1 to %t_2. |
| 748 |
If %off, then the resulting extracted Sound will be time-shifted to start at zero, |
| 749 |
i.e. its time domain will run from 0 seconds to %t_2 \-m %t_1. |
| 750 |
|
| 751 |
Window shapes |
| 752 |
============= |
| 753 |
|
| 754 |
Suppose we have the following sound, with the part we want to extract (from 0.06 to 0.16 seconds) |
| 755 |
already marked: |
| 756 |
{ 6x3 |
| 757 |
sweep = Create Sound from formula: "sweep", 1, 0.0, 0.3, 44100, ~ sin(2*pi*1000*x^2) |
| 758 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 759 |
One mark bottom: 0.06, "yes", "yes", "no", "" |
| 760 |
One mark bottom: 0.16, "yes", "yes", "no", "" |
| 761 |
} |
| 762 |
We now extract the part form 0.05 to 0.15 seconds: |
| 763 |
{ |
| 764 |
Extract part: 0.06, 0.16, "rectangular", 1.0, "yes" |
| 765 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 766 |
} |
| 767 |
With %%Preserve times% off, we instead get: |
| 768 |
{ |
| 769 |
selectObject: sweep |
| 770 |
Extract part: 0.06, 0.16, "rectangular", 1.0, "no" |
| 771 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 772 |
} |
| 773 |
These were extracted with a rectangular window. We have many other shapes |
| 774 |
(see @@Sound: Multiply by window...@). With a Hanning window, we get: |
| 775 |
{ |
| 776 |
selectObject: sweep |
| 777 |
Extract part: 0.06, 0.16, "Hanning", 1.0, "yes" |
| 778 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 779 |
} |
| 780 |
With a Hamming window, we get: |
| 781 |
{ |
| 782 |
selectObject: sweep |
| 783 |
Extract part: 0.06, 0.16, "Hamming", 1.0, "yes" |
| 784 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 785 |
} |
| 786 |
With a triangular window, we get: |
| 787 |
{ |
| 788 |
selectObject: sweep |
| 789 |
Extract part: 0.06, 0.16, "triangular", 1.0, "yes" |
| 790 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 791 |
} |
| 792 |
With a parabolic window, we get: |
| 793 |
{ |
| 794 |
selectObject: sweep |
| 795 |
Extract part: 0.06, 0.16, "parabolic", 1.0, "yes" |
| 796 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 797 |
} |
| 798 |
With a Gaussian1 window, we get: |
| 799 |
{ |
| 800 |
selectObject: sweep |
| 801 |
Extract part: 0.06, 0.16, "Gaussian1", 1.0, "yes" |
| 802 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 803 |
} |
| 804 |
With a Kaiser1 window, we get: |
| 805 |
{ |
| 806 |
selectObject: sweep |
| 807 |
Extract part: 0.06, 0.16, "Kaiser1", 1.0, "yes" |
| 808 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 809 |
} |
| 810 |
These last six windows have a comparable effective duration. |
| 811 |
The names of the last two windows, however, sound as if they |
| 812 |
want to approximate a Gaussian shape, but they obviously don’t |
| 813 |
(they don’t go to zero fast enough at the edges). |
| 814 |
We can improve the Gaussianness of the window shape |
| 815 |
by halving the effective duration. |
| 816 |
With a Gaussian2 window, we get: |
| 817 |
{ |
| 818 |
selectObject: sweep |
| 819 |
Extract part: 0.06, 0.16, "Gaussian2", 1.0, "yes" |
| 820 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 821 |
} |
| 822 |
and the very similar Kaiser2 window: |
| 823 |
{ |
| 824 |
selectObject: sweep |
| 825 |
Extract part: 0.06, 0.16, "Kaiser2", 1.0, "yes" |
| 826 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 827 |
} |
| 828 |
The advantage of these two windows is that they cut away too muich of the signal at the edges. |
| 829 |
To make the effective window duration similar again, we would like to |
| 830 |
extract a part that is physically twice as long. |
| 831 |
We can do that by setting %%Relative width% to 2.0 instead of 1.0. |
| 832 |
The Gaussian2 window then results in: |
| 833 |
{ |
| 834 |
selectObject: sweep |
| 835 |
Extract part: 0.06, 0.16, "Gaussian2", 2.0, "yes" |
| 836 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 837 |
One mark bottom: 0.06, "yes", "yes", "yes", "" |
| 838 |
One mark bottom: 0.16, "yes", "yes", "yes", "" |
| 839 |
} |
| 840 |
and the very similar Kaiser2 window: |
| 841 |
{ |
| 842 |
selectObject: sweep |
| 843 |
Extract part: 0.06, 0.16, "Kaiser2", 2.0, "yes" |
| 844 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 845 |
One mark bottom: 0.06, "yes", "yes", "yes", "" |
| 846 |
One mark bottom: 0.16, "yes", "yes", "yes", "" |
| 847 |
} |
| 848 |
The Gaussian3, Gaussian4 and Gaussian5 windows approximate the Gaussian shape |
| 849 |
even better than Gaussian2 and Kaiser2 do, |
| 850 |
but they require even longer relative widths, namely 3.0, 4.0 and 5.0 respectively. |
| 851 |
|
| 852 |
In Praat, most acoustical analyses are done with Kaiser2 windows, |
| 853 |
such as @@Sound: To Spectrogram...@ and @@Sound: To Pitch (ac)...@ |
| 854 |
(the latter with the %%Very accurate% setting switched on). |
| 855 |
|
| 856 |
################################################################################ |
| 857 |
"Extract selected sound (windowed)..." |
| 858 |
© Paul Boersma 2024 |
| 859 |
|
| 860 |
A command in the Sound menu of several windows (SoundEditor, TextGridEditor...), |
| 861 |
to copy the selected part of the sound to the Objects window. |
| 862 |
|
| 863 |
For settings and behaviour, see @@Sound: Extract part...@. |
| 864 |
|
| 865 |
################################################################################ |
| 866 |
"Sound: Filter (de-emphasis)..." |
| 867 |
© Paul Boersma 2003-03-09 |
| 868 |
|
| 869 |
A command to filter every selected @Sound object. The resulting Sound object has a lower spectral slope. |
| 870 |
|
| 871 |
The reverse of @@Sound: Filter (pre-emphasis)...@. For an example, see @@Source-filter synthesis@. |
| 872 |
|
| 873 |
Setting |
| 874 |
======= |
| 875 |
|
| 876 |
##From frequency (Hz) |
| 877 |
: the frequency %F above which the spectral slope will decrease by 6 dB/octave. |
| 878 |
|
| 879 |
Algorithm |
| 880 |
========= |
| 881 |
|
| 882 |
The de-emphasis factor %\al is computed as |
| 883 |
~ %\al = exp (-2 %\pi %F %\Det) |
| 884 |
|
| 885 |
where %\Det is the sampling period of the sound. The new sound %y is then computed recursively as: |
| 886 |
~ %y_1 = %x_1 |
| 887 |
~ %y_%i = %x_%i + %\al %y__%i\-m1_ |
| 888 |
|
| 889 |
################################################################################ |
| 890 |
"Sound: Filter (formula)..." |
| 891 |
© Paul Boersma 2004-11-23 |
| 892 |
|
| 893 |
A command to convert every selected @Sound object into a filtered sound. |
| 894 |
|
| 895 |
The filtering is done in the frequency domain. This command is equivalent to the following sequence: |
| 896 |
, 1. @@Sound: To Spectrum...@ yes |
| 897 |
, 2. @@Matrix: Formula... |
| 898 |
, 3. @@Spectrum: To Sound |
| 899 |
|
| 900 |
For a comparative discussion of various filtering methods, see the @Filtering tutorial. |
| 901 |
|
| 902 |
The example formula is the following: |
| 903 |
{; |
| 904 |
if x<500 or x>1000 then 0 else self fi ; rectangular band |
| 905 |
} |
| 906 |
|
| 907 |
This formula represents a rectangular pass band between 500 Hz and 1000 Hz (%x is the frequency). |
| 908 |
Rectangular bands are %not recommended, since they may lead to an appreciable amount of %#ringing in the time domain. |
| 909 |
The transition between stop and pass band should be smooth, as e.g. in @@Sound: Filter (pass Hann band)...@. |
| 910 |
|
| 911 |
################################################################################ |
| 912 |
"Sound: Filter (one formant)..." |
| 913 |
© Paul Boersma 2003-03-09 |
| 914 |
|
| 915 |
A command to filter every selected @Sound object, with a single formant of a specified frequency and bandwidth. |
| 916 |
|
| 917 |
Algorithm |
| 918 |
========= |
| 919 |
|
| 920 |
Two recursive filter coefficients are computed as follows: |
| 921 |
~ %p = \-m2 exp (\-m%\pi %bandwidth %dt) cos (2%\pi %frequency %dt) |
| 922 |
~ %q = exp (\-m2%\\pi %bandwidth %dt) |
| 923 |
|
| 924 |
where %dt is the sample period. The new signal %y is then computed from the old signal %x and itself as |
| 925 |
~ %y__1_ := %x_1 |
| 926 |
~ %y__2_ := %x_2 \-m %p %y_1 |
| 927 |
~ \At%n \>_ 3: %y_%n := %x_%n \-m %p %y__%n\-m1_ \-m %q %y__%n\-m2_ |
| 928 |
|
| 929 |
After filtering, the sound %y is scaled so that its absolute extremum is 0.9. |
| 930 |
|
| 931 |
For a comparative discussion of various filtering methods, see the @Filtering tutorial. |
| 932 |
|
| 933 |
This filter has an in-place version: @@Sound: Filter with one formant (in-place)...@. |
| 934 |
|
| 935 |
################################################################################ |
| 936 |
"Sound: Filter with one formant (in-place)..." |
| 937 |
© Paul Boersma 2017-11-14 |
| 938 |
|
| 939 |
A command to filter every selected @Sound object in-place, with a single formant of a specified frequency and bandwidth. |
| 940 |
|
| 941 |
This is the in-place version of @@Sound: Filter (one formant)...@, |
| 942 |
i.e. it does not create a new Sound object but modifies the selected object. |
| 943 |
|
| 944 |
################################################################################ |
| 945 |
"Sound: Filter (pass Hann band)..." |
| 946 |
© Paul Boersma 2004-11-23 |
| 947 |
|
| 948 |
A command to convert every selected @Sound object into a filtered sound. |
| 949 |
|
| 950 |
The filtering is done in the frequency domain. This command is equivalent to the following sequence: |
| 951 |
, 1. @@Sound: To Spectrum... |
| 952 |
, 2. @@Spectrum: Filter (pass Hann band)... |
| 953 |
, 3. @@Spectrum: To Sound |
| 954 |
|
| 955 |
For a comparative discussion of various filtering methods, see the @Filtering tutorial. |
| 956 |
|
| 957 |
For a complementary filter, see @@Sound: Filter (stop Hann band)...@. |
| 958 |
|
| 959 |
################################################################################ |
| 960 |
"Sound: Filter (stop Hann band)..." |
| 961 |
© Paul Boersma 2004-11-23 |
| 962 |
|
| 963 |
A command to convert every selected @Sound object into a filtered sound. |
| 964 |
|
| 965 |
The filtering is done in the frequency domain. This command is equivalent to the following sequence: |
| 966 |
, 1. @@Sound: To Spectrum... |
| 967 |
, 2. @@Spectrum: Filter (stop Hann band)... |
| 968 |
, 3. @@Spectrum: To Sound |
| 969 |
|
| 970 |
For a comparative discussion of various filtering methods, see the @Filtering tutorial. |
| 971 |
|
| 972 |
For a complementary filter, see @@Sound: Filter (pass Hann band)...@. |
| 973 |
|
| 974 |
################################################################################ |
| 975 |
"Sound: Formula..." |
| 976 |
© Paul Boersma 2002-12-06 |
| 977 |
|
| 978 |
A command for changing the data in all selected @Sound objects. |
| 979 |
|
| 980 |
See the @Formulas tutorial for examples and explanations. |
| 981 |
|
| 982 |
################################################################################ |
| 983 |
"Sound: Get absolute extremum..." |
| 984 |
© Paul Boersma 2004-07-11 |
| 985 |
|
| 986 |
A @@Query submenu|query@ to the selected @Sound object. |
| 987 |
|
| 988 |
Return value |
| 989 |
============ |
| 990 |
|
| 991 |
the absolute extremum (in Pascal) within a specified time window. |
| 992 |
|
| 993 |
Settings |
| 994 |
======== |
| 995 |
|
| 996 |
%%Time range% (s) |
| 997 |
: the time range (%t_1, %t_2). Values outside this range are ignored. |
| 998 |
If %t_1 is not less than %t_2, the entire time domain of the sound is considered. |
| 999 |
|
| 1000 |
%%Interpolation |
| 1001 |
: the interpolation method (None, Parabolic, Sinc) of the @@vector peak interpolation@. |
| 1002 |
The standard is Sinc70 because a Sound object is normally a sampled band-limited signal, |
| 1003 |
which can be seen as a sum of sinc functions. |
| 1004 |
|
| 1005 |
################################################################################ |
| 1006 |
"Sound: Get energy..." |
| 1007 |
© Paul Boersma 2021-07-19 |
| 1008 |
|
| 1009 |
A @@Query submenu|query@ to the selected @Sound object. |
| 1010 |
|
| 1011 |
Availability |
| 1012 |
============ |
| 1013 |
|
| 1014 |
This command becomes available in the Query submenu when you select one Sound. |
| 1015 |
Like most query commands, it is greyed out if you select two Sounds or more. |
| 1016 |
|
| 1017 |
Behaviour |
| 1018 |
========= |
| 1019 |
|
| 1020 |
If you execute this command, Praat should write the energy of the selected Sound (in the time interval you are asking for) into the Info window. |
| 1021 |
If the unit of sound amplitude is Pa (Pascal), the unit of energy will be Pa^2·s. |
| 1022 |
|
| 1023 |
Setting |
| 1024 |
======= |
| 1025 |
|
| 1026 |
##Time range (s) |
| 1027 |
: the time range (%t_1, %t_2). Values outside this range are ignored. |
| 1028 |
If %t_1 is not less than %t_2, the entire time domain of the sound is considered. |
| 1029 |
|
| 1030 |
Definition |
| 1031 |
========== |
| 1032 |
|
| 1033 |
The energy is defined as |
| 1034 |
~ \in__%t1_^^%t2^ %x^2(%t) %dt |
| 1035 |
|
| 1036 |
where %x(%t) is the amplitude of the sound. For stereo sounds, it is |
| 1037 |
~ \in__%t1_^^%t2^ (%x^2(%t) + %y^2(%t))/2 %dt |
| 1038 |
|
| 1039 |
where %x(%t) and %y(%t) are the two channels; this definition, which averages (rather than sums) over the channels, ensures that |
| 1040 |
if you convert a mono sound to a stereo sound, the energy will stay the same. |
| 1041 |
|
| 1042 |
Related commands |
| 1043 |
================ |
| 1044 |
|
| 1045 |
For an interpretation of the energy as the sound energy in air, see @@Sound: Get energy in air@. |
| 1046 |
For the power, see @@Sound: Get power...@. |
| 1047 |
|
| 1048 |
Implementation |
| 1049 |
============== |
| 1050 |
|
| 1051 |
In Praat, a Sound is defined only at a finite number of time points, spaced evenly. |
| 1052 |
For instance, a three-seconds long Sound with a sampling frequency of 10 kHz is defined at 30,000 time points, |
| 1053 |
which usually (e.g. when you create the Sound with @@Create Sound from formula...@) lie |
| 1054 |
at 0.00005, 0.00015, 0.00025 ... 2.99975, 2.99985 and 2.99995 seconds. |
| 1055 |
The simple way Praat looks at this is that the first %sample is centred around 0.00005 seconds, |
| 1056 |
and the amplitude of that sample (%x_1) represents %x(%t) for %t between 0 and 0.00010 seconds. |
| 1057 |
Likewise, the second sample is centred around 0.00015 seconds but can be said to run from 0.00010 to 0.00020 seconds, |
| 1058 |
and the 30,000th and last sample is centred around 2.99995 seconds and its amplitude (%x__30000_) |
| 1059 |
represents all times between 2.99990 and 3.00000 seconds. |
| 1060 |
This example sound %x(%t) is therefore defined for all times between 0 and 3 seconds, |
| 1061 |
but is undefined before 0 seconds or after 3 seconds. |
| 1062 |
|
| 1063 |
The energy of the whole example sound is therefore |
| 1064 |
~ \in_0^3 %x^2(%t) %dt |
| 1065 |
|
| 1066 |
and we approximate this as a sum over all 30,000 samples: |
| 1067 |
~ \su__%i=1_^^30000^ %x_%i^2 %\Det_%i |
| 1068 |
|
| 1069 |
where %\Det_%i is the duration of the %%i%th sample, i.e. 0.0001 seconds for every sample. |
| 1070 |
|
| 1071 |
Now consider what happens if we want to know the energy between %t_1 = 0.00013 and %t_2 = 0.00054 seconds. |
| 1072 |
The first sample of the sound falls entirely outside this interval; |
| 1073 |
70 percent of the second sample falls within the interval, namely the part from 0.00013 to 0.00020 seconds; |
| 1074 |
all of the third, fourth and fifth samples fall within the interval; |
| 1075 |
and 40 percent of the sixth sample falls within the interval, namely the part from 0.00050 to 0.00054 seconds |
| 1076 |
(note that the centre of this sixth sample, which is at 0.00055 seconds, even lies outside the interval). |
| 1077 |
The energy is then |
| 1078 |
~ \su__%i=2_^6 %x_%i^2 %\Det_%i |
| 1079 |
|
| 1080 |
where %\Det_3 = %\Det_4 = %\Det_5 = 0.0001 seconds, |
| 1081 |
but %\Det_2 is only 0.00007 seconds (namely the part of the second sample that falls between %t_1 and %t_2), |
| 1082 |
and %\Det_6 is only 0.00004 seconds (namely the part of the sixth sample that falls between %t_1 and %t_2). |
| 1083 |
|
| 1084 |
This way of integrating the squared signal (technically, a Riemann sum over a partition [of the interval from |
| 1085 |
%t_1 to %t_2] that is regular everywhere except at the edges and has central tags everywhere except at the edges) |
| 1086 |
ensures that the result is a continuous function of %t_1 and %t_2, |
| 1087 |
i.e., a very small change in %t_1 or %t_2 can only lead to a very small change in the computed energy |
| 1088 |
(instead, simply summing over all samples whose centre falls between %t_1 and %t_2 would result instead in a sudden jump |
| 1089 |
in the computed energy whenever %t_1 or %t_2 crosses a sample centre, |
| 1090 |
which would be unphysical behaviour and therefore not how Praat should behave; |
| 1091 |
see the @@energy integration continuity test@). |
| 1092 |
|
| 1093 |
Edge cases |
| 1094 |
========== |
| 1095 |
|
| 1096 |
If the sound is not defined everywhere between %t_1 and %t_2, then the energy is not defined there either. |
| 1097 |
Those times are skipped in the integral, i.e. they count as if they have zero energy. |
| 1098 |
|
| 1099 |
################################################################################ |
| 1100 |
"energy integration continuity test" |
| 1101 |
© Paul Boersma 2025-05-14 |
| 1102 |
|
| 1103 |
{ |
| 1104 |
\`{random_initializeWithSeedUnsafelyButPredictably} (89678363) |
| 1105 |
samplingFrequency = 44100 |
| 1106 |
my.Sound = \@{Create Sound from formula:} "sineWithNoise", 1, 0.0, 1.0, |
| 1107 |
... samplingFrequency, ~ 1/2 * sin(2*pi*377*x) + randomGauss(0,0.1) |
| 1108 |
} |
| 1109 |
|
| 1110 |
What is the biggest step between two consecutive samples? |
| 1111 |
{ |
| 1112 |
difference.Sound = \@{Copy:} "difference" |
| 1113 |
\@{Formula:} ~ if col = ncol then 0 else self [col + 1] - self [col] fi |
| 1114 |
biggestAbsoluteWaveformStepBetweenSamples = \@{Sound: ||Get absolute extremum:} 0, 0, "none" |
| 1115 |
\`{appendInfoLine}: "## biggest absolute waveform step between samples: ", |
| 1116 |
... biggestAbsoluteWaveformStepBetweenSamples, " Pa" |
| 1117 |
} |
| 1118 |
|
| 1119 |
This corresponds to the following biggest energy step between two consecutive samples: |
| 1120 |
{ |
| 1121 |
biggestAbsoluteEnergyStepBetweenSamples = biggestAbsoluteWaveformStepBetweenSamples ^ 2 / samplingFrequency |
| 1122 |
\`{appendInfoLine}: "## biggest absolute energy step between samples: ", |
| 1123 |
... biggestAbsoluteEnergyStepBetweenSamples, " Pa²s" |
| 1124 |
} |
| 1125 |
|
| 1126 |
We’ll divide up every sample into 10 ministeps: |
| 1127 |
{ |
| 1128 |
oversampling = 10 |
| 1129 |
} |
| 1130 |
|
| 1131 |
Between any consecutive ministeps, the energy step should not exceed one tenth |
| 1132 |
of the biggest energy step between two consecutive samples: |
| 1133 |
{ |
| 1134 |
biggestAbsoluteEnergyMinistep = biggestAbsoluteEnergyStepBetweenSamples / oversampling |
| 1135 |
\`{appendInfoLine}: "## biggest absolute energy ministep: ", |
| 1136 |
... biggestAbsoluteEnergyMinistep, " Pa²s" |
| 1137 |
} |
| 1138 |
|
| 1139 |
Large test: |
| 1140 |
{ |
| 1141 |
\`{stopwatch} |
| 1142 |
minidt = 1.0 / samplingFrequency / oversampling |
| 1143 |
tmin = 1e-9 ; not 0.0, in order to prevent autowindowing |
| 1144 |
previousEnergy = \#@{Sound: ||Get energy:} 0, tmin |
| 1145 |
for i from 1 to 10000 |
| 1146 |
energy = \#@{Sound: ||Get energy:} 0, tmin + i * minidt |
| 1147 |
energyGain = energy - previousEnergy |
| 1148 |
if i < 100 |
| 1149 |
\`{appendInfoLine}: i, " ", energy, " ", energyGain |
| 1150 |
endif |
| 1151 |
step = \`{abs} (energyGain) |
| 1152 |
\`{assert} step > 0.0 |
| 1153 |
\`{assert} step < 1.0000000000001 * biggestAbsoluteEnergyMinistep ; also captures undefined samples |
| 1154 |
previousEnergy = energy |
| 1155 |
endfor |
| 1156 |
\`{appendInfoLine}: "## time elapsed: ", \`{fixed$} (\`{stopwatch} * 1000, 3), " ms" |
| 1157 |
} |
| 1158 |
|
| 1159 |
################################################################################ |
| 1160 |
"Sound: Get energy in air" |
| 1161 |
© Paul Boersma 2007-01-29 |
| 1162 |
|
| 1163 |
A @@Query submenu|query@ to the selected @Sound object. |
| 1164 |
|
| 1165 |
Return value |
| 1166 |
============ |
| 1167 |
|
| 1168 |
The energy in air, expressed in Joule/m^2. |
| 1169 |
|
| 1170 |
Algorithm |
| 1171 |
========= |
| 1172 |
|
| 1173 |
The energy of a sound in air is defined as |
| 1174 |
~ 1 / (%\ro%c) \in %x^2(%t) %dt |
| 1175 |
|
| 1176 |
where %x(%t) is the sound pressure in units of Pa (Pascal), %\ro is the air density |
| 1177 |
(apx. 1.14 kg/m^3), and %c is the velocity of sound in air (apx. 353 m/s). |
| 1178 |
For how stereo sounds are handled, see @@Sound: Get energy...@. |
| 1179 |
|
| 1180 |
See also |
| 1181 |
======== |
| 1182 |
|
| 1183 |
For an air-independent interpretation of the energy, see @@Sound: Get energy...@. |
| 1184 |
For the power, see @@Sound: Get power in air@. |
| 1185 |
|
| 1186 |
################################################################################ |
| 1187 |
"Sound: Get intensity (dB)" |
| 1188 |
© Paul Boersma 2007-01-29 |
| 1189 |
|
| 1190 |
A @@Query submenu|query@ to the selected @Sound object. |
| 1191 |
|
| 1192 |
Return value |
| 1193 |
============ |
| 1194 |
|
| 1195 |
the intensity in air, expressed in dB relative to the auditory threshold. |
| 1196 |
|
| 1197 |
Algorithm |
| 1198 |
========= |
| 1199 |
|
| 1200 |
The intensity of a sound in air is defined as |
| 1201 |
~ 10 log__10_ { 1 / (%T %P_0^2) \in%dt %x^2(%t) } |
| 1202 |
|
| 1203 |
where %x(%t) is the sound pressure in units of Pa (Pascal), %T is the duration of the sound, |
| 1204 |
and %P_0 = 2·10^^-5^ Pa is the auditory threshold pressure. |
| 1205 |
For how stereo sounds are handled, see @@Sound: Get energy...@. |
| 1206 |
|
| 1207 |
See also |
| 1208 |
======== |
| 1209 |
|
| 1210 |
For the intensity in Watt/m^2, see @@Sound: Get power in air@. For an auditory intensity, |
| 1211 |
see @@Excitation: Get loudness@. |
| 1212 |
|
| 1213 |
################################################################################ |
| 1214 |
"Sound: Get maximum..." |
| 1215 |
© Paul Boersma 2022-12-02 |
| 1216 |
|
| 1217 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1218 |
The Info window will show the maximum amplitude (sound pressure in Pascal) within a specified time window. |
| 1219 |
|
| 1220 |
Settings |
| 1221 |
======== |
| 1222 |
|
| 1223 |
##Time range (s) |
| 1224 |
: the time range (%t_1, %t_2). Values outside this range are ignored, except for purposes of interpolation. |
| 1225 |
If %t_1 is not less than %t_2, the entire time domain of the sound is considered. |
| 1226 |
|
| 1227 |
##Interpolation |
| 1228 |
: the interpolation method (#none, #parabolic, #cubic, #sinc70, #sinc700) of the @@vector peak interpolation@. |
| 1229 |
The standard is “sinc70” because a Sound object is normally a sampled band-limited signal, |
| 1230 |
which can be seen as a sum of sinc functions. |
| 1231 |
|
| 1232 |
################################################################################ |
| 1233 |
"Sound: Get mean..." |
| 1234 |
© Paul Boersma 2022-12-02 |
| 1235 |
|
| 1236 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1237 |
The Info window will show the mean amplitude (sound pressure in Pascal) within a specified time range. |
| 1238 |
|
| 1239 |
Setting |
| 1240 |
======= |
| 1241 |
|
| 1242 |
##Time range (s) |
| 1243 |
: the time range (%t_1, %t_2). Values outside this range are ignored. |
| 1244 |
If %t_1 is not less than %t_2, the entire time domain of the sound is considered. |
| 1245 |
|
| 1246 |
Mathematical definition |
| 1247 |
======================= |
| 1248 |
|
| 1249 |
The mean amplitude between the times %t_1 and %t_2 is defined as |
| 1250 |
~ 1/(%t_2 \-m %t_1) \in__%t1_^^%t2^ %x(%t) %dt |
| 1251 |
|
| 1252 |
where %x(%t) is the amplitude of the sound in Pa. |
| 1253 |
|
| 1254 |
################################################################################ |
| 1255 |
"Sound: Get minimum..." |
| 1256 |
© Paul Boersma 2022-12-02 |
| 1257 |
|
| 1258 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1259 |
The Info window will show the minimum amplitude (sound pressure in Pascal) within a specified time window. |
| 1260 |
|
| 1261 |
Settings |
| 1262 |
======== |
| 1263 |
|
| 1264 |
##Time range (s) |
| 1265 |
: the time range (%t_1, %t_2). Values outside this range are ignored, except for purposes of interpolation. |
| 1266 |
If %t_1 is not less than %t_2, the entire time domain of the sound is considered. |
| 1267 |
|
| 1268 |
%%Interpolation |
| 1269 |
: the interpolation method (#none, #parabolic, #cubic, #sinc70, #sinc700) of the @@vector peak interpolation@. |
| 1270 |
The standard is “sinc70” because a Sound object is normally a sampled band-limited signal, |
| 1271 |
which can be seen as a sum of sinc functions. |
| 1272 |
|
| 1273 |
################################################################################ |
| 1274 |
"Sound: Get nearest zero crossing..." |
| 1275 |
© Paul Boersma 2022-12-02 |
| 1276 |
|
| 1277 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1278 |
The Info window will show the time associated with the zero crossing nearest to a specified time point. |
| 1279 |
It is @undefined if there are no zero crossings or if the specified time is outside the time domain of the sound. |
| 1280 |
Linear interpolation is used between sample points. |
| 1281 |
|
| 1282 |
Setting |
| 1283 |
======= |
| 1284 |
|
| 1285 |
##Time (s) |
| 1286 |
: the time for which you want to get the time of the nearest zero crossing. |
| 1287 |
|
| 1288 |
################################################################################ |
| 1289 |
"Sound: Get power..." |
| 1290 |
© Paul Boersma 1999,2004,2007,2022,2026 |
| 1291 |
|
| 1292 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1293 |
The Info window will show the power within a specified time window. |
| 1294 |
If the unit of sound amplitude is Pa (Pascal), the unit of power will be Pa^2. |
| 1295 |
|
| 1296 |
Setting |
| 1297 |
======= |
| 1298 |
|
| 1299 |
##Time range (s) |
| 1300 |
: the time range (%t_1, %t_2). Values outside this range are ignored. |
| 1301 |
If %t_1 is not less than %t_2, the entire time domain of the sound is considered. |
| 1302 |
|
| 1303 |
Mathematical definition |
| 1304 |
======================= |
| 1305 |
|
| 1306 |
The power is defined as |
| 1307 |
~ 1/(%t_2\-m%t_1) \in__%t1_^^%t2^ %x^2(%t) %dt |
| 1308 |
|
| 1309 |
where %x(%t) is the amplitude of the sound. |
| 1310 |
For how stereo sounds are handled, see @@Sound: Get energy...@. |
| 1311 |
|
| 1312 |
See also |
| 1313 |
======== |
| 1314 |
|
| 1315 |
For an interpretation of the power as the sound power in air, see @@Sound: Get power in air@. |
| 1316 |
For the total energy, see @@Sound: Get energy...@. |
| 1317 |
|
| 1318 |
################################################################################ |
| 1319 |
"Sound: Get power in air" |
| 1320 |
© Paul Boersma 2022-12-02 |
| 1321 |
|
| 1322 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1323 |
The Info window will show the power in air, expressed in Watt/m^2. |
| 1324 |
|
| 1325 |
Mathematical definition |
| 1326 |
======================= |
| 1327 |
|
| 1328 |
The power of a sound in air is defined as |
| 1329 |
~ 1 / (%\ro%c%T) \in %x^2(%t) %dt |
| 1330 |
|
| 1331 |
where %x(%t) is the sound pressure in units of Pa (Pascal), %\ro is the air density |
| 1332 |
(apx. 1.14 kg/m^3), %c is the velocity of sound in air (apx. 353 m/s), and %T is the duration of the sound. |
| 1333 |
For how stereo sounds are handled, see @@Sound: Get energy...@. |
| 1334 |
|
| 1335 |
For an air-independent interpretation of the power, see @@Sound: Get power...@. |
| 1336 |
For the energy, see @@Sound: Get energy in air@. For the intensity in dB, |
| 1337 |
see @@Sound: Get intensity (dB)@. |
| 1338 |
|
| 1339 |
################################################################################ |
| 1340 |
"Sound: Get root-mean-square..." |
| 1341 |
© Paul Boersma 2022-12-02 |
| 1342 |
|
| 1343 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1344 |
The Info window will show the root-mean-square (rms) value of the sound pressure, expressed in Pascal. |
| 1345 |
|
| 1346 |
Setting |
| 1347 |
======= |
| 1348 |
|
| 1349 |
##Time range (s) |
| 1350 |
: the time range (%t_1, %t_2). Values outside this range are ignored. |
| 1351 |
If %t_1 is not less than %t_2, the entire time domain of the sound is considered. |
| 1352 |
|
| 1353 |
Mathematical definition |
| 1354 |
======================= |
| 1355 |
|
| 1356 |
The root-mean-square value is defined as |
| 1357 |
~ \Vr { 1/(%t_2\-m%t_1) \in__%t1_^^%t2^ %x^2(%t) %dt } |
| 1358 |
|
| 1359 |
where %x(%t) is the amplitude of the sound. |
| 1360 |
For how stereo sounds are handled, see @@Sound: Get energy...@. |
| 1361 |
|
| 1362 |
################################################################################ |
| 1363 |
"Sound: Get standard deviation..." |
| 1364 |
© Paul Boersma 2022-12-02 |
| 1365 |
|
| 1366 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1367 |
The Info window will show the standard deviation (in Pascal) of the sound pressure within a specified window. |
| 1368 |
If the sound contains less than 2 samples, the value is @undefined. |
| 1369 |
|
| 1370 |
Setting |
| 1371 |
======= |
| 1372 |
|
| 1373 |
##Time range (s) |
| 1374 |
: the time range (%t_1, %t_2). Values outside this range are ignored. |
| 1375 |
If %t_1 is not less than %t_2, the entire time domain of the sound is considered. |
| 1376 |
|
| 1377 |
Mathematical definition |
| 1378 |
======================= |
| 1379 |
|
| 1380 |
The standard deviation is defined as |
| 1381 |
~ 1/(%t_2-%t_1) \in%__%t1_^^%t2^ (%x(%t) - %\mu)^2 %dt |
| 1382 |
|
| 1383 |
where %x(%t) is the amplitude of the sound, and %\mu is its mean. |
| 1384 |
For our discrete Sound object, the standard deviation is approximated by |
| 1385 |
~ 1/(%n\-m1) \su__%i=%m..%m+%n\-m1_ (%x_%i \-m %\mu)^2 |
| 1386 |
|
| 1387 |
where %n is the number of sample centres between %t_1 and %t_2. Note the \"minus 1\". |
| 1388 |
|
| 1389 |
################################################################################ |
| 1390 |
"Sound: Get time of maximum..." |
| 1391 |
© Paul Boersma 2022-12-02 |
| 1392 |
|
| 1393 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1394 |
The Info window will show the time (in seconds) associated with the maximum pressure in a specified time range. |
| 1395 |
|
| 1396 |
Settings |
| 1397 |
======== |
| 1398 |
|
| 1399 |
##Time range (s) |
| 1400 |
: the time range (%t__1_, %t__2_). Values outside this range are ignored, except for purposes of interpolation. |
| 1401 |
If %t__1_ is not less than %t__2_, the entire time domain of the sound is considered. |
| 1402 |
|
| 1403 |
##Interpolation |
| 1404 |
: the interpolation method (#none, #parabolic, #cubic, #sinc70, #sinc700) of the @@vector peak interpolation@. |
| 1405 |
The standard is “sinc70” because a Sound object is normally a sampled band-limited signal, |
| 1406 |
which can be seen as a sum of sinc functions. |
| 1407 |
|
| 1408 |
################################################################################ |
| 1409 |
"Sound: Get time of minimum..." |
| 1410 |
© Paul Boersma 2022-12-02 |
| 1411 |
|
| 1412 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1413 |
The Info window will show the time (in seconds) associated with the minimum pressure in a specified time range. |
| 1414 |
|
| 1415 |
Settings |
| 1416 |
======== |
| 1417 |
|
| 1418 |
##Time range (s) |
| 1419 |
: the time range (%t_1, %t_2). Values outside this range are ignored, except for purposes of interpolation. |
| 1420 |
If %t_1 is not less than %t_2, the entire time domain of the sound is considered. |
| 1421 |
|
| 1422 |
##Interpolation |
| 1423 |
: the interpolation method (#none, #parabolic, #cubic, #sinc70, #sinc700) of the @@vector peak interpolation@. |
| 1424 |
The standard is “sinc70” because a Sound object is normally a sampled band-limited signal, |
| 1425 |
which can be seen as a sum of sinc functions. |
| 1426 |
|
| 1427 |
################################################################################ |
| 1428 |
"Sound: Get value at sample number..." |
| 1429 |
© Paul Boersma 2022-12-02 |
| 1430 |
|
| 1431 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1432 |
The Info window will show the amplitude (sound pressure in Pascal) at a specified sample number. |
| 1433 |
If the sample number is less than 1 or greater than the number of samples, the result is @undefined. |
| 1434 |
|
| 1435 |
Setting |
| 1436 |
======= |
| 1437 |
|
| 1438 |
##Sample number |
| 1439 |
: the sample number at which the value is to be evaluated. |
| 1440 |
|
| 1441 |
################################################################################ |
| 1442 |
"Sound: Get value at time..." |
| 1443 |
© Paul Boersma 2022-12-02 |
| 1444 |
|
| 1445 |
A command available in the @@Query submenu@ if you select a @Sound object. |
| 1446 |
The Info window will show an estimate of the amplitude (sound pressure in Pascal) at a specified time. |
| 1447 |
If that time is outside the samples of the Sound, the result is equal to the value of the nearest sample; |
| 1448 |
otherwise, the result is an interpolated value. |
| 1449 |
|
| 1450 |
Settings |
| 1451 |
======== |
| 1452 |
|
| 1453 |
##Time (s) |
| 1454 |
: the time at which the value is to be evaluated. |
| 1455 |
|
| 1456 |
##Interpolation |
| 1457 |
: the interpolation method, see @@vector value interpolation@. |
| 1458 |
The standard is “sinc70” because a Sound object is normally a sampled band-limited signal, |
| 1459 |
which can be seen as a sum of sinc functions. |
| 1460 |
|
| 1461 |
################################################################################ |
| 1462 |
"Sound: Lengthen (overlap-add)..." |
| 1463 |
© Paul Boersma 20030916) // 2023-- |
| 1464 |
|
| 1465 |
A command to convert each selected @Sound object into a longer new @Sound object. |
| 1466 |
|
| 1467 |
Settings |
| 1468 |
======== |
| 1469 |
|
| 1470 |
##Pitch floor (Hz) |
| 1471 |
: the minimum pitch used in the periodicity analysis. The standard value is 75 Hz. For the voice of a young child, set this to 150 Hz." |
| 1472 |
The shortest voiceless interval in the decomposition is taken as 1.5 divided by %%minimum frequency%. |
| 1473 |
|
| 1474 |
##Pitch ceiling (Hz) |
| 1475 |
: the maximum pitch used in the periodicity analysis. The standard value is 600 Hz. For an adult male voice, set this to 300 Hz. |
| 1476 |
|
| 1477 |
##Factor |
| 1478 |
: the factor with which the sound will be lengthened. The standard value is 1.5. If you take a value less than 1, |
| 1479 |
the resulting sound will be shorter than the original. A value larger than 3 will not work. |
| 1480 |
|
| 1481 |
Algorithm |
| 1482 |
========= |
| 1483 |
|
| 1484 |
@@overlap-add@. |
| 1485 |
|
| 1486 |
################################################################################ |
| 1487 |
"Sound: Multiply by window..." |
| 1488 |
© Paul Boersma 2024 |
| 1489 |
|
| 1490 |
A command to multiply each selected @Sound object by a window shape. |
| 1491 |
|
| 1492 |
Settings |
| 1493 |
======== |
| 1494 |
|
| 1495 |
##Window shape |
| 1496 |
: one of 12 possible window shapes. |
| 1497 |
|
| 1498 |
Window shapes |
| 1499 |
============= |
| 1500 |
|
| 1501 |
Suppose we have the following sound: |
| 1502 |
{ 6x3 |
| 1503 |
Create Sound from formula: "sweep", 1, 0.0, 0.1, 44100, ~ sin(2*pi*1000*x^2) |
| 1504 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 1505 |
} |
| 1506 |
The shape of a ##Hanning window# is |
| 1507 |
{ 6x3 |
| 1508 |
Create Sound from formula: "window", 1, 0.0, 0.1, 44100, ~ 1 |
| 1509 |
Multiply by window: "Hanning" |
| 1510 |
Draw: 0, 0, 0.0, 1.0, "yes", "curve" |
| 1511 |
} |
| 1512 |
If you multiply these with each other, the result will be |
| 1513 |
{ 6x3 |
| 1514 |
selectObject: "Sound sweep" |
| 1515 |
Multiply by window: "Hanning" |
| 1516 |
Draw: 0, 0, -1.0, 1.0, "yes", "curve" |
| 1517 |
} |
| 1518 |
In short: |
| 1519 |
{- |
| 1520 |
procedure drawWindowing: .windowShape$ |
| 1521 |
Create Sound from formula: "sweep", 1, 0.0, 0.1, 44100, ~ sin(2*pi*1000*x^2) |
| 1522 |
Select outer viewport: 0, 3.1, 0, 2.5 |
| 1523 |
Draw: 0, 0, -1.1, 1.1, "yes", "curve" |
| 1524 |
Create Sound from formula: "window", 1, 0.0, 0.1, 44100, ~ 1 |
| 1525 |
Multiply by window: .windowShape$ |
| 1526 |
Select outer viewport: 2.2, 5.3, 0, 2.5 |
| 1527 |
Draw: 0, 0, -1.1, 1.1, "no", "curve" |
| 1528 |
Draw inner box |
| 1529 |
Text bottom: "yes", "Time (s)" |
| 1530 |
Marks bottom: 2, "yes", "yes", "no" |
| 1531 |
Marks left: 2, "yes", "yes", "no" |
| 1532 |
One mark left: 0.0, "no", "no", "yes", "" |
| 1533 |
selectObject: "Sound sweep" |
| 1534 |
Multiply by window: .windowShape$ |
| 1535 |
Text top: "no", "##" + .windowShape$ |
| 1536 |
Select outer viewport: 4.4, 7.5, 0, 2.5 |
| 1537 |
Draw: 0, 0, -1.1, 1.1, "no", "curve" |
| 1538 |
Draw inner box |
| 1539 |
Text bottom: "yes", "Time (s)" |
| 1540 |
Marks bottom: 2, "yes", "yes", "no" |
| 1541 |
Marks left: 2, "yes", "yes", "no" |
| 1542 |
One mark left: 0.0, "no", "no", "yes", "" |
| 1543 |
Axes: 0, 100, 0, 100 |
| 1544 |
info$ = Picture info |
| 1545 |
fontSize = extractNumber (info$, "Font size: ") |
| 1546 |
Select outer viewport: 2.2, 3.1, 0, 2.5 |
| 1547 |
Text special: 50, "centre", 50, "half", "Times", 2*fontSize, "0", "\xx" |
| 1548 |
Select outer viewport: 4.4, 5.3, 0, 2.5 |
| 1549 |
Text special: 50, "centre", 50, "half", "Times", 2*fontSize, "0", "=" |
| 1550 |
endproc |
| 1551 |
} |
| 1552 |
{- 7.5x2.5 |
| 1553 |
@drawWindowing: "Hanning" |
| 1554 |
} |
| 1555 |
Other windows: |
| 1556 |
{- 7.5x2.5 |
| 1557 |
@drawWindowing: "Hamming" |
| 1558 |
} |
| 1559 |
{- 7.5x2.5 |
| 1560 |
@drawWindowing: "triangular" |
| 1561 |
} |
| 1562 |
{- 7.5x2.5 |
| 1563 |
@drawWindowing: "parabolic" |
| 1564 |
} |
| 1565 |
{- 7.5x2.5 |
| 1566 |
@drawWindowing: "Gaussian1" |
| 1567 |
} |
| 1568 |
{- 7.5x2.5 |
| 1569 |
@drawWindowing: "Kaiser1" |
| 1570 |
} |
| 1571 |
The following one does nothing: |
| 1572 |
{- 7.5x2.5 |
| 1573 |
@drawWindowing: "rectangular" |
| 1574 |
} |
| 1575 |
These two have an effective duration that is 50 percent shorter: |
| 1576 |
{- 7.5x2.5 |
| 1577 |
@drawWindowing: "Gaussian2" |
| 1578 |
} |
| 1579 |
{- 7.5x2.5 |
| 1580 |
@drawWindowing: "Kaiser2" |
| 1581 |
} |
| 1582 |
And these are narrower again: |
| 1583 |
{- 7.5x2.5 |
| 1584 |
@drawWindowing: "Gaussian3" |
| 1585 |
} |
| 1586 |
{- 7.5x2.5 |
| 1587 |
@drawWindowing: "Gaussian4" |
| 1588 |
} |
| 1589 |
{- 7.5x2.5 |
| 1590 |
@drawWindowing: "Gaussian5" |
| 1591 |
} |
| 1592 |
|
| 1593 |
################################################################################ |
| 1594 |
"audio control panel" |
| 1595 |
© Paul Boersma 2022-09-11,2024,2026 |
| 1596 |
|
| 1597 |
Your platform’s way of controlling where sounds will be played, and how loud. |
| 1598 |
|
| 1599 |
On macOS X or 11 or 12 or 13 or 14 or 15 or 26, go to the Apple menu, |
| 1600 |
then to ##System Settings# (older: ##System Preferences#), |
| 1601 |
then to #Sound, then to #Output. If you want to change only the loudness, |
| 1602 |
then modern Macs have three keys on the keyboard for that. |
| 1603 |
|
| 1604 |
On Ubuntu Linux 22.04 or 24.04, the fastest way is to click the loudspeaker icon in the menu bar, |
| 1605 |
then click the #Settings symbol (or the cartwheel), then #Output |
| 1606 |
(otherwise, look for the #Settings app, then #Sound, then #Output). |
| 1607 |
|
| 1608 |
On Windows 10 or 11, it lies somewhat deeper: |
| 1609 |
go to the Start icon, then to #Settings, then to #System, then to #Sound, then to #Output. |
| 1610 |
|
| 1611 |
################################################################################ |
| 1612 |
"Sound: Play" |
| 1613 |
© Paul Boersma 2005-08-22 |
| 1614 |
|
| 1615 |
A command to play @Sound objects. |
| 1616 |
|
| 1617 |
Availability |
| 1618 |
============ |
| 1619 |
|
| 1620 |
You can choose this command after selecting one or more Sounds. |
| 1621 |
|
| 1622 |
Purpose |
| 1623 |
======= |
| 1624 |
|
| 1625 |
To play the selected Sounds through the internal or external loudspeakers, |
| 1626 |
the headphones, or the analog or digital outputs of your computer. |
| 1627 |
|
| 1628 |
Behaviour |
| 1629 |
========= |
| 1630 |
|
| 1631 |
All of the Sounds selected are played, |
| 1632 |
in the order in which they appear in the list. If the sampling frequency of the Sound does not match any of |
| 1633 |
the system's sampling frequencies, a fast but inaccurate conversion is performed via linear interpolation. |
| 1634 |
|
| 1635 |
Usage |
| 1636 |
===== |
| 1637 |
|
| 1638 |
The output level and the choice of the output device(s) depend on the settings |
| 1639 |
in your @@audio control panel@. |
| 1640 |
|
| 1641 |
################################################################################ |
| 1642 |
"Sound: Draw..." |
| 1643 |
© Paul Boersma 2023 |
| 1644 |
|
| 1645 |
A command that becomes available in the #Draw menu when you select one or more @Sound objects. |
| 1646 |
|
| 1647 |
Purpose |
| 1648 |
======= |
| 1649 |
To draw the selected Sound into the selected part of the @@Picture window@. |
| 1650 |
|
| 1651 |
################################################################################ |
| 1652 |
"Sound: Filter (pre-emphasis)..." |
| 1653 |
© Paul Boersma 2003-03-09 |
| 1654 |
|
| 1655 |
A command to filter each selected @Sound object. The resulting Sound object has a higher spectral slope. |
| 1656 |
|
| 1657 |
The reverse of @@Sound: Filter (de-emphasis)...@. |
| 1658 |
|
| 1659 |
Setting |
| 1660 |
======= |
| 1661 |
|
| 1662 |
##From frequency (Hz) |
| 1663 |
: the frequency %F above which the spectral slope will increase by 6 dB/octave. |
| 1664 |
|
| 1665 |
Algorithm |
| 1666 |
========= |
| 1667 |
|
| 1668 |
The pre-emphasis factor %\al is computed as |
| 1669 |
~ %\al = exp (-2 %\pi %F \De%t) |
| 1670 |
|
| 1671 |
where \De%t is the sampling period of the sound. The new sound %y is then computed as: |
| 1672 |
~ %y_%i = %x_%i - %\al %x__%i-1_ |
| 1673 |
|
| 1674 |
################################################################################ |
| 1675 |
"Sound: Pre-emphasize (in-place)..." |
| 1676 |
© Paul Boersma 2022-04-07 |
| 1677 |
|
| 1678 |
A command to change the spectral slope of every selected @Sound object. |
| 1679 |
|
| 1680 |
The reverse of @@Sound: De-emphasize (in-place)...@. |
| 1681 |
|
| 1682 |
This is the in-place version of @@Sound: Filter (pre-emphasis)...@, |
| 1683 |
i.e., it does not create a new Sound object but modifies an existing object. |
| 1684 |
|
| 1685 |
Setting |
| 1686 |
======= |
| 1687 |
|
| 1688 |
##From frequency (Hz) |
| 1689 |
: the frequency %F above which the spectral slope will increase by 6 dB/octave. |
| 1690 |
|
| 1691 |
Algorithm |
| 1692 |
========= |
| 1693 |
|
| 1694 |
The pre-emphasis factor %\al is computed as |
| 1695 |
~ %\al = exp (-2 %\pi %F \De%t) |
| 1696 |
|
| 1697 |
where \De%t is the sampling period of the sound. Every sample %x_%i of the sound, |
| 1698 |
except %x_1, is then changed, going down from the last sample: |
| 1699 |
~ %x_%i = %x_%i - %\al %x__%i-1_ |
| 1700 |
|
| 1701 |
################################################################################ |
| 1702 |
"Sound: Resample..." |
| 1703 |
© Paul Boersma 2004-03-30 |
| 1704 |
|
| 1705 |
A command that creates new @Sound objects from the selected Sounds. |
| 1706 |
|
| 1707 |
Purpose |
| 1708 |
======= |
| 1709 |
|
| 1710 |
High-precision resampling from any sampling frequency to any other sampling frequency. |
| 1711 |
|
| 1712 |
Settings |
| 1713 |
======== |
| 1714 |
|
| 1715 |
##Sampling frequency (Hz) |
| 1716 |
: the new sampling frequency, in hertz. |
| 1717 |
|
| 1718 |
##Precision |
| 1719 |
: the depth of the interpolation, in samples (standard is 50). |
| 1720 |
This determines the quality of the interpolation used in resampling. |
| 1721 |
|
| 1722 |
Algorithm |
| 1723 |
========= |
| 1724 |
|
| 1725 |
If #Precision is 1, the method is linear interpolation, which is inaccurate but fast. |
| 1726 |
// BUG |
| 1727 |
|
| 1728 |
If #Precision is greater than 1, the method is sin(%x)/%x (“%sinc”) interpolation, |
| 1729 |
with a depth equal to #Precision. |
| 1730 |
For higher #Precision, the algorithm is slower but more accurate. |
| 1731 |
|
| 1732 |
If ##Sampling frequency# is less than the sampling frequency of the selected sound, |
| 1733 |
an anti-aliasing low-pass filtering is performed prior to resampling. |
| 1734 |
|
| 1735 |
Behaviour |
| 1736 |
========= |
| 1737 |
|
| 1738 |
A new Sound will appear in the list of objects, |
| 1739 |
bearing the same name as the original Sound, followed by the sampling frequency. |
| 1740 |
For instance, the Sound `hallo` will give a new Sound `hallo_10000`. |
| 1741 |
|
| 1742 |
################################################################################ |
| 1743 |
"Sound: Set value at sample number..." |
| 1744 |
© Paul Boersma 2014-04-21 |
| 1745 |
|
| 1746 |
A command to change a specified sample of the selected @Sound object. |
| 1747 |
|
| 1748 |
Settings |
| 1749 |
======== |
| 1750 |
|
| 1751 |
##Sample number |
| 1752 |
: the sample whose value is to be changed. Specify any value between 1 and the number of samples in the Sound. |
| 1753 |
If you specify a value outside that range, you will get an error message. |
| 1754 |
|
| 1755 |
##New value |
| 1756 |
: the value that is to be put into the specified sample. |
| 1757 |
|
| 1758 |
Scripting |
| 1759 |
========= |
| 1760 |
|
| 1761 |
Example: |
| 1762 |
{; |
| 1763 |
\`{selectObject}: "Sound hallo" |
| 1764 |
\#{Set value at sample number:} 100, 1/2 |
| 1765 |
} |
| 1766 |
This sets the value of the 100th sample to 0.5. |
| 1767 |
|
| 1768 |
################################################################################ |
| 1769 |
"SoundEditor" |
| 1770 |
© Paul Boersma 20220814,2023-06-08 |
| 1771 |
|
| 1772 |
An @@Editors|Editor@ for viewing and editing a @Sound object. |
| 1773 |
Most of the functions of this editor are described in the @Intro. |
| 1774 |
|
| 1775 |
The markers |
| 1776 |
=========== |
| 1777 |
|
| 1778 |
To set the cursor, use the left mouse button. A short horizontal line will also be shown at the left edge (in cyan); |
| 1779 |
the extension of this line crosses the cursor line at the sound's function value (seen as a cyan dot). |
| 1780 |
This function value (shown at the left in cyan) is the sinc-interpolated value, and is generally different from the |
| 1781 |
value that you would expect when looking at the linearly interpolated version of the sampled sound. |
| 1782 |
|
| 1783 |
To select a part of the time domain, use the @@time selection@ mechanism. |
| 1784 |
|
| 1785 |
Playing |
| 1786 |
======= |
| 1787 |
|
| 1788 |
To play any part of the sound, click in one of the rectangles |
| 1789 |
below or above the sound window (there can be 1 to 8 of these rectangles), |
| 1790 |
or choose a command from the Play menu. |
| 1791 |
|
| 1792 |
To mute one or more channels (of a multi-channel sound), @@Command-click@ |
| 1793 |
on the 🔈 icon at the right side of the corresponding channel number. |
| 1794 |
The icon will turn to 🔇. In subsequent playing actions, |
| 1795 |
the channel will not be played. Another @@Command-click@ on a muted channel icon will activate the channel again. |
| 1796 |
|
| 1797 |
Publishing |
| 1798 |
========== |
| 1799 |
|
| 1800 |
To perform analyses on the selection, or save it to a file, |
| 1801 |
create an independent Sound as a copy of the selection, |
| 1802 |
by clicking on the button that will copy the selection to the List of Objects; |
| 1803 |
the resulting Sound will be called “Sound untitled”. |
| 1804 |
|
| 1805 |
Editing |
| 1806 |
======= |
| 1807 |
- Cut: cut the selection to the clipboard, for later pasting into the same or another Sound. |
| 1808 |
- Copy selection to Sound clipboard: copy the selection to the clipboard, for later pasting into the same or another Sound. |
| 1809 |
- Paste after selection: paste the clipboard to the cursor or after the selection. |
| 1810 |
- Set selection to zero: set the selected samples to zero. |
| 1811 |
- Reverse selection: reverse the selected part of the sound. |
| 1812 |
|
| 1813 |
You can undo these commands with Undo (@@Keyboard shortcuts|Command-Z@). |
| 1814 |
|
| 1815 |
The Group button |
| 1816 |
================ |
| 1817 |
|
| 1818 |
To synchronize a SoundEditor window with other windows that show a time signal, |
| 1819 |
push the Group button in all the windows that you want to synchronize. |
| 1820 |
You cannot Cut from or Paste into a synchronized SoundEditor window. |
| 1821 |
|
| 1822 |
################################################################################ |
| 1823 |
"SoundRecorder" |
| 1824 |
© Paul Boersma 2020-11-20,2024 |
| 1825 |
|
| 1826 |
With the Praat SoundRecorder window you can record a mono or stereo sound |
| 1827 |
for subsequent viewing and analysis in Praat. |
| 1828 |
The SoundRecorder appears on your screen if you choose @@Record mono Sound...@ or @@Record stereo Sound...@ |
| 1829 |
from the @@New menu@. |
| 1830 |
|
| 1831 |
Depending on your system, the SoundRecorder window may allow you to choose |
| 1832 |
the sampling frequency, the input gain, and the input device (microphone, line, or digital). |
| 1833 |
The sound input level is monitored continuously with one or two meters. |
| 1834 |
The resulting sound has 16 bits per sample, like sounds on an audio CD. |
| 1835 |
|
| 1836 |
Usage |
| 1837 |
===== |
| 1838 |
|
| 1839 |
To record the sound, use the Record and Stop buttons in the SoundRecorder window. |
| 1840 |
Click ##Save to list# to copy the recorded sound to the object window |
| 1841 |
(or ##Save left channel to list# or ##Save right channel to list# |
| 1842 |
to copy the left or right channel if you have a stereo sound). |
| 1843 |
The name of the resulting Sound object will be taken from the text field next to the button clicked. |
| 1844 |
|
| 1845 |
Size of the recording buffer |
| 1846 |
============================ |
| 1847 |
|
| 1848 |
The size of the recording buffer determines how many seconds of sound you can record. |
| 1849 |
For instance, if the recording buffer is 20 megabytes (the standard value), you can record 220 seconds in stereo |
| 1850 |
(440 seconds in mono) at a sampling frequency of 22050 Hz, |
| 1851 |
or 110 seconds in stereo (220 seconds in mono) at a sampling frequency of 44100 Hz. |
| 1852 |
You can change the size of the recording buffer |
| 1853 |
with #Praat \-> #Settings \-> ##Sound recording settings...#. |
| 1854 |
|
| 1855 |
Recording sounds on the Mac or in Linux |
| 1856 |
====================================== |
| 1857 |
|
| 1858 |
On the Mac or in Linux, you can record from the list on the left in the SoundRecorder window. |
| 1859 |
The list can contain several devices, such as the internal microphone, a line input, or external USB devices. |
| 1860 |
Audio tracks on a CD can be opened directly with @@Read from file...@ or @@Open long sound file...@. |
| 1861 |
|
| 1862 |
Recording sounds in Windows |
| 1863 |
=========================== |
| 1864 |
|
| 1865 |
In Windows 10, you can choose your input device by right-clicking on the loudspeaker icon in the Start bar, |
| 1866 |
then choosing ##Open Sound settings# \-> ##Choose your input device#. In Windows 11, |
| 1867 |
you right-click the loudspeaker icon and choose ##Sound settings# \-> ##Choose a device for speaking or recording# instead." |
| 1868 |
To set some input properties, right-click the loudspeaker icon, |
| 1869 |
then on Windows 10 you choose #Sounds \-> #Recording \-> #Properties, |
| 1870 |
while on Windows 11 you choose ##Sound settings# \-> #Advanced \-> ##All sound devices# \-> ##Input devices# \-> #Microphone. |
| 1871 |
|
| 1872 |
Watching the input level |
| 1873 |
======================== |
| 1874 |
|
| 1875 |
While recording, you can watch the input level as a green rectangle whose size changes. |
| 1876 |
Whenever the input is loud, the top of the rectangle becomes yellow; if it turns red, the sound may have been clipped. |
| 1877 |
In the Meter menu you can choose other visualizations, |
| 1878 |
such as a moving ball that measures spectral centre of gravity (horizontally) versus intensity (vertically). |
| 1879 |
|
| 1880 |
The File menu |
| 1881 |
============= |
| 1882 |
|
| 1883 |
If your computer has little memory, a very long recorded sound might be too big to be copied to the list of objects. |
| 1884 |
Fortunately, the File menu contains commands to save the recording |
| 1885 |
to a sound file on disk, so that you will never have to lose your recording. |
| 1886 |
You can later open such a long sound file in Praat with @@Open long sound file...@ from the Open menu. |
| 1887 |
|
| 1888 |
Sound pressure calibration |
| 1889 |
========================== |
| 1890 |
|
| 1891 |
Your computer's sound-recording software returns integer values between -32768 and 32767. |
| 1892 |
Praat divides them by 32768 before putting them into a Sound object, |
| 1893 |
so that the values in the Sound objects are always between -1 and +1. |
| 1894 |
|
| 1895 |
The Praat program considers these numbers to be air pressures in units of Pascal, |
| 1896 |
but they are probably not the actual true air pressures that went into the microphone. |
| 1897 |
For how to obtain the true air pressures, perform a @@sound pressure calibration@. |
| 1898 |
|
| 1899 |
################################################################################ |
| 1900 |
"Sounds: Concatenate" |
| 1901 |
© Paul Boersma 2011-02-11 |
| 1902 |
|
| 1903 |
A command to concatenate all selected @Sound objects into a single large Sound. |
| 1904 |
All sounds must have equal sampling frequencies and equal numbers of channels. |
| 1905 |
They are concatenated in the order in which they appear in the list of objects |
| 1906 |
(not in the order in which you select them; remember: What You See Is What You Get). |
| 1907 |
|
| 1908 |
How to concatenate directly to a file |
| 1909 |
===================================== |
| 1910 |
If the resulting sound does not fit into memory, use one of the |
| 1911 |
commands in the @@Save menu@. See @@How to concatenate sound files@. |
| 1912 |
|
| 1913 |
See also |
| 1914 |
======== |
| 1915 |
If you want the sounds to fade into each other smoothly, choose @@Sounds: Concatenate with overlap...@ instead. |
| 1916 |
|
| 1917 |
################################################################################ |
| 1918 |
"Sounds: Concatenate with overlap..." |
| 1919 |
© Paul Boersma 2017-09-04 |
| 1920 |
|
| 1921 |
A command to concatenate all selected @Sound objects into a single large Sound, with smooth cross-fading between the sounds. |
| 1922 |
|
| 1923 |
All sounds must have equal sampling frequencies and equal numbers of channels. |
| 1924 |
They are concatenated in the order in which they appear in the list of objects (not in the order in which you select them; remember: What You See Is What You Get). |
| 1925 |
|
| 1926 |
Settings |
| 1927 |
======== |
| 1928 |
// 1 field, of which 0 texts and 0 additional radio buttons, |
| 1929 |
// hence lines = 1 + 0 * 0.6 - 0 * 0.3 = 1.0, |
| 1930 |
// hence height = 1.4 + 1.0 * 0.4 = 1.8 |
| 1931 |
{- 5.4x1.8 |
| 1932 |
)~~~" |
| 1933 |
Manual_DRAW_SETTINGS_WINDOW ("Sounds: Concatenate with overlap", 1.0) |
| 1934 |
Manual_DRAW_SETTINGS_WINDOW_FIELD ("Overlap time (s)", "0.01") |
| 1935 |
R"~~~( |
| 1936 |
} |
| 1937 |
|
| 1938 |
##Overlap time (s) |
| 1939 |
: the time by which any two adjacent sounds will come to overlap, |
| 1940 |
i.e. the time during which the earlier sound fades out and the later sound fades in. |
| 1941 |
|
| 1942 |
Procedure |
| 1943 |
========= |
| 1944 |
|
| 1945 |
Suppose we start with the following two sounds. They are both 0.1 seconds long. |
| 1946 |
The first sound is a sine wave with a frequency of 100 Hz, the second a sine wave with a frequency of 230 Hz: |
| 1947 |
{- 5.0x3.0 |
| 1948 |
Create Sound from formula: "sine100", 1, 0, 0.1, 10000, ~ 0.9*sin(2*pi*100*x) |
| 1949 |
Draw: 0, 0, -1, 1, "yes", "Curve" |
| 1950 |
Remove |
| 1951 |
} |
| 1952 |
{- 5.0x3.0 |
| 1953 |
Create Sound from formula: "sine230", 1, 0, 0.1, 10000, ~ 0.9*sin(2*pi*230*x) |
| 1954 |
Draw: 0, 0, -1, 1, "yes", "Curve" |
| 1955 |
Remove |
| 1956 |
} |
| 1957 |
If the overlap time is 0.01 seconds, the concatenation of these two sounds will produce a Sound with a duration of 0.19 seconds, |
| 1958 |
which is the sum of the durations of the two sounds, minus the overlap time. |
| 1959 |
|
| 1960 |
The concatenation works in the following way. |
| 1961 |
The last 0.01 seconds of the first sound is multiplied by a falling raised cosine (the second half of a Hann window, see the first red curve), |
| 1962 |
and the first 0.01 seconds of the second sound is multiplied by a rising raised cosine (the first half of a Hann window, see the second red curve): |
| 1963 |
{- 6.7x5 |
| 1964 |
Create Sound from formula: "sine", 1, 0, 0.1, 10000, ~ 0.9 |
| 1965 |
Formula (part): 0.09, 0.1, 1, 1, ~ self*(0.5-0.5*cos(pi*(xmax-x)/0.01)) |
| 1966 |
Select inner viewport: 0.5, 3.5, 0.5, 2.5 |
| 1967 |
Red |
| 1968 |
Draw: 0, 0, -1, 1, "no", "Curve" |
| 1969 |
Formula: ~ self*sin(2*pi*100*x) |
| 1970 |
Black |
| 1971 |
Draw: 0, 0, -1, 1, "no", "Curve" |
| 1972 |
Draw inner box |
| 1973 |
One mark top: 0, "yes", "yes", "no", "" |
| 1974 |
One mark top: 0.09, "yes", "yes", "yes", "" |
| 1975 |
One mark top: 0.1, "yes", "yes", "no", "" |
| 1976 |
Text top: "no", "Time (s)" |
| 1977 |
One mark left: -1, "yes", "yes", "no", "" |
| 1978 |
One mark left: 0, "yes", "yes", "yes", "" |
| 1979 |
One mark left: 1, "yes", "yes", "no", "" |
| 1980 |
Formula: ~ 0.9 |
| 1981 |
Formula (part): 0, 0.01, 1, 1, ~ self*(0.5-0.5*cos(pi*x/0.01)) |
| 1982 |
Select inner viewport: 3.2, 6.2, 2.5, 4.5 |
| 1983 |
Red |
| 1984 |
Draw: 0, 0, -1, 1, "no", "Curve" |
| 1985 |
Formula: ~ self*sin(2*pi*230*x) |
| 1986 |
Black |
| 1987 |
Draw: 0, 0, -1, 1, "no", "Curve" |
| 1988 |
Draw inner box |
| 1989 |
One mark bottom: 0, "yes", "yes", "no", "" |
| 1990 |
One mark bottom: 0.01, "yes", "yes", "yes", "" |
| 1991 |
One mark bottom: 0.1, "yes", "yes", "no", "" |
| 1992 |
Text bottom: "no", "Time (s)" |
| 1993 |
One mark right: -1, "yes", "yes", "no", "" |
| 1994 |
One mark right: 0, "yes", "yes", "yes", "" |
| 1995 |
One mark right: 1, "yes", "yes", "no", "" |
| 1996 |
Remove |
| 1997 |
} |
| 1998 |
|
| 1999 |
This figure shows how the two sounds are windowed (faded out and in), as well as how they will overlap. |
| 2000 |
|
| 2001 |
Finally, the two windowed ("cross-faded") sounds are added to each other: |
| 2002 |
{- 6.7x3.0 |
| 2003 |
sine100 = Create Sound from formula... sine100 1 0 0.1 10000 0.9*sin(2*pi*100*x) |
| 2004 |
sine230 = Create Sound from formula... sine100 1 0 0.1 10000 0.9*sin(2*pi*230*x) |
| 2005 |
plus sine100 |
| 2006 |
Concatenate with overlap... 0.01 |
| 2007 |
Draw... 0 0 -1 1 yes Curve |
| 2008 |
One mark bottom... 0.09 yes yes yes |
| 2009 |
One mark bottom... 0.1 yes yes yes |
| 2010 |
plus sine100 |
| 2011 |
plus sine230 |
| 2012 |
Remove |
| 2013 |
} |
| 2014 |
|
| 2015 |
This example showed how it works if you concatenate two sounds; |
| 2016 |
if you concatenate three sounds, there will be two overlaps, and so on. |
| 2017 |
|
| 2018 |
################################################################################ |
| 2019 |
"Sounds: Convolve..." |
| 2020 |
© Paul Boersma & David Weenink 2010-04-04,2024 |
| 2021 |
|
| 2022 |
A command available in the #Combine menu when you select two @Sound objects. |
| 2023 |
This command convolves two selected @Sound objects with each other. |
| 2024 |
As a result, a new Sound will appear in the list of objects; |
| 2025 |
this new Sound is the %convolution of the two original Sounds. |
| 2026 |
|
| 2027 |
Settings |
| 2028 |
======== |
| 2029 |
|
| 2030 |
##Amplitude scaling |
| 2031 |
: Here you can choose between the “principled” options #integral, #sum, and #normalize, which are explained in 1, 2 and 3 below. |
| 2032 |
There is also a “pragmatic” option, namely ##peak 0.99#, which scales the resulting sound in such a way |
| 2033 |
that its absolute peak becomes 0.99, so that the sound tends to be clearly audible without distortion when you play it |
| 2034 |
(see @@Sound: Scale peak...@). |
| 2035 |
|
| 2036 |
##Signal outside time domain is... |
| 2037 |
: Here you can choose whether outside their time domains the sounds are considered to be #zero |
| 2038 |
(the standard value), or #similar to the sounds within the time domains. |
| 2039 |
This is explained in 4 below. |
| 2040 |
|
| 2041 |
1. Convolution as an integral |
| 2042 |
============================= |
| 2043 |
|
| 2044 |
The convolution %f*%g of two continuous time signals %f(%t) and %g(%t) is defined as the #integral |
| 2045 |
~ (%f*%g) (%t) \=3 \in %f(%\ta) %g(%t−%\ta) %d\ta |
| 2046 |
|
| 2047 |
If %f and %g are sampled signals (as Sounds are in Praat), with the same @@sampling period@ %\Det, |
| 2048 |
the definition is discretized as |
| 2049 |
~ (%f*%g) [%t] \=3 \su_%\ta %f[%\ta] %g[%t−%\ta] %\Det |
| 2050 |
|
| 2051 |
where %\ta and %t-%\ta are the discrete times at which %f and %g are defined, respectively. |
| 2052 |
|
| 2053 |
Convolution is a commutative operation, i.e. %g*%f equals %f*%g. |
| 2054 |
This means that the order in which you put the two Sounds in the object list does not matter: you get the same result either way. |
| 2055 |
|
| 2056 |
2. Convolution as a sum |
| 2057 |
======================= |
| 2058 |
|
| 2059 |
You can see in the formula above that if both input Sounds are expressed in units of Pa, |
| 2060 |
the resulting Sound should ideally be expressed in Pa^^2^s. |
| 2061 |
Nevertheless, Praat will express it in Pa, because Sounds cannot be expressed otherwise. |
| 2062 |
|
| 2063 |
This basically means that it is impossible to get the amplitude of the resulting Sound correct for all purposes. |
| 2064 |
For this reason, Praat considers a different definition of convolution as well, namely as the #sum |
| 2065 |
~ (%f*%g) [%t] \=3 \su_%\ta %f[%\ta] %g[%t−%\ta] |
| 2066 |
|
| 2067 |
The sum definition is appropriate if you want to filter a pulse train with a finite-impulse-response filter |
| 2068 |
and expect the amplitudes of each resulting period to be equal to the amplitude of the filter. Thus, the pulse train |
| 2069 |
{ 5x3 |
| 2070 |
Create Sound from formula: "peaks", 1, 0.0, 0.6, 1000, ~ x * (col mod 100 = 0) |
| 2071 |
Draw: 0, 0, 0.0, 0.6, "yes", "curve" |
| 2072 |
} |
| 2073 |
convolved with the “leaky integrator” filter |
| 2074 |
{ 5x3 |
| 2075 |
Create Sound from formula: "leak", 1, 0.0, 1.0, 1000, ~ exp (-x / 0.1) |
| 2076 |
Draw: 0, 0, 0.0, 1.0, "yes", "curve" |
| 2077 |
} |
| 2078 |
yields the convolution |
| 2079 |
{ 5x3 |
| 2080 |
selectObject: "Sound peaks", "Sound leak" |
| 2081 |
Convolve: "sum", "zero" |
| 2082 |
Draw: 0, 0, 0.0, 0.8523, "yes", "curve" |
| 2083 |
} |
| 2084 |
|
| 2085 |
The difference between the integral and sum definitions is that in the sum definition |
| 2086 |
the resulting sound is divided by %\Det. |
| 2087 |
|
| 2088 |
3. Normalized convolution |
| 2089 |
========================= |
| 2090 |
|
| 2091 |
The %%normalized convolution% is defined as |
| 2092 |
~ (normalized %f*%g) (%t) \=3 \in %f(%\ta) %g(%t−%\ta) %d\ta |
| 2093 |
/ \Vr (\in %f^2(%\ta) %d\ta \in %g^^2^(%\ta) %d\ta) |
| 2094 |
|
| 2095 |
4. Shape scaling |
| 2096 |
================ |
| 2097 |
|
| 2098 |
The boundaries of the integral in 1 are −\oo and +\oo. |
| 2099 |
However, %f and %g are Sound objects in Praat and therefore have finite time domains. |
| 2100 |
If %f runs from %t_1 to %t_2 and is assumed to be #zero before %t_1 and after %t_2, and |
| 2101 |
%g runs from %t_3 to %t_4 and is assumed to be zero outside that domain, |
| 2102 |
then the convolution will be zero before %t_1+%t_3 and after %t_2+%t_4, |
| 2103 |
while between %t_1+%t_3 and %t_2+%t_4 it is |
| 2104 |
~ (%f*%g) (%t) = \in__%t1_^^%t2^ %f(%\ta) %g(%t−%\ta) %d\ta |
| 2105 |
|
| 2106 |
In this formula, the argument of %f runs from %t_1 to %t_2, |
| 2107 |
but the argument of %g runs from (%t_1+%t_3)−%t_2 to (%t_2+%t_4)−%t_1, |
| 2108 |
i.e. from %t_3−(%t_2−%t_1) to %t_4+(%t_2−%t_1). |
| 2109 |
This means that the integration is performed over two equal stretches of time during which %g must be taken zero, |
| 2110 |
namely a time stretch before %t_3 and a time stretch after %t_4, both of duration %t_2−%t_1 |
| 2111 |
(equivalent equations can be formulated that rely on two stretches of %t_4−%t_3 of zeroes in %f rather than in %g, |
| 2112 |
or on a stretch of %t_2−%t_1 of zeroes in %g and a stretch of %t_4−%t_3 of zeroes in %f. |
| 2113 |
|
| 2114 |
If you consider the sounds outside their time domains as #similar to what they are within their time domains, instead of #zero, |
| 2115 |
the discretized formula in 1 should be based on the average over the jointly defined values of %f[%\ta] and %g[%t−%\ta], |
| 2116 |
without counting any multiplications of values outside the time domains. |
| 2117 |
Suppose that %f is defined on the time domain [0, 1.2] with the value of 1 everywhere, |
| 2118 |
and %g is defined on the time domain [0, 3] with the value 1 everywhere. |
| 2119 |
Their convolution under the assumption that they are #zero elsewhere is then |
| 2120 |
{- 5x3 |
| 2121 |
Create Sound from formula... short mono 0 1.2 1000 1 |
| 2122 |
Create Sound from formula... long mono 0 3 1000 1 |
| 2123 |
plus Sound short |
| 2124 |
Convolve... integral zero |
| 2125 |
Draw... 0 0 0 1.5 yes curve |
| 2126 |
One mark left... 1.2 yes yes yes |
| 2127 |
plus Sound short |
| 2128 |
plus Sound long |
| 2129 |
Remove |
| 2130 |
} |
| 2131 |
but under the assumption that the sounds are #similar (i.e. 1) elsewhere, their convolution should be |
| 2132 |
{- 5x3 |
| 2133 |
Create Sound from formula... short mono 0 1.2 1000 1 |
| 2134 |
Create Sound from formula... long mono 0 3 1000 1 |
| 2135 |
plus Sound short |
| 2136 |
Convolve... integral similar |
| 2137 |
Draw... 0 0 0 1.5 yes curve |
| 2138 |
One mark left... 1.2 yes yes yes |
| 2139 |
plus Sound short |
| 2140 |
plus Sound long |
| 2141 |
Remove |
| 2142 |
} |
| 2143 |
i.e. a constant value of 1.2. This is what you get by choosing the #similar option; |
| 2144 |
if %f is shorter than %g, the first and last parts of the convolution will be divided by a straight line of duration %t_2−%t_1 |
| 2145 |
to compensate for the fact that the convolution has been computed over fewer values of %f and %g there. |
| 2146 |
|
| 2147 |
5. Behaviour |
| 2148 |
============ |
| 2149 |
|
| 2150 |
The start time of the resulting Sound will be the sum of the start times of the original Sounds, |
| 2151 |
the end time of the resulting Sound will be the sum of the end times of the original Sounds, |
| 2152 |
the time of the first sample of the resulting Sound will be the sum of the first samples of the original Sounds, |
| 2153 |
the time of the last sample of the resulting Sound will be the sum of the last samples of the original Sounds, |
| 2154 |
and the number of samples in the resulting Sound will be the sum of the numbers of samples of the original Sounds minus 1. |
| 2155 |
|
| 2156 |
6. Behaviour for stereo and other multi-channel sounds |
| 2157 |
====================================== |
| 2158 |
|
| 2159 |
You can convolve e.g. a 10-channel sound either with another 10-channel sound or with a 1-channel (mono) sound. |
| 2160 |
|
| 2161 |
If both Sounds have more than one channel, the two Sounds have to have the same number of channels; |
| 2162 |
each channel of the resulting Sound is then computed as the convolution of the corresponding channels |
| 2163 |
of the original Sounds. For instance, if you convolve two 10-channel sounds, |
| 2164 |
the resulting sound will have 10 channels, and its 9th channel will be the convolution of the 9th channels |
| 2165 |
of the two original sounds. |
| 2166 |
|
| 2167 |
If one of the original Sounds has multiple channels and the other Sound has only one channel, |
| 2168 |
the resulting Sound will have multiple channels; each of these is computed as the convolution of |
| 2169 |
the corresponding channel of the multiple-channel original and the single channel of the single-channel original. |
| 2170 |
For instance, if you convolve a 10-channel sound with a mono sound, |
| 2171 |
the resulting sound will have 10 channels, and its 9th channel will be the convolution of the mono sound |
| 2172 |
with the 9th channel of the original 10-channel sound. |
| 2173 |
|
| 2174 |
The amplitude scaling factor will be the same for all channels, so that the relative amplitude of the channels |
| 2175 |
will be preserved in the resulting sound. For the #normalize scaling, for instance, the norm of %f in the formula above |
| 2176 |
is taken over all channels of %f. For the ##peak 0.99# scaling, the resulting sound will typically have an absolute peak |
| 2177 |
of 0.99 in only one channel, and lower absolute peaks in the other channels. |
| 2178 |
|
| 2179 |
7. Algorithm |
| 2180 |
============ |
| 2181 |
|
| 2182 |
The computation makes use of the fact that convolution in the time domain corresponds to multiplication in the frequency domain: |
| 2183 |
we first pad %f with a stretch of %t_4−%t_3 of zeroes and %g with a stretch of %t_2−%t_1 of zeroes (see 4 above), |
| 2184 |
so that both sounds obtain a duration of (%t_2−%t_1)+(%t_4−%t_3); |
| 2185 |
we then calculate the spectra of the two zero-padded sounds by Fourier transformation, |
| 2186 |
then multiply the two spectra with each other, |
| 2187 |
and finally Fourier-transform the result of this multiplication back to the time domain; |
| 2188 |
the result will again have a duration of (%t_2−%t_1)+(%t_4−%t_3). |
| 2189 |
|
| 2190 |
################################################################################ |
| 2191 |
"Sounds: Cross-correlate..." |
| 2192 |
© David Weenink & Paul Boersma 2010-04-04,2024 |
| 2193 |
|
| 2194 |
A command available in the #Combine menu when you select two @Sound objects. |
| 2195 |
This command cross-correlates two selected @Sound objects with each other. |
| 2196 |
As a result, a new Sound will appear in the list of objects; |
| 2197 |
this new Sound is the %cross-correlation of the two original Sounds. |
| 2198 |
|
| 2199 |
Settings |
| 2200 |
======== |
| 2201 |
|
| 2202 |
##Amplitude scaling |
| 2203 |
: Here you can choose between the “principled” options #integral, #sum, and #normalize, which are explained in 1, 2 and 3 below. |
| 2204 |
There is also a “pragmatic” option, namely ##peak 0.99#, which scales the resulting sound in such a way |
| 2205 |
that its absolute peak becomes 0.99, so that the sound tends to be clearly audible without distortion when you play it |
| 2206 |
(see @@Sound: Scale peak...@). |
| 2207 |
|
| 2208 |
##Signal outside time domain is... |
| 2209 |
: Here you can choose whether outside their time domains the sounds are considered to be #zero |
| 2210 |
(the standard value), or #similar to the sounds within the time domains. |
| 2211 |
This is explained in 4 below. |
| 2212 |
|
| 2213 |
1. Cross-correlation as an integral |
| 2214 |
=================================== |
| 2215 |
|
| 2216 |
The cross-correlation of two continuous time signals %f(%t) and %g(%t) is a function of the lag time %\\ta, |
| 2217 |
and defined as the #integral |
| 2218 |
~ cross-corr (%f, %g) (%\ta) \=3 \in %f(%t) %g(%t+%\ta) %dt |
| 2219 |
|
| 2220 |
If %f and %g are sampled signals (as Sounds are in Praat), with the same @@sampling period@ %%\\Det%, |
| 2221 |
the definition is discretized as |
| 2222 |
~ cross-corr (%f, %g) [%\ta] \=3 \su_%t %f[%t] %g[%t+%\ta] %\Det |
| 2223 |
|
| 2224 |
where %\ta and %t+%\ta are the discrete times at which %f and %g are defined, respectively. |
| 2225 |
|
| 2226 |
Cross-correlation is not a commutative operation, i.e. cross-corr (%g, %f) equals the time reversal of cross-corr (%f, %g). |
| 2227 |
This means that the order in which you put the two Sounds in the object list does matter: |
| 2228 |
the two results are each other's time reversals. |
| 2229 |
|
| 2230 |
2. Cross-correlation as a sum |
| 2231 |
============================= |
| 2232 |
|
| 2233 |
You can see in the formula above that if both input Sounds are expressed in units of Pa, |
| 2234 |
the resulting Sound should ideally be expressed in Pa^^2^s. |
| 2235 |
Nevertheless, Praat will express it in Pa, because Sounds cannot be expressed otherwise. |
| 2236 |
|
| 2237 |
This basically means that it is impossible to get the amplitude of the resulting Sound correct for all purposes. |
| 2238 |
For this reason, Praat considers a different definition of cross-correlation as well, namely as the #sum |
| 2239 |
~ cross-corr (%f, %g) [%\ta] \=3 \su_%t %f[%t] %g[%t+%\ta] |
| 2240 |
|
| 2241 |
The difference between the integral and sum definitions is that in the sum definition |
| 2242 |
the resulting sound is divided by %\Det. |
| 2243 |
|
| 2244 |
3. Normalized cross-correlation |
| 2245 |
=============================== |
| 2246 |
The %%normalized cross-correlation% is defined as |
| 2247 |
~ norm-cross-corr (%f, %g) (%\ta) \=3 \in %f(%t) %g(%t+%\ta) %dt |
| 2248 |
/ \Vr (\in %f^2(%t) %dt \in %g^2(%t) %dt) |
| 2249 |
|
| 2250 |
4. Shape scaling |
| 2251 |
================ |
| 2252 |
The boundaries of the integral in 1 are −\oo and +\oo. |
| 2253 |
However, %f and %g are Sound objects in Praat and therefore have finite time domains. |
| 2254 |
If %f runs from %t_1 to %t_2 and is assumed to be #zero before %t_1 and after %t_2, and |
| 2255 |
%g runs from %t_3 to %t_4 and is assumed to be zero outside that domain, |
| 2256 |
then the cross-correlation will be zero before %t_3−%t_2 and after %t_4−%t_1, |
| 2257 |
while between %t_3−%t_2 and %t__4_−%t_1 it is |
| 2258 |
~ cross-corr (%f, %g) (%\ta) = \in__%t1_^^%t2^ %f(%t) %g(%t+%\ta) %dt |
| 2259 |
|
| 2260 |
In this formula, the argument of %f runs from %t_1 to %t_2, |
| 2261 |
but the argument of %g runs from %t_1+(%t_3−%t_2) to %t_2+(%t_4−%t_1), |
| 2262 |
i.e. from %t_3−(%t_2−%t_1) to %t_4+(%t_2−%t_1). |
| 2263 |
This means that the integration is performed over two equal stretches of time during which %g must be taken zero, |
| 2264 |
namely a time stretch before %t_3 and a time stretch after %t_4, both of duration %t_2−%t_1 |
| 2265 |
(equivalent equations can be formulated that rely on two stretches of %t_4−%t_3 of zeroes in %f rather than in %g, |
| 2266 |
or on a stretch of %t_2−%t_1 of zeroes in %g and a stretch of %t_4−%t_3 of zeroes in %f. |
| 2267 |
|
| 2268 |
If you consider the sounds outside their time domains as #similar to what they are within their time domains, instead of #zero, |
| 2269 |
the discretized formula in 1 should be based on the average over the jointly defined values of %f[%\ta] and %g[%t−%\ta], |
| 2270 |
without counting any multiplications of values outside the time domains. |
| 2271 |
Suppose that %f is defined on the time domain [0, 1.2] with the value of 1 everywhere, |
| 2272 |
and %g is defined on the time domain [0, 3] with the value 1 everywhere. |
| 2273 |
Their cross-correlation under the assumption that they are #zero elsewhere is then |
| 2274 |
{ 5x3 |
| 2275 |
short = Create Sound from formula: "short", 1, 0.0, 1.2, 1000, ~ 1 |
| 2276 |
long = Create Sound from formula: "long", 1, 0.0, 3.0, 1000, ~ 1 |
| 2277 |
plusObject: short |
| 2278 |
Cross-correlate: "integral", "zero" |
| 2279 |
Draw: 0, 0, 0.0, 1.5, "yes", "curve" |
| 2280 |
One mark left: 1.2, "yes", "yes", "yes", "" |
| 2281 |
} |
| 2282 |
but under the assumption that the sounds are #similar (i.e. 1) elsewhere, their cross-correlation should be |
| 2283 |
{ 5x3 |
| 2284 |
selectObject: short, long |
| 2285 |
Cross-correlate: "integral", "similar" |
| 2286 |
Draw: 0, 0, 0.0, 1.5, "yes", "curve" |
| 2287 |
One mark left: 1.2, "yes", "yes", "yes", "" |
| 2288 |
} |
| 2289 |
|
| 2290 |
i.e. a constant value of 1.2. This is what you get by choosing the #similar option; |
| 2291 |
if %f is shorter than %g, the first and last parts of the cross-correlation will be divided by a straight line of duration %t_2−%t_1 |
| 2292 |
to compensate for the fact that the cross-correlation has been computed over fewer values of %f and %g there. |
| 2293 |
|
| 2294 |
5. Behaviour |
| 2295 |
============ |
| 2296 |
|
| 2297 |
The start time of the resulting Sound will be the start time of %f minus the end time of %g, |
| 2298 |
the end time of the resulting Sound will be the end time of %f minus the start time of %g, |
| 2299 |
the time of the first sample of the resulting Sound will be the first sample of %f minus the last sample of %g, |
| 2300 |
the time of the last sample of the resulting Sound will be the last sample of %f minus the first sample of %g, |
| 2301 |
and the number of samples in the resulting Sound will be the sum of the numbers of samples of %f and %g minus 1. |
| 2302 |
|
| 2303 |
6. Behaviour for stereo and other multi-channel sounds |
| 2304 |
====================================== |
| 2305 |
|
| 2306 |
You can cross-correlate e.g. a 10-channel sound either with another 10-channel sound or with a 1-channel (mono) sound. |
| 2307 |
|
| 2308 |
If both Sounds have more than one channel, the two Sounds have to have the same number of channels; |
| 2309 |
each channel of the resulting Sound is then computed as the cross-correlation of the corresponding channels |
| 2310 |
of the original Sounds. For instance, if you cross-correlate two 10-channel sounds, |
| 2311 |
the resulting sound will have 10 channels, and its 9th channel will be the cross-correlation of the 9th channels |
| 2312 |
of the two original sounds. |
| 2313 |
|
| 2314 |
If one of the original Sounds has multiple channels and the other Sound has only one channel, |
| 2315 |
the resulting Sound will have multiple channels; each of these is computed as the cross-correlation of |
| 2316 |
the corresponding channel of the multiple-channel original and the single channel of the single-channel original. |
| 2317 |
For instance, if you cross-correlate a 10-channel sound with a mono sound, |
| 2318 |
the resulting sound will have 10 channels, and its 9th channel will be the cross-correlation of the mono sound |
| 2319 |
with the 9th channel of the original 10-channel sound. |
| 2320 |
|
| 2321 |
The amplitude scaling factor will be the same for all channels, so that the relative amplitude of the channels |
| 2322 |
will be preserved in the resulting sound. For the #normalize scaling, for instance, the norm of %f in the formula above |
| 2323 |
is taken over all channels of %f. For the ##peak 0.99# scaling, the resulting sound will typically have an absolute peak |
| 2324 |
of 0.99 in only one channel, and lower absolute peaks in the other channels. |
| 2325 |
|
| 2326 |
7. Algorithm |
| 2327 |
============ |
| 2328 |
|
| 2329 |
The computation makes use of the fact that cross-correlation in the time domain corresponds to multiplication |
| 2330 |
of the time-reversal of %f with %g in the frequency domain: |
| 2331 |
we first pad %f with a stretch of %t_4−%t_3 of zeroes and %g with a stretch of %t_2−%t_1 of zeroes (see 4 above), |
| 2332 |
so that both sounds obtain a duration of (%t_2−%t_1) + (%t_4−%t_3); |
| 2333 |
we then calculate the spectra of the two zero-padded sounds by Fourier transformation, |
| 2334 |
then multiply the complex conjugate of the spectrum of %f with the spectrum of %g, |
| 2335 |
and finally Fourier-transform the result of this multiplication back to the time domain; |
| 2336 |
the result will again have a duration of (%t_2−%t_1) + (%t_4−%t_3). |
| 2337 |
|
| 2338 |
################################################################################ |
| 2339 |
"Sound: Autocorrelate..." |
| 2340 |
© David Weenink & Paul Boersma 2010-04-04,2024 |
| 2341 |
|
| 2342 |
A command available in the #Periodicity menu when you select one or more @Sound objects. |
| 2343 |
This command autocorrelates the selected @Sound object. |
| 2344 |
As a result, a new Sound will appear in the list of objects; |
| 2345 |
this new Sound is the %autocorrelation of the original Sound. |
| 2346 |
|
| 2347 |
Settings |
| 2348 |
======== |
| 2349 |
|
| 2350 |
##Amplitude scaling |
| 2351 |
: Here you can choose between the “principled” options #integral, #sum, and #normalize, which are explained in 1, 2 and 3 below. |
| 2352 |
There is also a “pragmatic” option, namely ##peak 0.99#, which scales the resulting sound in such a way |
| 2353 |
that its absolute peak becomes 0.99, so that the sound tends to be clearly audible without distortion when you play it |
| 2354 |
(see @@Sound: Scale peak...@). |
| 2355 |
|
| 2356 |
##Signal outside time domain is... |
| 2357 |
: Here you can choose whether outside its time domain the sound is considered to be #zero |
| 2358 |
(the standard value), or #similar to the sound within the time domain. |
| 2359 |
This is explained in 4 below. |
| 2360 |
//DEFINITION (U"Here you can choose whether outside its time domain the sound is considered to be #zero |
| 2361 |
//(the standard value), or #similar to the sound within the time domain, or #periodic, i.e. that |
| 2362 |
//outside the time domain the waveforms is a repetition of the waveform within the time domain. |
| 2363 |
//This is explained in 4 below. |
| 2364 |
|
| 2365 |
1. Autocorrelation as an integral |
| 2366 |
================================= |
| 2367 |
|
| 2368 |
The autocorrelation of a continuous time signal %f(%t) is a function of the lag time %\ta, |
| 2369 |
and defined as the #integral |
| 2370 |
~ %R_%f (%\ta) \=3 \in %f(%t) %f(%t+%\ta) %dt |
| 2371 |
|
| 2372 |
If %f is a sampled signal (as Sounds are in Praat), with @@sampling period@ %\Det, |
| 2373 |
the definition is discretized as |
| 2374 |
~ %R_%f [%\ta] \=3 \su_%t %f[%t] %f[%t+%\ta] %\Det |
| 2375 |
|
| 2376 |
where %\ta and %t+%\ta are the discrete times at which %f is defined. |
| 2377 |
|
| 2378 |
The autocorrelation is symmetric: %R_%f (−%\ta) = %R_%f (%\ta). |
| 2379 |
|
| 2380 |
2. Autocorrelation as a sum |
| 2381 |
=========================== |
| 2382 |
|
| 2383 |
You can see in the formula above that if the input Sound is expressed in units of Pa, |
| 2384 |
the resulting Sound should ideally be expressed in Pa^2s. |
| 2385 |
Nevertheless, Praat will express it in Pa, because Sounds cannot be expressed otherwise. |
| 2386 |
|
| 2387 |
This basically means that it is impossible to get the amplitude of the resulting Sound correct for all purposes. |
| 2388 |
For this reason, Praat considers a different definition of autocorrelation as well, namely as the #sum |
| 2389 |
~ %R_%f [%\ta] \=3 \su_%t %f[%t] %g[%t+%\ta] |
| 2390 |
|
| 2391 |
The difference between the integral and sum definitions is that in the sum definition |
| 2392 |
the resulting sound is divided by %\Det. |
| 2393 |
|
| 2394 |
3. Normalized autocorrelation |
| 2395 |
============================= |
| 2396 |
|
| 2397 |
The %%normalized autocorrelation% is defined as |
| 2398 |
~ norm-autocorr (%f) (%\ta) \=3 \in %f(%t) %f(%t+%\ta) %dt / \in %f^2(%t) %dt |
| 2399 |
|
| 2400 |
4. Shape scaling |
| 2401 |
================ |
| 2402 |
|
| 2403 |
The boundaries of the integral in 1 are −\oo and +\oo. |
| 2404 |
However, %f is a Sound object in Praat and therefore has a finite time domain. |
| 2405 |
If %f runs from %t_1 to %t_2 and is assumed to be #zero before %t_1 and after %t_2, |
| 2406 |
then the autocorrelation will be zero before %t_1−%t_2 and after %t_2−%t_1, |
| 2407 |
while between %t_1−%t_2 and %t_2−%t_1 it is |
| 2408 |
~ %R_%f (%\ta) = \in__%t1_^^%t2^ %f(%t) %f(%t+%\ta) %dt |
| 2409 |
|
| 2410 |
In this formula, the argument of the first %f runs from %t_1 to %t_2, |
| 2411 |
but the argument of the second %f runs from %t_1+(%t_1−%t_2) to %t_2+(%t_2−%t_1), |
| 2412 |
i.e. from %t_1−(%t_2−%t_1) to %t_2+(%t_2−%t_1). |
| 2413 |
This means that the integration is performed over two equal stretches of time during which %f must be taken zero, |
| 2414 |
namely a time stretch before %t_1 and a time stretch after %t_2, both of duration %t_2−%t_1. |
| 2415 |
|
| 2416 |
If you consider the sound outside its time domains as #similar to what it is within its time domain, instead of #zero, |
| 2417 |
the discretized formula in 1 should be based on the average over the jointly defined values of %f[%\ta] and %f[%t-%\ta], |
| 2418 |
without counting any multiplications of values outside the time domain. |
| 2419 |
Suppose that %f is defined on the time domain [0, 1.2] with the value of 1 everywhere. |
| 2420 |
Its autocorrelation under the assumption that it is #zero elsewhere is then |
| 2421 |
{ 5x3 |
| 2422 |
Create Sound from formula: "sound", 1, 0.0, 1.2, 1000, ~ 1 |
| 2423 |
Autocorrelate: "integral", "zero" |
| 2424 |
Draw: 0, 0, 0.0, 1.5, "yes", "curve" |
| 2425 |
One mark left: 1.2, "yes", "yes", "yes", "" |
| 2426 |
} |
| 2427 |
but under the assumption that the sound is #similar (i.e. 1) elsewhere, its autocorrelation should be |
| 2428 |
{ 5x3 |
| 2429 |
Create Sound from formula: "sound", 1, 0.0, 1.2, 1000, ~ 1 |
| 2430 |
Autocorrelate: "integral", "similar" |
| 2431 |
Draw: 0, 0, 0.0, 1.5, "yes", "curve" |
| 2432 |
One mark left: 1.2, "yes", "yes", "yes", "" |
| 2433 |
} |
| 2434 |
i.e. a constant value of 1.2. This is what you get by choosing the #similar option; |
| 2435 |
the autocorrelation will be divided by a triangular function |
| 2436 |
to compensate for the fact that the autocorrelation has been computed over fewer values closer to the edges; |
| 2437 |
this procedure is followed in all autocorrelation-based pitch computations in Praat (see @@Sound: To Pitch...@). |
| 2438 |
For examples, see @@Boersma (1993)@. |
| 2439 |
|
| 2440 |
5. Behaviour |
| 2441 |
============ |
| 2442 |
|
| 2443 |
The start time of the resulting Sound will be the start time of %f minus the end time of %f, |
| 2444 |
the end time of the resulting Sound will be the end time of %f minus the start time of %f, |
| 2445 |
the time of the first sample of the resulting Sound will be the first sample of %f minus the last sample of %f, |
| 2446 |
the time of the last sample of the resulting Sound will be the last sample of %f minus the first sample of %f, |
| 2447 |
and the number of samples in the resulting Sound will be twice the number of samples of %f, minus 1. |
| 2448 |
|
| 2449 |
6. Behaviour for stereo and other multi-channel sounds |
| 2450 |
====================================== |
| 2451 |
|
| 2452 |
If the selected Sound has more than one channel, each channel of the resulting Sound is computed |
| 2453 |
as the cross-correlation of the corresponding channel |
| 2454 |
of the original Sound. For instance, if you autocorrelate a 10-channel sound, |
| 2455 |
the resulting sound will again have 10 channels, and its 9th channel will be the autocorrelation of the 9th channel |
| 2456 |
of the original sound. |
| 2457 |
|
| 2458 |
The amplitude scaling factor will be the same for all channels, so that the relative amplitude of the channels |
| 2459 |
will be preserved in the resulting sound. For the #normalize scaling, for instance, the squared norm of %f in the formula above |
| 2460 |
is taken over all channels of %f. For the ##peak 0.99# scaling, the resulting sound will typically have an absolute peak |
| 2461 |
of 0.99 in only one channel, and lower absolute peaks in the other channels. |
| 2462 |
|
| 2463 |
Algorithm |
| 2464 |
========= |
| 2465 |
|
| 2466 |
The autocorrelation is calculated as the @@Sounds: Cross-correlate...|cross-correlation@ of a sound with itself. |
| 2467 |
|
| 2468 |
################################################################################ |
| 2469 |
"Sound: Scale intensity..." |
| 2470 |
© Paul Boersma 2012-06-14 |
| 2471 |
|
| 2472 |
A command available in the #Modify menu when you select one or more @Sound objects. |
| 2473 |
With this command you multiply the amplitude of each Sound in such a way that its average (i.e. root-mean-square) intensity becomes |
| 2474 |
the ##new average intensity# that you specify (see Settings). |
| 2475 |
|
| 2476 |
Settings |
| 2477 |
======== |
| 2478 |
|
| 2479 |
##New average intensity (dB SPL) |
| 2480 |
: the new average intensity of the Sound. The standard value is 70 dB SPL. This means that the root-mean-square amplitude |
| 2481 |
of the sound will come to lie 70 dB above the assumed auditory threshold of 0.00002 Pa. Please check whether as a result a peak in the sound |
| 2482 |
does not get below -1 Pa or above +1 Pa. If that happens, the sound will be clipped when played, which will be audible as distortion; |
| 2483 |
in that case you may want to set this number to 60 dB or even lower. |
| 2484 |
|
| 2485 |
################################################################################ |
| 2486 |
"Sound: Scale peak..." |
| 2487 |
© Paul Boersma 2010-03-28,2024 |
| 2488 |
|
| 2489 |
A command available in the #Modify menu when you select one or more @Sound objects. |
| 2490 |
With this command you multiply the amplitude of each Sound in such a way that its absolute peak becomes |
| 2491 |
the ##new absolute peak# that you specify (see Settings). |
| 2492 |
|
| 2493 |
Settings |
| 2494 |
======== |
| 2495 |
|
| 2496 |
##New absolute peak |
| 2497 |
: the new absolute peak of the Sound. The standard value is 0.99: this maximizes the audibility of the Sound |
| 2498 |
(sounds with lower amplitude are weaker) without distorting it |
| 2499 |
(sounds with absolute peaks above 1 are clipped when they are played). |
| 2500 |
|
| 2501 |
Examples |
| 2502 |
======== |
| 2503 |
|
| 2504 |
The absolute peak of the following sound is 0.033: |
| 2505 |
{ 6.0x3.0 |
| 2506 |
Create Sound from formula: "033", 1, 0.0, 0.1, 10000, |
| 2507 |
... ~ -0.02 * (sin (2 * pi * 205 * x) + sin (2 * pi * 5 * x)) + 0.007 |
| 2508 |
Draw: 0, 0, -0.033, 0.0247, "yes", "curve" |
| 2509 |
} |
| 2510 |
|
| 2511 |
This sound will play rather weakly. To make it louder, you can do ##Scale peak...# with a ##new absolute peak# of 0.99. |
| 2512 |
Praat will then multiply the waveform by 30, changing the sound to the following: |
| 2513 |
{ 6.0x3.0 |
| 2514 |
Scale peak: 0.99 |
| 2515 |
Draw: 0, 0, -0.99, 0.741, "yes", "curve" |
| 2516 |
} |
| 2517 |
|
| 2518 |
The absolute peak is now 0.99, and the sound will play loudly. |
| 2519 |
|
| 2520 |
The reverse is also possible. The absolute peak of the following sound is 19.8: |
| 2521 |
{ 6.0x3.0 |
| 2522 |
Create Sound from formula: "198", 1, 0.0, 0.1, 10000, |
| 2523 |
... ~ 12 * (sin (2 * pi * 305 * x) + sin (2 * pi * 5 * x)) - 4.2 |
| 2524 |
Draw: 0, 0, -15.28, 19.8, "yes", "curve" |
| 2525 |
} |
| 2526 |
|
| 2527 |
This sound will not play correctly: all samples with an amplitude outside the [-1;+1] range will be clipped to -1 or +1. |
| 2528 |
To make this sound nicer to play, you can again do ##Scale peak...# with a ##new absolute peak# of 0.99. |
| 2529 |
Praat will then divide the waveform by 20, changing the sound to the following: |
| 2530 |
{ 6.0x3.0 |
| 2531 |
Scale peak: 0.99 |
| 2532 |
Draw: 0, 0, -0.764, 0.99, "yes", "curve" |
| 2533 |
} |
| 2534 |
|
| 2535 |
The absolute peak is now 0.99, and the sound will play without distortion. |
| 2536 |
)~~~" |
| 2537 |
MAN_PAGES_END |
| 2538 |
|
| 2539 |
} |
| 2540 |
|
| 2541 |
/* End of file manual_sound.cpp */ |