manual_spectrum.cpp 43 KB

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