| 1 | /* manual_spectrum.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2008,2010-2012,2014-2017,2019-2023,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 | |
| 23 | enum class Decoration { |
| 24 | None, |
| 25 | Minimal, |
| 26 | Fancy, |
| 27 | }; |
| 28 | |
| 29 | static void draw_SpectrumHann (Graphics g, double f1, double f2, bool stop, Decoration garnish) { |
| 30 | try { |
| 31 | const double fmin = ( garnish == Decoration::Fancy ? 300 : 0 ); |
| 32 | const double fmax = ( garnish == Decoration::Fancy ? 1300 : 4000 ); |
| 33 | const double df = ( garnish == Decoration::Fancy ? 1 : 4 ); |
| 34 | autoSound me = Sound_create (1, fmin, fmax, (long) floor ((fmax - fmin) / df) + 1, df, fmin); |
| 35 | constexpr double w = 100.0; |
| 36 | const double f1left = f1 - w, f1right = f1 + w, f2left = f2 - w, f2right = f2 + w; |
| 37 | constexpr double halfpibysmooth = NUMpi / (w + w); |
| 38 | Graphics_setWindow (g, fmin, fmax, -0.1, 1.1); |
| 39 | for (integer i = 1; i <= my nx; i ++) { |
| 40 | const double f = my x1 + (i - 1) * my dx; |
| 41 | my z [1] [i] = ( |
| 42 | f < f1left ? |
| 43 | 0.0 |
| 44 | : f < f1right ? |
| 45 | ( f1 > 0.0 ? 0.5 - 0.5 * cos (halfpibysmooth * (f - f1left)) : 1.0 ) |
| 46 | : f < f2left ? |
| 47 | 1.0 |
| 48 | : f < f2right ? |
| 49 | ( f2 < fmax ? 0.5 + 0.5 * cos (halfpibysmooth * (f - f2left)) : 1.0 ) |
| 50 | : |
| 51 | 0.0 |
| 52 | ); |
| 53 | } |
| 54 | if (stop) |
| 55 | for (integer i = 1; i <= my nx; i ++) |
| 56 | my z [1] [i] = 1.0 - my z [1] [i]; |
| 57 | if (garnish != Decoration::None) { |
| 58 | Graphics_drawInnerBox (g); |
| 59 | Graphics_textLeft (g, true, U"Amplitude filter %H (%f)"); |
| 60 | Graphics_markLeft (g, 0.0, true, true, false, nullptr); |
| 61 | Graphics_markLeft (g, 1.0, true, true, false, nullptr); |
| 62 | } |
| 63 | if (garnish == Decoration::Minimal) { |
| 64 | Graphics_textBottom (g, true, U"Frequency %f (Hz)"); |
| 65 | Graphics_markBottom (g, 0.0, true, true, false, nullptr); |
| 66 | Graphics_markBottom (g, 500.0, true, true, false, nullptr); |
| 67 | Graphics_markBottom (g, 1000.0, true, true, false, nullptr); |
| 68 | Graphics_markBottom (g, 2000.0, true, true, false, nullptr); |
| 69 | Graphics_markBottom (g, 4000.0, true, true, false, nullptr); |
| 70 | } |
| 71 | if (garnish == Decoration::Fancy) { |
| 72 | Graphics_textBottom (g, true, U"Frequency %f"); |
| 73 | Graphics_markBottom (g, f1left, false, true, true, U"%f__1_-%w"); |
| 74 | Graphics_markBottom (g, f1, false, true, true, U"%f__1_"); |
| 75 | Graphics_markBottom (g, f1right, false, true, true, U"%f__1_+%w"); |
| 76 | Graphics_markBottom (g, f2left, false, true, true, U"%f__2_-%w"); |
| 77 | Graphics_markBottom (g, f2, false, true, true, U"%f__2_"); |
| 78 | Graphics_markBottom (g, f2right, false, true, true, U"%f__2_+%w"); |
| 79 | Graphics_markRight (g, 1.0, false, true, false, U"0 dB"); |
| 80 | Graphics_markLeft (g, 0.5, true, true, true, nullptr); |
| 81 | Graphics_markRight (g, 0.5, false, true, false, U"-6 dB"); |
| 82 | } |
| 83 | Graphics_setColour (g, stop ? Melder_BLUE : Melder_RED); |
| 84 | Sound_draw (me.get(), g, 0.0, 0.0, -0.1, 1.1, false, U"curve"); |
| 85 | Graphics_setColour (g, Melder_BLACK); |
| 86 | } catch (MelderError) { |
| 87 | Melder_clearError (); |
| 88 | } |
| 89 | } |
| 90 | static void draw_SpectrumPassHann (Graphics g) { |
| 91 | draw_SpectrumHann (g, 500.0, 1000.0, false, Decoration::Fancy); |
| 92 | } |
| 93 | static void draw_SpectrumPassHann_decompose (Graphics g) { |
| 94 | draw_SpectrumHann (g, 0.0, 500.0, false, Decoration::Minimal); |
| 95 | draw_SpectrumHann (g, 500, 1000, false, Decoration::None); |
| 96 | draw_SpectrumHann (g, 1000, 2000, false, Decoration::None); |
| 97 | draw_SpectrumHann (g, 2000, 4000, false, Decoration::None); |
| 98 | } |
| 99 | static void draw_SpectrumStopHann (Graphics g) { |
| 100 | draw_SpectrumHann (g, 500, 1000, true, Decoration::Fancy); |
| 101 | } |
| 102 | static void draw_SpectrumStopHann_decompose (Graphics g) { |
| 103 | draw_SpectrumHann (g, 500.0, 1000.0, false, Decoration::Minimal); |
| 104 | draw_SpectrumHann (g, 500.0, 1000.0, true, Decoration::None); |
| 105 | } |
| 106 | |
| 107 | void manual_spectrum_init (ManPages me); |
| 108 | void manual_spectrum_init (ManPages me) { |
| 109 | |
| 110 | MAN_PAGES_BEGIN |
| 111 | R"~~~( |
| 112 | ################################################################################ |
| 113 | "Ltas" |
| 114 | © Paul Boersma 2007-03-20 |
| 115 | |
| 116 | One of the @@types of objects@ in Praat. |
| 117 | #Ltas is short for Long-Term Average Spectrum. |
| 118 | |
| 119 | An object of class Ltas represents the logarithmic @@power spectral density@ as a function of frequency, |
| 120 | expressed in dB/Hz relative to 2·10^^-5^ Pa. |
| 121 | |
| 122 | Inside an Ltas object |
| 123 | ===================== |
| 124 | |
| 125 | With @Inspect, you will see the following attributes: |
| 126 | |
| 127 | %x__%min_ |
| 128 | : the bottom of the frequency domain, in hertz. Usually 0. |
| 129 | |
| 130 | %x__%max_ |
| 131 | : the top of the frequency domain, in hertz. |
| 132 | |
| 133 | %n__%x_ |
| 134 | : the number of frequency bins (≥ 1). |
| 135 | |
| 136 | %dx |
| 137 | : the frequency step, or %%bin width%, in hertz. |
| 138 | |
| 139 | %x__1_ |
| 140 | : the frequency associated with the first bin, in hertz. |
| 141 | Usually equals %dx / 2, because the first bin tends to start at 0 hertz. |
| 142 | |
| 143 | %z__1%i_, %i = 1 ... %n__%x_ |
| 144 | : the power spectral density, expressed in dB. |
| 145 | |
| 146 | ################################################################################ |
| 147 | "Ltas: Average" |
| 148 | © Paul Boersma 2023-05-03 |
| 149 | |
| 150 | The command ##Average# becomes available under Combine when you select one or more Ltas objects. |
| 151 | |
| 152 | When you choose ##Average#, a new @Ltas called “averaged” will appear in the list of objects. |
| 153 | This new Ltas will contain the average of the Ltases that you had selected. |
| 154 | |
| 155 | Algorithm |
| 156 | ========= |
| 157 | The averaging takes place in the energy domain. For instance, if you select three Ltases, |
| 158 | the values in the three Ltases will be converted from dB to Pa^2, |
| 159 | then added up, then divided by 3, then converted from Pa^2 to dB. |
| 160 | |
| 161 | ################################################################################ |
| 162 | )~~~" |
| 163 | MAN_PAGES_END |
| 164 | |
| 165 | MAN_BEGIN (U"Ltas: Get bin number from frequency...", U"ppgb", 20140421) |
| 166 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 167 | ENTRY (U"Return bin") |
| 168 | NORMAL (U"the band number belonging to the specified frequency, expressed as a real number.") |
| 169 | ENTRY (U"Example") |
| 170 | NORMAL (U"If the Ltas has a bin width of 1000 Hz, and the lowest frequency is 0 Hz, " |
| 171 | "the bin number associated with a frequency of 1800 Hz is 2.3.") |
| 172 | ENTRY (U"Scripting") |
| 173 | NORMAL (U"You can use this command to put the nearest bin centre into a script variable:") |
| 174 | CODE (U"selectObject: \"Ltas hallo\"") |
| 175 | CODE (U"bin = Get bin number from frequency: 1800") |
| 176 | CODE (U"nearestBin = round (bin)") |
| 177 | NORMAL (U"In this case, the value will not be written into the Info window. To round down or up, use") |
| 178 | CODE (U"leftBin = floor (bin)") |
| 179 | CODE (U"rightBin = ceiling (bin)") |
| 180 | MAN_END |
| 181 | |
| 182 | MAN_BEGIN (U"Ltas: Get bin width", U"ppgb", 20041122) |
| 183 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 184 | ENTRY (U"Return value") |
| 185 | NORMAL (U"the with of a bin, expressed in hertz.") |
| 186 | MAN_END |
| 187 | |
| 188 | MAN_BEGIN (U"Ltas: Get frequency from bin number...", U"ppgb", 20041122) |
| 189 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 190 | ENTRY (U"Return value") |
| 191 | NORMAL (U"the frequency (in hertz) associated with a specified bin number.") |
| 192 | ENTRY (U"Setting") |
| 193 | TERM (U"##Bin number") |
| 194 | DEFINITION (U"the bin number whose frequency is sought.") |
| 195 | ENTRY (U"Algorithm") |
| 196 | NORMAL (U"the result is") |
| 197 | EQUATION (U"%f__1_ + (%binNumber - 1) · Δ%f") |
| 198 | NORMAL (U"where %f__1_ is the frequency associated with the centre of the first bin, " |
| 199 | "and Δ%f is the bin width.") |
| 200 | MAN_END |
| 201 | |
| 202 | MAN_BEGIN (U"Ltas: Get frequency of maximum...", U"ppgb", 20200912) |
| 203 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 204 | ENTRY (U"Return value") |
| 205 | NORMAL (U"the frequency (in hertz) associated with the maximum energy density.") |
| 206 | ENTRY (U"Settings") |
| 207 | TERM (U"##From frequency (Hz)") |
| 208 | TERM (U"##To frequency (Hz)") |
| 209 | DEFINITION (U"the selected frequency domain. Values outside this domain are ignored. " |
| 210 | "If ##To frequency# is not greater than ##From frequency#, " |
| 211 | "the entire frequency domain of the Ltas object is considered.") |
| 212 | TERM (U"##Interpolation") |
| 213 | DEFINITION (U"the interpolation method (#none, #parabolic, #cubic, #sinc70, #sinc700) of the @@vector peak interpolation@. " |
| 214 | "The standard is #none because of the usual large binning. " |
| 215 | "If the Ltas was computed with @@Spectrum: To Ltas (1-to-1)@, " |
| 216 | "a #parabolic or #cubic interpolation would be more appropriate.") |
| 217 | MAN_END |
| 218 | |
| 219 | MAN_BEGIN (U"Ltas: Get frequency of minimum...", U"ppgb", 20200912) |
| 220 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 221 | ENTRY (U"Return value") |
| 222 | NORMAL (U"the frequency (in hertz) associated with the minimum energy density.") |
| 223 | ENTRY (U"Settings") |
| 224 | TERM (U"##Time range (s)") |
| 225 | DEFINITION (U"the time range (%t__1_, %t__2_). Values outside this range are ignored. " |
| 226 | "If %t__1_ is not less than %t__2_, the entire frequency domain of the Ltas is considered.") |
| 227 | TERM (U"%%Interpolation") |
| 228 | DEFINITION (U"the interpolation method (#none, #parabolic, #cubic, #sinc) of the @@vector peak interpolation@. " |
| 229 | "The standard is #none because of the usual large binning. " |
| 230 | "If the Ltas was computed with @@Spectrum: To Ltas (1-to-1)@, " |
| 231 | "a #parabolic or #cubic interpolation would be more appropriate.") |
| 232 | MAN_END |
| 233 | |
| 234 | MAN_BEGIN (U"Ltas: Get highest frequency", U"ppgb", 20041122) |
| 235 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 236 | ENTRY (U"Return value") |
| 237 | NORMAL (U"the highest frequency, expressed in hertz.") |
| 238 | MAN_END |
| 239 | |
| 240 | MAN_BEGIN (U"Ltas: Get lowest frequency", U"ppgb", 20041122) |
| 241 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object for its lowest frequency.") |
| 242 | ENTRY (U"Return value") |
| 243 | NORMAL (U"the lowest frequency, expressed in Hertz. It is usually 0 Hz.") |
| 244 | MAN_END |
| 245 | |
| 246 | MAN_BEGIN (U"Ltas: Get maximum...", U"ppgb", 20200912) |
| 247 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 248 | ENTRY (U"Return value") |
| 249 | NORMAL (U"the maximum value (in dB) within a specified frequency range.") |
| 250 | ENTRY (U"Settings") |
| 251 | TERM (U"##From frequency (Hz))") |
| 252 | TERM (U"##To frequency (Hz)") |
| 253 | DEFINITION (U"the selected frequency domain. Values outside this domain are ignored. " |
| 254 | "If %%To frequency% is not greater than %%From frequency%, " |
| 255 | "the entire frequency domain of the Ltas object is considered.") |
| 256 | TERM (U"%%Interpolation") |
| 257 | DEFINITION (U"the interpolation method (#none, #parabolic, #cubic, #sinc70, #sinc700) of the @@vector peak interpolation@. " |
| 258 | "The standard is #none because of the usual large binning. " |
| 259 | "If the Ltas was computed with @@Spectrum: To Ltas (1-to-1)@, " |
| 260 | "a #parabolic or #cubic interpolation would be more appropriate.") |
| 261 | MAN_END |
| 262 | |
| 263 | MAN_BEGIN (U"Ltas: Get mean...", U"ppgb", 20041122) |
| 264 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 265 | ENTRY (U"Return value") |
| 266 | NORMAL (U"the mean value (in dB) within a specified frequency range.") |
| 267 | ENTRY (U"Settings") |
| 268 | TERM (U"##From frequency (Hz))") |
| 269 | TERM (U"##To frequency (Hz)") |
| 270 | DEFINITION (U"the frequency range. Values outside this range are ignored. " |
| 271 | "If ##To frequency# is not greater than ##From frequency#, the entire frequency domain of the Ltas is considered.") |
| 272 | ENTRY (U"Algorithm") |
| 273 | NORMAL (U"The mean value between the frequencies %f__1_ and %f__2_ is defined as") |
| 274 | EQUATION (U"1/(%f__2_ - %f__1_) ∫__%%f%1_^^%%f%2^ %df %x(%f)") |
| 275 | NORMAL (U"where %x(%f) is the LTAS as a function of frequency, expressed in dB. " |
| 276 | "For our discrete Ltas object, this mean is approximated by") |
| 277 | EQUATION (U"1/%n ∑__%i=%m..%m+%n-1_ %x__%i_") |
| 278 | NORMAL (U"where %n is the number of band centres between %f__1_ and %f__2_.") |
| 279 | MAN_END |
| 280 | |
| 281 | MAN_BEGIN (U"Ltas: Get minimum...", U"ppgb", 20200912) |
| 282 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 283 | ENTRY (U"Return value") |
| 284 | NORMAL (U"the minimum value (in dB) within a specified frequency range.") |
| 285 | ENTRY (U"Settings") |
| 286 | TERM (U"##From frequency (Hz))") |
| 287 | TERM (U"##To frequency (Hz)") |
| 288 | DEFINITION (U"the selected frequency domain. Values outside this domain are ignored. " |
| 289 | "If ##To frequency# is not greater than ##From frequency#, " |
| 290 | "the entire frequency domain of the Ltas object is considered.") |
| 291 | TERM (U"%%Interpolation") |
| 292 | DEFINITION (U"the interpolation method (#none, #parabolic, #cubic, #sinc70, #sinc700) of the @@vector peak interpolation@. " |
| 293 | "The standard is #none because of the usual large binning. " |
| 294 | "If the Ltas was computed with @@Spectrum: To Ltas (1-to-1)@, " |
| 295 | "a #parabolic or #cubic interpolation would be more appropriate.") |
| 296 | MAN_END |
| 297 | |
| 298 | MAN_BEGIN (U"Ltas: Get number of bins", U"ppgb", 20041122) |
| 299 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 300 | ENTRY (U"Return value") |
| 301 | NORMAL (U"the total number of frequency bins.") |
| 302 | MAN_END |
| 303 | |
| 304 | MAN_BEGIN (U"Ltas: Get standard deviation...", U"ppgb", 19991016) |
| 305 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 306 | ENTRY (U"Return value") |
| 307 | NORMAL (U"the standard deviation (in dB) of the LTAS within a specified frequency domain.") |
| 308 | ENTRY (U"Settings") |
| 309 | TERM (U"##From frequency (Hz))") |
| 310 | TERM (U"##To frequency (Hz)") |
| 311 | DEFINITION (U"the frequency window. Values outside this domain are ignored. " |
| 312 | "If ##To frequency# is not greater than ##From frequency#, the entire frequency domain of the Ltas is considered.") |
| 313 | ENTRY (U"Algorithm") |
| 314 | NORMAL (U"The standard deviation between the frequencies %f__1_ and %f__2_ is defined as") |
| 315 | EQUATION (U"1/(%f__2_ – %f__1_) ∫__%%f%1_^^%%f%2^ %df (%x(%f) – %μ)^2") |
| 316 | NORMAL (U"where %x(%f) is the LTAS as a function of frequency, and %μ its mean. " |
| 317 | "For our discrete Ltas object, the standard deviation is approximated by") |
| 318 | EQUATION (U"1/(%n–1) ∑__%i=%m..%m+%n-1_ (%x__%i_ – %μ)^2") |
| 319 | NORMAL (U"where %n is the number of band centres between %f__1_ and %f__2_. Note the \"minus 1\".") |
| 320 | MAN_END |
| 321 | |
| 322 | MAN_BEGIN (U"Ltas: Get value at frequency...", U"ppgb", 20101228) |
| 323 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 324 | ENTRY (U"Return value") |
| 325 | NORMAL (U"the value (in dB) at a specified frequency. " |
| 326 | "If %frequency is outside the bands of the Ltas, the result is 0.") |
| 327 | ENTRY (U"Settings") |
| 328 | TERM (U"##Frequency (Hz)") |
| 329 | DEFINITION (U"the frequency at which the value is to be evaluated.") |
| 330 | TERM (U"%%Interpolation") |
| 331 | DEFINITION (U"the interpolation method, see @@vector value interpolation@. " |
| 332 | "The standard is #None because binning is usually large.") |
| 333 | MAN_END |
| 334 | |
| 335 | MAN_BEGIN (U"Ltas: Get value in bin...", U"ppgb", 20041122) |
| 336 | INTRO (U"A @@Query submenu|query@ to the selected @Ltas object.") |
| 337 | ENTRY (U"Return value") |
| 338 | NORMAL (U"the LTAS value (in dB) in a specified bin. " |
| 339 | "If the bin number is less than 1 or greater than the number of bin, the result is 0; " |
| 340 | "otherwise, it is %z [1] [%%bin number%].") |
| 341 | ENTRY (U"Setting") |
| 342 | TERM (U"##Bin number") |
| 343 | DEFINITION (U"the bin whose value is to be looked up.") |
| 344 | MAN_END |
| 345 | |
| 346 | MAN_BEGIN (U"Sound: To Spectrogram...", U"ppgb", 20211015) |
| 347 | INTRO (U"A command that creates a @Spectrogram from every selected @Sound object. " |
| 348 | "It performs a %%short-term spectral analysis%, which means that for a number of time points in the Sound, " |
| 349 | "Praat computes an approximation of the spectrum at that time. Each such spectrum is called an %%analysis frame%.") |
| 350 | NORMAL (U"For tutorial information, see @@Intro 3. Spectral analysis@.") |
| 351 | ENTRY (U"Settings") |
| 352 | TERM (U"##Window length (s)") |
| 353 | DEFINITION (U"the duration of the analysis window, in seconds. If this is 0.005 seconds, Praat uses for each frame " |
| 354 | "the part of the sound that lies between 0.0025 seconds before and 0.0025 seconds after the centre of that frame " |
| 355 | "(for Gaussian windows, Praat actually uses a bit more than that). " |
| 356 | "The window length determines the %bandwidth of the spectral analysis, i.e. the width of the horizontal line " |
| 357 | "in the spectrogram of a pure sine wave. " |
| 358 | "For a Gaussian window, the -3 dB bandwidth is 2*sqrt(6*ln(2))/(%π*%%Window length%), " |
| 359 | "or 1.2982804 / %%Window length%. " |
| 360 | "To get a “broad-band” spectrogram (bandwidth 260 Hz), set %%Window length% to 5 milliseconds; " |
| 361 | "to get a “narrow-band” spectrogram (bandwidth 43 Hz), set it to 30 milliseconds. " |
| 362 | "The other window shapes give slightly different values.") |
| 363 | TERM (U"##Maximum frequency (Hz)") |
| 364 | DEFINITION (U"the maximum frequency subject to analysis, e.g. 5000 hertz. " |
| 365 | "If it is higher than the Nyquist frequency of the Sound (which is half its sampling frequency), " |
| 366 | "some values in the result will be zero (and will be drawn in white by @@Spectrogram: Paint...@).") |
| 367 | TERM (U"##Time step (s)") |
| 368 | DEFINITION (U"the distance between the centres of subsequent frames, e.g. 0.002 seconds. " |
| 369 | "This determines the number of frames of the resulting Spectrogram. For instance, if the Sound is 1 second long, " |
| 370 | "and the time step is 2 milliseconds, the Spectrogram will consist of almost 500 frames " |
| 371 | "(not %exactly 500, because no reliable spectrum can be measured near the beginning and end of the sound). " |
| 372 | "See below for cases in which the time step of the resulting Spectrogram is different from what you supply here.") |
| 373 | TERM (U"##Frequency step (Hz)") |
| 374 | DEFINITION (U"the frequency resolution, e.g. 20 Hertz. " |
| 375 | "This determines the number of frequency bands (%bins) of the resulting Spectrogram. For instance, if the %%Maximum frequency% " |
| 376 | "is 5000 Hz, and the frequency step is 20 Hz, the Spectrogram will consist of 250 frequency bands. " |
| 377 | "See below for cases in which the frequency step of the resulting Spectrogram is different from what you supply here.") |
| 378 | TERM (U"##Window shape") |
| 379 | DEFINITION (U"determines the shape of the analysis window. " |
| 380 | "You can choose from: #Gaussian, #Square (none, rectangular), #Hamming (raised sine-squared), " |
| 381 | "#Bartlett (triangular), #Welch (parabolic), and #Hanning (sine-squared). " |
| 382 | "The Gaussian window is superior, as it gives no sidelobes in your spectrogram; " |
| 383 | "it analyzes a factor of 2 slower than the other window shapes, " |
| 384 | "because the analysis is actually performed on twice as many samples per frame.") |
| 385 | NORMAL (U"For purposes of computation speed, Praat may decide to change the time step and the frequency step. " |
| 386 | "This is because the time step never needs to be smaller than 1/(8√%π) of the window length, " |
| 387 | "and the frequency step never needs to be smaller than (√%π)/8 of the inverse of the window length. " |
| 388 | "For instance, if the window length is 29 ms, the actual time step will never be less than 29/(8√%π) = 2.045 ms. " |
| 389 | "And if the window length is 5 ms, the actual frequency step will never be less than (√%π)/8/0.005 = 44.31 Hz.") |
| 390 | ENTRY (U"Tests of the bandwidth") |
| 391 | NORMAL (U"You can check the bandwidth formula with the following procedure:") |
| 392 | CODE (U"! create a 1000-Hz sine wave, windowed by a 0.2-seconds Gaussian window.") |
| 393 | CODE (U"Create Sound from formula: \"gauss\", 1, 0.0, 1.0, 44100, \"sin(2*pi*1000*x) * exp(-3*((x-0.5)/0.1)^2)\"") |
| 394 | CODE (U"! compute its spectrum and look at its bandwidth") |
| 395 | CODE (U"To Spectrum: \"yes\"") |
| 396 | CODE (U"Draw: 980, 1020, 20, 80, \"yes\"") |
| 397 | CODE (U"Marks bottom every: 1, 2, \"yes\", \"yes\", \"yes\"") |
| 398 | CODE (U"Marks left every: 1, 2, \"yes\", \"yes\", \"yes\"") |
| 399 | CODE (U"! now you should see a peak at 1000 Hz with a 3 dB bandwidth of 7 Hz (20 dB: 17 Hz)") |
| 400 | CODE (U"! more precise: compute the position and width of the peak, and write them to the console") |
| 401 | CODE (U"Formula: ~ if x<980 or x>1020 then 0 else self fi") |
| 402 | CODE (U"To Formant (peaks): 20") |
| 403 | CODE (U"List: \"no\", \"yes\", 6, \"no\", 3, \"yes\", 3, \"yes\"") |
| 404 | CODE (U"! now you should be able to read that a peak was found at 999.99982 Hz") |
| 405 | CODE (U"! with a bandwidth of 6.497 Hz; the theory above predicted 6.491 Hz") |
| 406 | CODE (U"") |
| 407 | CODE (U"! The same, windowed by a 0.1-seconds Hamming window.") |
| 408 | CODE (U"Create Sound from formula: \"Hamming\", 1, 0.0, 1.0, 44100, ~ if x<0.4 or x>0.6 then 0 else sin(2*pi*1000*x)*(0.54+0.46*cos(pi*(x-0.5)/0.1)) fi") |
| 409 | CODE (U"To Spectrum: \"yes\"") |
| 410 | CODE (U"Formula: ~ if x<970 or x>1030 then 0 else self fi") |
| 411 | CODE (U"To Formant (peaks): 20") |
| 412 | CODE (U"List: \"no\", \"yes\", 6, \"no\", 3, \"yes\", 3, \"yes\"") |
| 413 | CODE (U"! peak at 999.99817 Hz, 3 dB bw 6.518 Hz, 20 dB bw 15 Hz, zero bw 20 Hz, sidelobe -42 dB") |
| 414 | CODE (U"") |
| 415 | CODE (U"! The same, windowed by a 0.1-seconds rectangular window.") |
| 416 | CODE (U"Create Sound from formula: \"rectangular\", 1, 0.0, 1.0, 44100, ~ if x<0.4 or x>0.6 then 0 else sin(2*pi*1000*x) fi") |
| 417 | CODE (U"To Spectrum: \"yes\"") |
| 418 | CODE (U"Formula: ~ if x<970 or x>1030 then 0 else self fi") |
| 419 | CODE (U"To Formant (peaks): 20") |
| 420 | CODE (U"List: \"no\", \"yes\", 6, \"no\", 3, \"yes\", 3, \"yes\"") |
| 421 | CODE (U"! peak at 999.99506 Hz, 3 dB bw 4.440 Hz, 20 dB bw 27 Hz, zero bw 10 Hz, sidelobe -14 dB") |
| 422 | CODE (U"") |
| 423 | CODE (U"! The same, windowed by a 0.1-seconds Hanning window.") |
| 424 | CODE (U"Create Sound from formula: \"Hanning\", 1, 0.0, 1.0, 44100, ~ if x<0.4 or x>0.6 then 0 else sin(2*pi*1000*x)*(0.5+0.5*cos(pi*(x-0.5)/0.1)) fi") |
| 425 | CODE (U"To Spectrum: \"yes\"") |
| 426 | CODE (U"Formula: ~ if x<970 or x>1030 then 0 else self fi") |
| 427 | CODE (U"To Formant (peaks): 20") |
| 428 | CODE (U"List: \"no\", \"yes\", 6, \"no\", 3, \"yes\", 3, \"yes\"") |
| 429 | CODE (U"! peak at 999.99945 Hz, 3 dB bw 7.212 Hz, 20 dB bw 16 Hz, zero bw 20 Hz, sidelobe -31 dB") |
| 430 | CODE (U"") |
| 431 | CODE (U"! The same, windowed by a 0.1-seconds triangular window.") |
| 432 | CODE (U"Create Sound from formula: \"triangular\", 1, 0.0, 1.0, 44100, ~ if x<0.4 or x>0.6 then 0 else sin(2*pi*1000*x)*(1-abs((x-0.5)/0.1)) fi") |
| 433 | CODE (U"To Spectrum: \"yes\"") |
| 434 | CODE (U"Formula: ~ if x<970 or x>1030 then 0 else self fi") |
| 435 | CODE (U"To Formant (peaks): 20") |
| 436 | CODE (U"List: \"no\", \"yes\", 6, \"no\", 3, \"yes\", 3, \"yes\"") |
| 437 | CODE (U"! peak at 999.99933 Hz, 3 dB bw 6.384 Hz, 20 dB bw 15 Hz, zero bw 20 Hz, sidelobe -26 dB") |
| 438 | CODE (U"") |
| 439 | CODE (U"! The same, windowed by a 0.1-seconds parabolic window.") |
| 440 | CODE (U"Create Sound from formula: \"parabolic\", 1, 0.0, 1.0, 44100, ~ if x<0.4 or x>0.6 then 0 else sin(2*pi*1000*x)*(1-((x-0.5)/0.1)^2) fi") |
| 441 | CODE (U"To Spectrum: \"yes\"") |
| 442 | CODE (U"Formula: ~ if x<970 or x>1030 then 0 else self fi") |
| 443 | CODE (U"To Formant (peaks): 20") |
| 444 | CODE (U"List: \"no\", \"yes\", 6, \"no\", 3, \"yes\", 3, \"yes\"") |
| 445 | CODE (U"! peak at 999.99921 Hz, 3 dB bw 5.786 Hz, 20 dB bw 12 Hz, zero bw 15 Hz, sidelobe -21 dB") |
| 446 | MAN_END |
| 447 | |
| 448 | MAN_BEGIN (U"Sound: To Ltas (pitch-corrected)...", U"ppgb", 20061203) |
| 449 | INTRO (U"A command available in the #Spectrum menu if you select one or more @Sound objects. " |
| 450 | "It tries to compute an @Ltas of the spectral envelope of the voiced parts, " |
| 451 | "correcting away the influence of F0 in a way that does not sacrifice frequency selectivity. " |
| 452 | "The resulting Ltas is meant to reflect only the resonances (formants) in the vocal tract " |
| 453 | "and the envelope of the glottal source spectrum.") |
| 454 | NORMAL (U"The analysis method is described in @@Boersma & Kovacic (2006)@.") |
| 455 | MAN_END |
| 456 | |
| 457 | MAN_BEGIN (U"Sound: To Spectrum...", U"ppgb", 20041123) |
| 458 | INTRO (U"A command that appears in the #Spectrum menu if you select one or more @Sound objects. " |
| 459 | "It turns the selected Sound into a @Spectrum by an over-all spectral analysis, a %%Fourier transform%.") |
| 460 | ENTRY (U"Setting") |
| 461 | TERM (U"##Fast") |
| 462 | DEFINITION (U"determines whether zeroes are appended to the sound such that the number of samples is a power of two. " |
| 463 | "This can appreciably speed up the Fourier transform.") |
| 464 | ENTRY (U"Mathematical procedure") |
| 465 | NORMAL (U"For the Fourier transform, the Praat-defined @@time domain@ of the @Sound is ignored. " |
| 466 | "Instead, its time domain is considered to run from %t=0 to %t=%T, " |
| 467 | "where %t=0 is supposed to be aligned with the first sample, " |
| 468 | "and %T is the total duration of the samples, i.e. %%N%Δ%t, " |
| 469 | "where %N is the number of samples and Δ%t is the @@sampling period@. " |
| 470 | "Thus, the last sample lies at %t=%T–Δ%t.") |
| 471 | NORMAL (U"For a sound %x(%t), defined for all times %t in the domain (0, %T), " |
| 472 | "the complex spectrum %X(%f) for any frequency %f is the forward Fourier transform of %x(%t), with a negative exponent:") |
| 473 | EQUATION (U"%X(%f) = ∫__0_^^%T^ %x(%t) %e^^-2%%πift%^ %dt") |
| 474 | NORMAL (U"If the Sound is expressed in Pascal (Pa), the Spectrum is expressed in Pa·s, or Pa/Hz. " |
| 475 | "Since a @Spectrum object can only contain a finite number of frequency samples, " |
| 476 | "it is only computed for frequencies that are multiples of Δ%f = 1/%T. " |
| 477 | "The number of those frequencies is determined by the number of samples %N of the sound.") |
| 478 | NORMAL (U"If %N is odd, there will be %N frequency samples. For instance, if the sound has 20,457 samples, " |
| 479 | "the spectrum will be computed at the frequencies -10,228Δ%f, -10,227Δ%f, ..., –Δ%f, 0, +Δ%f, ..., " |
| 480 | "+10,227Δ%f, +10,228Δ%f. If we suppose that a frequency sample represents a frequency bin with a width of Δ%f, " |
| 481 | "we see that the frequency samples span adjacent frequency ranges, " |
| 482 | "e.g. the first sample runs from -10,228.5Δ%f to -10,227.5Δ%f, the second from -10,227.5Δ%f to -10,226.5Δ%f. " |
| 483 | "Together, the frequency samples span the frequency domain of the spectrum, " |
| 484 | "which runs from -%F to +%F, where %F = 10,228.5Δ%f. " |
| 485 | "We can see that this frequency equals one half of the @@sampling frequency@ of the original sound: " |
| 486 | "%F = 10,228.5Δ%f = 10,228.5/%T = 10,228.5/(20,457Δ%t) = 0.5/Δ%t. This is the so-called @@Nyquist frequency@.") |
| 487 | NORMAL (U"If %N is even, there will be %N+1 frequency samples. For instance, if the sound has 32,768 samples, " |
| 488 | "the spectrum will be computed at the frequencies -16,384Δ%f, -16,383Δ%f, ..., -Δ%f, 0, +Δ%f, ..., " |
| 489 | "+16,383Δ%f, +16,384Δ%f. Again, the frequency samples span adjacent frequency ranges, " |
| 490 | "but the first and last samples are only half as wide as the rest, " |
| 491 | "i.e. the first sample runs from -16,384Δ%f to -16,383.5Δ%f, the second from -16,383.5Δ%f to -16,382.5Δ%f, " |
| 492 | "and the last from +16,383.5Δ%f to +16,384Δ%f. " |
| 493 | "Together, the frequency samples again span the frequency domain of the spectrum, " |
| 494 | "which runs from –%F to +%F, where %F = 16,384Δ%f = 0.5/Δ%t, the Nyquist frequency.") |
| 495 | ENTRY (U"Storage") |
| 496 | NORMAL (U"In a @Spectrum object, Praat stores the real and imaginary parts of the complex spectrum separately. " |
| 497 | "The real part is equal to the cosine transform:") |
| 498 | EQUATION (U"re %X(%f) = ∫__0_^^%T^ %x(%t) cos (2%%πft%) %dt") |
| 499 | NORMAL (U"The imaginary part is equal to the reverse of the sine transform:") |
| 500 | EQUATION (U"im %X(%f) = – ∫__0_^^%T^ %x(%t) sin (2%%πft%) %dt") |
| 501 | NORMAL (U"The complex spectrum can be reconstructed from the real and imaginary part as follows:") |
| 502 | EQUATION (U"%X(%f) = re %X(%f) + %i im %X(%f)") |
| 503 | NORMAL (U"Since the cosine is a symmetric function of %t and the sine is an antisymmetric function of %t, " |
| 504 | "the complex spectrum for a negative frequency is the complex conjugate of the complex spectrum for the corresponding " |
| 505 | "positive frequency:") |
| 506 | EQUATION (U"%X(-%f) = re %X(-%f) + %i im %X(-%f) = re %X(%f) - %i im %X(%f) = %X^*(%f)") |
| 507 | NORMAL (U"For purposes of storage, therefore, the negative frequencies are superfluous. " |
| 508 | "For this reason, the Spectrum object stores re %X(%f) and im %X(%f) only for frequencies %f = 0, Δ%f, 2Δ%f... " |
| 509 | "In the case of a sound with 20,457 samples, the Spectrum object contains the real part of %X(0) " |
| 510 | "(its imaginary part is always zero), and the real and imaginary parts of %X(%f) " |
| 511 | "for frequencies from Δ%f to 10,228Δ%f, which makes in total 1+2·10,228 = 20,457 real values. " |
| 512 | "In the case of a sound with 32,768 samples, the Spectrum object contains the real parts of %X(0) and %X(16,384Δ%f) " |
| 513 | "(their imaginary parts are always zero), and the real and imaginary parts of %X(%f) " |
| 514 | "for frequencies from Δ%f to 16,383Δ%f, which makes in total 2+2·16,383 = 32,768 real values.") |
| 515 | NORMAL (U"Since the negative frequencies have been removed, the frequency domain now runs from 0 to %F. " |
| 516 | "This means that the first frequency bin is now only 0.5Δ%f wide (i.e. as wide as the last bin for even-%N spectra), " |
| 517 | "which has consequences for computations of energies.") |
| 518 | ENTRY (U"Behaviour") |
| 519 | NORMAL (U"If you perform @@Spectrum: To Sound@ on the resulting Spectrum object, " |
| 520 | "a Sound is created that is equal to the original Sound (or to the original Sound with appended zeroes).") |
| 521 | ENTRY (U"Properties") |
| 522 | NORMAL (U"The frequency integral over the squared Spectrum equals the time integral over the squared Sound:") |
| 523 | EQUATION (U"∫__-%F_^^+%F^ |%X(%f)|^2 %df = ∫__0_^%T |%x(%t)|^2 %dt") |
| 524 | NORMAL (U"This is called %%Parceval's theorem%.") |
| 525 | /* |
| 526 | Copy... square |
| 527 | Formula... self^2 |
| 528 | To Spectrum... yes |
| 529 | Formula... self * exp (- (x/50) ^ 2) |
| 530 | To Sound |
| 531 | Rename... smoothIntensity |
| 532 | |
| 533 | the result is a smoothed version of your squared sound. |
| 534 | Perhaps divide the original by its square root: |
| 535 | |
| 536 | select Sound square |
| 537 | Formula... self / sqrt (Sound_smoothIntensity []) |
| 538 | Play |
| 539 | |
| 540 | > I also have a question about whether this would remove the contour or |
| 541 | > just normalize the loudness? |
| 542 | |
| 543 | it removes the contour. I tested it. It works. |
| 544 | */ |
| 545 | MAN_END |
| 546 | |
| 547 | MAN_BEGIN (U"Spectrogram", U"ppgb", 20070321) |
| 548 | INTRO (U"One of the @@types of objects@ in Praat. For tutorial information, see @@Intro 3. Spectral analysis@.") |
| 549 | NORMAL (U"A Spectrogram object represents an acoustic time-frequency representation of a sound: " |
| 550 | "the @@power spectral density@ %PSD (%f, %t), expressed in Pa^2/Hz. " |
| 551 | "It is sampled into a number of points centred around equally spaced times %t__%i_ " |
| 552 | "and frequencies %f__%j_.") |
| 553 | ENTRY (U"Inside a Spectrogram") |
| 554 | NORMAL (U"With @Inspect, you will see the following attributes:") |
| 555 | TERM (U"%xmin") |
| 556 | DEFINITION (U"start time, in seconds.") |
| 557 | TERM (U"%xmax") |
| 558 | DEFINITION (U"end time, in seconds.") |
| 559 | TERM (U"%nx") |
| 560 | DEFINITION (U"the number of times (≥ 1).") |
| 561 | TERM (U"%dx") |
| 562 | DEFINITION (U"time step, in seconds.") |
| 563 | TERM (U"%x1") |
| 564 | DEFINITION (U"the time associated with the first column, in seconds. " |
| 565 | "This will usually be in the range [%xmin, %xmax]. " |
| 566 | "The time associated with the last column (i.e., %x1 + (%nx – 1) %dx)) " |
| 567 | "will also usually be in that range.") |
| 568 | TERM (U"%ymin") |
| 569 | DEFINITION (U"lowest frequency, in Hertz. Normally 0.") |
| 570 | TERM (U"%ymax") |
| 571 | DEFINITION (U"highest frequency, in Hertz.") |
| 572 | TERM (U"%ny") |
| 573 | DEFINITION (U"the number of frequencies (≥ 1).") |
| 574 | TERM (U"%dy") |
| 575 | DEFINITION (U"frequency step, in Hertz.") |
| 576 | TERM (U"%y1") |
| 577 | DEFINITION (U"the frequency associated with the first row, in Hertz. Usually %dy / 2. " |
| 578 | "The frequency associated with the last row (i.e., %y1 + (%ny – 1) %dy)) " |
| 579 | "will often be %ymax - %dy / 2.") |
| 580 | TERM (U"%z__%ij_, %i = 1 ... %ny, %j = 1 ... %nx") |
| 581 | DEFINITION (U"the power spectral density, in Pa^2/Hz. ") |
| 582 | MAN_END |
| 583 | |
| 584 | MAN_BEGIN (U"Spectrogram: Formula...", U"ppgb", 20021206) |
| 585 | INTRO (U"A command for changing the data in all selected @Spectrogram objects.") |
| 586 | NORMAL (U"See the @Formulas tutorial for examples and explanations.") |
| 587 | MAN_END |
| 588 | |
| 589 | MAN_BEGIN (U"Spectrogram: Paint...", U"ppgb", 20030916) |
| 590 | INTRO (U"A command to draw the selected @Spectrogram object(s) into the @@Picture window@ in shades of grey.") |
| 591 | ENTRY (U"Settings") |
| 592 | TERM (U"##From time (s)") |
| 593 | TERM (U"##To time (s)") |
| 594 | DEFINITION (U"the time domain along the %x axis.") |
| 595 | TERM (U"##From frequency (Hz)") |
| 596 | TERM (U"##To frequency (Hz)") |
| 597 | DEFINITION (U"the frequency domain along the %y axis.") |
| 598 | TERM (U"##Dynamic range (dB)") |
| 599 | DEFINITION (U"The global maximum of the spectrogram (after preemphasis) will always be drawn in black; " |
| 600 | "all values that are more than %%Dynamic range% dB below this maximum (after dynamic compression) " |
| 601 | "will be drawn in white. Values in-between have appropriate shades of grey.") |
| 602 | TERM (U"##Preemphasis (dB/octave)") |
| 603 | DEFINITION (U"determines the steepness of a high-pass filter, " |
| 604 | "i.e., how much the power of higher frequencies will be raised before drawing, as compared to lower frequencies. " |
| 605 | "Since the spectral slope of human vowels is approximately -6 dB per octave, " |
| 606 | "the standard value for this parameter is +6 dB per octave, " |
| 607 | "so that the spectrum is flattened and the higher formants look as strong as the lower ones.") |
| 608 | TERM (U"##Dynamic compression") |
| 609 | DEFINITION (U"determines how much stronger weak time frames should be made before drawing. " |
| 610 | "Normally, this parameter is between 0 and 1. If it is 0, there is no dynamic compression. " |
| 611 | "If it is 1, all time frames (vertical bands) will be drawn equally strong, " |
| 612 | "i.e., all of them will contain frequencies that are drawn in black. " |
| 613 | "If this parameter is 0.4 and the global maximum is at 80 dB, then a frame with a maximum at 20 dB " |
| 614 | "(which will normally be drawn all white if the dynamic range is 50 dB), " |
| 615 | "will be raised by 0.4 * (80 - 20) = 24 dB, " |
| 616 | "so that its maximum will be seen at 44 dB (thus making this frame visible).") |
| 617 | MAN_END |
| 618 | |
| 619 | MAN_BEGIN (U"Spectrogram: To Spectrum (slice)...", U"ppgb", 19961003) |
| 620 | INTRO (U"A command to create a @Spectrum object from every selected @Spectrogram object.") |
| 621 | ENTRY (U"Purpose") |
| 622 | NORMAL (U"to extract the information contained in a Spectrogram at a certain time.") |
| 623 | ENTRY (U"Algorithm") |
| 624 | NORMAL (U"The Spectrum will be constructed from one frame of the Spectrogram, " |
| 625 | "namely the frame whose centre is closed to the %time argument. ") |
| 626 | MAN_END |
| 627 | |
| 628 | MAN_BEGIN (U"Spectrum", U"ppgb", 20041123) |
| 629 | INTRO (U"One of the @@types of objects@ in Praat. A Spectrum object represents " |
| 630 | "the complex spectrum as a function of frequency. " |
| 631 | "If the spectrum was created from a sound (which is expressed in units of Pascal), " |
| 632 | "the complex values are expressed in units Pa/Hz (Pascal per Hertz). " |
| 633 | "For detailed information, see @@Sound: To Spectrum...@.") |
| 634 | ENTRY (U"Spectrum commands") |
| 635 | NORMAL (U"Creation:") |
| 636 | LIST_ITEM (U"• @@Sound: To Spectrum...") |
| 637 | NORMAL (U"Queries:") |
| 638 | LIST_ITEM (U"• @@Spectrum: Get centre of gravity...") |
| 639 | LIST_ITEM (U"• @@Spectrum: Get standard deviation...") |
| 640 | LIST_ITEM (U"• @@Spectrum: Get skewness...") |
| 641 | LIST_ITEM (U"• @@Spectrum: Get kurtosis...") |
| 642 | LIST_ITEM (U"• @@Spectrum: Get central moment...") |
| 643 | NORMAL (U"Modification:") |
| 644 | LIST_ITEM (U"• @@Spectrum: Filter (pass Hann band)...") |
| 645 | LIST_ITEM (U"• @@Spectrum: Filter (stop Hann band)...") |
| 646 | LIST_ITEM (U"• @@Formula...") |
| 647 | NORMAL (U"Conversion:") |
| 648 | LIST_ITEM (U"• @@Spectrum: To Ltas (1-to-1)") |
| 649 | LIST_ITEM (U"• @@Spectrum: To Spectrogram") |
| 650 | NORMAL (U"Synthesis:") |
| 651 | LIST_ITEM (U"• @@Spectrum: To Sound") |
| 652 | MAN_END |
| 653 | |
| 654 | MAN_BEGIN (U"Spectrum: Filter (pass Hann band)...", U"ppgb", 20030916) |
| 655 | INTRO (U"A command to modify every selected @Spectrum object.") |
| 656 | NORMAL (U"The complex values in the #Spectrum are multiplied by real-valued sine shapes and straight lines, according to the following figure:") |
| 657 | PICTURE (5, 3, draw_SpectrumPassHann) |
| 658 | ENTRY (U"Settings") |
| 659 | TERM (U"##From frequency (Hz)# (standard value: 500 Hz)") |
| 660 | DEFINITION (U"the lower edge of the pass band (%f__1_ in the figure). The value zero is special: the filter then acts as a low-pass filter.") |
| 661 | TERM (U"##To frequency (Hz)# (standard value: 1000 Hz)") |
| 662 | DEFINITION (U"the upper edge of the pass band (%f__2_ in the figure). The value zero is special: the filter then acts as a high-pass filter.") |
| 663 | TERM (U"##Smoothing (Hz)# (standard value: 100 Hz)") |
| 664 | DEFINITION (U"the width of the region between pass and stop (%w in the figure).") |
| 665 | ENTRY (U"Usage") |
| 666 | NORMAL (U"Because of its symmetric Hann-like shape, the filter is especially useful for decomposing the Spectrum into consecutive bands. " |
| 667 | "For instance, we can decompose the spectrum into the bands 0-500 Hz, 500-1000 Hz, 1000-2000 Hz, and 2000-\"0\" Hz:") |
| 668 | PICTURE (5, 3, draw_SpectrumPassHann_decompose) |
| 669 | NORMAL (U"By adding the four bands together, we get the original spectrum again.") |
| 670 | NORMAL (U"A complementary filter is described at @@Spectrum: Filter (stop Hann band)...@.") |
| 671 | NORMAL (U"See the @Filtering tutorial for information on the need for smoothing and a comparative discussion of various filters.") |
| 672 | MAN_END |
| 673 | |
| 674 | MAN_BEGIN (U"Spectrum: Filter (stop Hann band)...", U"ppgb", 20030916) |
| 675 | INTRO (U"A command to modify every selected @Spectrum object.") |
| 676 | NORMAL (U"The complex values in the #Spectrum are multiplied by real-valued sine shapes and straight lines, according to the following figure:") |
| 677 | PICTURE (5, 3, draw_SpectrumStopHann) |
| 678 | ENTRY (U"Settings") |
| 679 | TERM (U"##From frequency (Hz)# (standard value: 500 Hz)") |
| 680 | DEFINITION (U"the lower edge of the stop band (%f__1_ in the figure). The value zero is special: the filter then acts as a high-pass filter.") |
| 681 | TERM (U"##To frequency (Hz)# (standard value: 1000 Hz)") |
| 682 | DEFINITION (U"the upper edge of the stop band (%f__2_ in the figure). The value zero is special: the filter then acts as a low-pass filter.") |
| 683 | TERM (U"##Smoothing (Hz)# (standard value: 100 Hz)") |
| 684 | DEFINITION (U"the width of the region between stop and pass (%w in the figure).") |
| 685 | ENTRY (U"Usage") |
| 686 | NORMAL (U"This filter is the complement from the pass-band filter (@@Spectrum: Filter (pass Hann band)...@). " |
| 687 | "For instance, we can decompose the spectrum into the above stop-band spectrum and a band from 500 to 1000 Hz:") |
| 688 | PICTURE (5, 3, draw_SpectrumStopHann_decompose) |
| 689 | NORMAL (U"By adding the two spectra together, we get the original spectrum again.") |
| 690 | NORMAL (U"See the @Filtering tutorial for information on the need for smoothing and a comparative discussion of various filters.") |
| 691 | MAN_END |
| 692 | |
| 693 | MAN_BEGIN (U"Spectrum: Formula...", U"ppgb", 20021206) |
| 694 | INTRO (U"A command for changing the data in all selected @Spectrum objects.") |
| 695 | NORMAL (U"See the @Formulas tutorial for examples and explanations.") |
| 696 | MAN_END |
| 697 | |
| 698 | MAN_BEGIN (U"Spectrum: Get central moment...", U"ppgb", 20020323) |
| 699 | INTRO (U"A command to query the selected @Spectrum object.") |
| 700 | NORMAL (U"If the complex spectrum is given by %S(%f), the %%n%th central spectral moment is given by") |
| 701 | EQUATION (U"∫__0_^∞ (%f – %f__%c_)^%n |%S(%f)|^%p %df") |
| 702 | NORMAL (U"divided by the \"energy\"") |
| 703 | EQUATION (U"∫__0_^∞ |%S(%f)|^%p %df") |
| 704 | NORMAL (U"In this formula, %f__%c_ is the spectral centre of gravity (see @@Spectrum: Get centre of gravity...@). " |
| 705 | "Thus, the %%n%th central moment is the average of (%f – %f__%c_)^%n over the entire frequency domain, " |
| 706 | "weighted by |%S(%f)|^%p. For %p = 2, the weighting is done by the power spectrum, and for %p = 1, " |
| 707 | "the weighting is done by the absolute spectrum. A value of %p = 2/3 has been seen as well.") |
| 708 | ENTRY (U"Settings") |
| 709 | TERM (U"##Moment") |
| 710 | DEFINITION (U"the number %n in the formulas above. A number of 3 gives you the third central spectral moment. " |
| 711 | "It is not impossible to ask for fractional moments, e.g. %n = 1.5.") |
| 712 | TERM (U"##Power") |
| 713 | DEFINITION (U"the quantity %p in the formula above. Common values are 2, 1, or 2/3.") |
| 714 | ENTRY (U"Usage") |
| 715 | NORMAL (U"For %n = 1, the central moment should be zero, since the centre of gravity %f__%c_ is computed with " |
| 716 | "the same %p. For %n = 2, you get the variance of the frequencies in the spectrum; the standard deviation " |
| 717 | "of the frequency is the square root of this. For %n = 3, you get the non-normalized spectral skewness; " |
| 718 | "to normalize it, you can divide by the 1.5 power of the second moment. For %n = 4, you get the " |
| 719 | "non-normalized spectral kurtosis; to normalize it, you can divide by the square of the second moment " |
| 720 | "and subtract 3. Praat can directly give you the quantities mentioned here:") |
| 721 | LIST_ITEM (U"• @@Spectrum: Get centre of gravity...") |
| 722 | LIST_ITEM (U"• @@Spectrum: Get standard deviation...") |
| 723 | LIST_ITEM (U"• @@Spectrum: Get skewness...") |
| 724 | LIST_ITEM (U"• @@Spectrum: Get kurtosis...") |
| 725 | MAN_END |
| 726 | |
| 727 | MAN_BEGIN (U"Spectrum: Get centre of gravity...", U"ppgb", 20070225) |
| 728 | INTRO (U"A command to query the selected @Spectrum object.") |
| 729 | NORMAL (U"If the complex spectrum is given by %S(%f), where %f is the frequency, the %%centre of gravity% " |
| 730 | "is given by") |
| 731 | EQUATION (U"∫__0_^∞ %f |%S(%f)|^%p %df") |
| 732 | NORMAL (U"divided by the \"energy\"") |
| 733 | EQUATION (U"∫__0_^∞ |%S(%f)|^%p %df") |
| 734 | NORMAL (U"Thus, the centre of gravity is the average of %f over the entire frequency domain, " |
| 735 | "weighted by |%S(%f)|^%p. For %p = 2, the weighting is done by the power spectrum, and for %p = 1, " |
| 736 | "the weighting is done by the absolute spectrum. A value of %p = 2/3 has been seen as well.") |
| 737 | ENTRY (U"Setting") |
| 738 | TERM (U"##Power") |
| 739 | DEFINITION (U"the quantity %p in the formulas above. Common values are 2, 1, or 2/3.") |
| 740 | ENTRY (U"Interpretation") |
| 741 | NORMAL (U"The spectral centre of gravity is a measure for how high the frequencies in a spectrum are on average. " |
| 742 | "For a sine wave with a frequency of 377 Hz, the centre of gravity is 377 Hz. You can easily check this " |
| 743 | "in Praat by creating such a sine wave (@@Create Sound from formula...@), then converting it to a Spectrum " |
| 744 | "(@@Sound: To Spectrum...@), then querying the mean frequency. For a white noise sampled at 22050 Hz, " |
| 745 | "the centre of gravity is 5512.5 Hz, i.e. one half of the @@Nyquist frequency@.") |
| 746 | ENTRY (U"Related measures") |
| 747 | NORMAL (U"The centre of gravity is used in the computation of spectral moments:") |
| 748 | LIST_ITEM (U"• @@Spectrum: Get central moment...") |
| 749 | LIST_ITEM (U"• @@Spectrum: Get standard deviation...") |
| 750 | LIST_ITEM (U"• @@Spectrum: Get skewness...") |
| 751 | LIST_ITEM (U"• @@Spectrum: Get kurtosis...") |
| 752 | MAN_END |
| 753 | |
| 754 | MAN_BEGIN (U"Spectrum: Get kurtosis...", U"ppgb", 20020323) |
| 755 | INTRO (U"A command to query the selected @Spectrum object.") |
| 756 | NORMAL (U"The (normalized) kurtosis of a spectrum is the fourth central moment of this spectrum, " |
| 757 | "divided by the square of the second central moment, minus 3. " |
| 758 | "See @@Spectrum: Get central moment...@.") |
| 759 | ENTRY (U"Setting") |
| 760 | TERM (U"##Power") |
| 761 | DEFINITION (U"the quantity %p in the formula for the centre of gravity and the second and fourth central moment. " |
| 762 | "Common values are 2, 1, or 2/3.") |
| 763 | ENTRY (U"Interpretation") |
| 764 | NORMAL (U"The kurtosis is a measure for how much the shape of the spectrum around the " |
| 765 | "%%centre of gravity% is different from a Gaussian shape. " |
| 766 | "For a white noise, the kurtosis is -6/5.") |
| 767 | ENTRY (U"Related measures") |
| 768 | LIST_ITEM (U"• @@Spectrum: Get centre of gravity...") |
| 769 | LIST_ITEM (U"• @@Spectrum: Get central moment...") |
| 770 | LIST_ITEM (U"• @@Spectrum: Get standard deviation...") |
| 771 | LIST_ITEM (U"• @@Spectrum: Get skewness...") |
| 772 | MAN_END |
| 773 | |
| 774 | MAN_BEGIN (U"Spectrum: Get skewness...", U"ppgb", 20020323) |
| 775 | INTRO (U"A command to query the selected @Spectrum object.") |
| 776 | NORMAL (U"The (normalized) skewness of a spectrum is the third central moment of this spectrum, " |
| 777 | "divided by the 1.5 power of the second central moment. " |
| 778 | "See @@Spectrum: Get central moment...@.") |
| 779 | ENTRY (U"Setting") |
| 780 | TERM (U"##Power") |
| 781 | DEFINITION (U"the quantity %p in the formula for the centre of gravity and the second and third central moment. " |
| 782 | "Common values are 2, 1, or 2/3.") |
| 783 | ENTRY (U"Interpretation") |
| 784 | NORMAL (U"The skewness is a measure for how much the shape of the spectrum below the " |
| 785 | "%%centre of gravity% is different from the shape above the mean frequency. " |
| 786 | "For a white noise, the skewness is zero.") |
| 787 | ENTRY (U"Related measures") |
| 788 | LIST_ITEM (U"• @@Spectrum: Get centre of gravity...") |
| 789 | LIST_ITEM (U"• @@Spectrum: Get central moment...") |
| 790 | LIST_ITEM (U"• @@Spectrum: Get standard deviation...") |
| 791 | LIST_ITEM (U"• @@Spectrum: Get kurtosis...") |
| 792 | MAN_END |
| 793 | |
| 794 | MAN_BEGIN (U"Spectrum: Get standard deviation...", U"ppgb", 20020323) |
| 795 | INTRO (U"A command to query the selected @Spectrum object.") |
| 796 | NORMAL (U"The standard deviation of a spectrum is the square root of the second central moment of this spectrum. " |
| 797 | "See @@Spectrum: Get central moment...@.") |
| 798 | ENTRY (U"Setting") |
| 799 | TERM (U"##Power") |
| 800 | DEFINITION (U"the quantity %p in the formula for the centre of gravity and the second central moment. " |
| 801 | "Common values are 2, 1, or 2/3.") |
| 802 | ENTRY (U"Interpretation") |
| 803 | NORMAL (U"The standard deviation is a measure for how much the frequencies in a spectrum can deviate from " |
| 804 | "the %%centre of gravity%. " |
| 805 | "For a sine wave, the standard deviation is zero. For a white noise, the standard deviation " |
| 806 | "is the @@Nyquist frequency@ divided by √12.") |
| 807 | ENTRY (U"Related measures") |
| 808 | LIST_ITEM (U"• @@Spectrum: Get centre of gravity...") |
| 809 | LIST_ITEM (U"• @@Spectrum: Get central moment...") |
| 810 | LIST_ITEM (U"• @@Spectrum: Get skewness...") |
| 811 | LIST_ITEM (U"• @@Spectrum: Get kurtosis...") |
| 812 | MAN_END |
| 813 | |
| 814 | MAN_PAGES_BEGIN |
| 815 | R"~~~( |
| 816 | ################################################################################ |
| 817 | "Spectrum: Tabulate (verbose)" |
| 818 | © Paul Boersma 2023-05-03 |
| 819 | |
| 820 | The command ##Tabulate (verbose)# becomes available under Tabulate |
| 821 | when you select exactly one @Spectrum object. |
| 822 | |
| 823 | When you choose ##Tabulate (verbose)#, a new @Table (with the same name as the Spectrum) |
| 824 | will appear in the list of objects. When you ##View & Edit# this Table, |
| 825 | you will see: |
| 826 | |
| 827 | A column called #bin. |
| 828 | : This contains the bin number, running from 1 to the number of frequency bins in the Spectrum. |
| 829 | |
| 830 | A column called ##frequency (Hz)#. |
| 831 | : This is the frequency that is associated with the bin. |
| 832 | In a Spectrum that you created from a @Sound, the frequency that is associated with bin 1 |
| 833 | is 0 Hz, and the frequency that is associated with the last bin is the @@Nyquist frequency@ |
| 834 | of that Sound (i.e. half the sampling frequency). The frequency step between consecutive |
| 835 | bins is always the same, and we call this step the %%bin step%, abbreviated as %df. |
| 836 | Thus, bin 2 is centred at %df, bin 3 at 2%df, bin 4 at 3%df, and so on. |
| 837 | |
| 838 | A column called ##re (Pa/Hz)#. |
| 839 | : This is the real part of the complex value of the spectrum in the bin. |
| 840 | |
| 841 | A column called ##im (Pa/Hz)#. |
| 842 | : This is the imaginary part of the complex value of the spectrum in the bin. |
| 843 | |
| 844 | A column called ##energy spectral density (Pa^2s/Hz)#. |
| 845 | : For most bins this is computed as the square of the real part plus the square of the imaginary part. |
| 846 | For bin 1 (where the imaginary part is zero) this is computed as 2 times the square of the real part. |
| 847 | If the number of the last bin is odd, the imaginary part will be zero, and the energy spectral density |
| 848 | is computed as 2 times the square of the real part. For an explanation of the factor of 2, see below. |
| 849 | |
| 850 | A column called ##startOfBinWithinDomain (Hz)#. |
| 851 | : The first bin starts at 0 Hz and ends at 0.5%df, i.e. in the middle of the centres of bin 1 and bin 2. |
| 852 | The second bin starts at 0.5%df and ends at 1.5%df, the third starts at 1.5%df and ends at 2.5%df. |
| 853 | This column lists the beginnings of the bins. The part “within domain” refers to the fact |
| 854 | that all bins represent both positive and negative frequencies, |
| 855 | but we count only the frequencies in the domain of the Spectrum, |
| 856 | which runs from 0 Hz to the Nyquist frequency. |
| 857 | |
| 858 | A column called ##endOfBinWithinDomain (Hz)#. |
| 859 | : This column is explained just above. |
| 860 | |
| 861 | A column called ##binWidthWithinDomain (Hz)#. |
| 862 | : Bin 1 runs from 0 Hz to 0.5%df, so it has a width of 0.5%df. |
| 863 | Bin 2 runs from 0.5%df to 1.5%df, so it has a width of %df; the same goes for almost all remaining bins. |
| 864 | As for the last bin: if there are an odd number %N of bins, |
| 865 | then bin %N runs from (%N − 1.5)·%df to (%N − 1.0)·%df (which is the Nyquist frequency), |
| 866 | so its width is 0.5%df. |
| 867 | |
| 868 | A column called ##binEnergy (Pa^2s)#. |
| 869 | : This is the bin’s energy spectral density times the width of the bin. |
| 870 | Thus, you get this mostly from multiplying the energy spectral density column by %df, |
| 871 | except for bin 1 and (if %N is odd) bin %N, where the energy spectral density |
| 872 | is multiplied by 0.5%df instead. The sum of all the values in this column is the |
| 873 | total energy of the signal, i.e. it should be equal to the average of the squares |
| 874 | of the samples of an original Sound, times the duration of that Sound. |
| 875 | |
| 876 | A column called ##power spectral density (Pa^2/Hz)#. |
| 877 | : This is the @@power spectral density@ in the bin. It is computed as |
| 878 | the energy spectral density divided by the duration of the original sound, |
| 879 | which is the same as multiplication by %df. This column is almost the same |
| 880 | as the bin energy column, except for bin 1 and (if %N is odd) bin %N, |
| 881 | where it is twice as large. |
| 882 | |
| 883 | ################################################################################ |
| 884 | )~~~" |
| 885 | MAN_PAGES_END |
| 886 | |
| 887 | MAN_BEGIN (U"Spectrum: To Ltas (1-to-1)", U"ppgb", 20141001) |
| 888 | INTRO (U"A command for converting each selected @Spectrum object into an @Ltas object without loss of frequency resolution.") |
| 889 | ENTRY (U"Algorithm") |
| 890 | NORMAL (U"Each band %b__%i_ in the Ltas is computed from a single frequency sample %s__%i_ in the Spectrum as follows:") |
| 891 | EQUATION (U"%b__%i_ = 2 ((re (%s__%i_))^2 + (im (%s__%i_))^2) / 4.0·10^^-10^") |
| 892 | NORMAL (U"If the original Spectrum is expressible in Pa / Hz (sound pressure in air), the Ltas values " |
| 893 | "are in \"dB/Hz\" relative to the auditory threshold at 1000 Hz (2·10^^-5^ Pa).") |
| 894 | MAN_END |
| 895 | |
| 896 | MAN_BEGIN (U"Spectrum: To Sound", U"ppgb", 200411123) |
| 897 | INTRO (U"A command for creating a @Sound object from every selected @Spectrum object.") |
| 898 | ENTRY (U"Mathematical procedure") |
| 899 | NORMAL (U"The reverse of the Fourier transform described in @@Sound: To Spectrum...@. " |
| 900 | "If the Spectrum is expressed in Pa/Hz, the Sound will be in Pascal. " |
| 901 | "The frequency integral over the Sound equals the time integral over the Spectrum.") |
| 902 | ENTRY (U"Behaviour") |
| 903 | NORMAL (U"If you perform this command on a Spectrum object that was created earlier with @@Sound: To Spectrum...@, " |
| 904 | "the resulting Sound is equal to the Sound that was input to ##Sound: To Spectrum...#.") |
| 905 | MAN_END |
| 906 | |
| 907 | MAN_BEGIN (U"Spectrum: To Spectrogram", U"ppgb", 19961003) |
| 908 | INTRO (U"A command to create a @Spectrogram object from every selected @Spectrum object.") |
| 909 | ENTRY (U"Purpose") |
| 910 | NORMAL (U"Format conversion.") |
| 911 | ENTRY (U"Behaviour") |
| 912 | NORMAL (U"The Spectrogram will have only one frame (time slice).") |
| 913 | ENTRY (U"Algorithm") |
| 914 | NORMAL (U"The values are computed as the sum of the squares of the real and imaginary parts of the Spectrum.") |
| 915 | MAN_END |
| 916 | |
| 917 | MAN_BEGIN (U"SpectrumEditor", U"ppgb", 20030316) |
| 918 | INTRO (U"One of the @editors in Praat. It allows you to view, " |
| 919 | "zoom, and play a @Spectrum object.") |
| 920 | NORMAL (U"Clicking on one of the (maximally) 8 rectangles above or below the drawing area " |
| 921 | "lets you play a @Sound that is synthesized from a band-filtered part of the @Spectrum. " |
| 922 | "You can also copy the Spectrum, band-filtered with the @@frequency selection@, " |
| 923 | "or the Sound synthesized from this Spectrum, to the list of objects.") |
| 924 | MAN_END |
| 925 | |
| 926 | } |
| 927 | |
| 928 | /* End of file manual_spectrum.cpp */ |