Cepstrogram.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /* Cepstrogram.cpp
  2. *
  3. * Copyright (C) 2013 - 2017 David Weenink
  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. See the GNU
  13. * 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. djmw 20010514
  20. djmw 20020812 GPL header
  21. djmw 20080122 Version 1: float -> double
  22. djmw 20110304 Thing_new
  23. */
  24. #include "Cepstrogram.h"
  25. #include "Cepstrum_and_Spectrum.h"
  26. #include "NUM2.h"
  27. #include "Sound_and_Spectrum.h"
  28. #include "Sound_extensions.h"
  29. #define TOLOG(x) ((1 / NUMln10) * log ((x) + 1e-30))
  30. #define TO10LOG(x) ((10 / NUMln10) * log ((x) + 1e-30))
  31. #define FROMLOG(x) (exp ((x) * (NUMln10 / 10.0)) - 1e-30)
  32. Thing_implement (Cepstrogram, Matrix, 2);
  33. Thing_implement (PowerCepstrogram, Cepstrogram, 2); // derives from Matrix -> also version 2
  34. autoCepstrogram Cepstrogram_create (double tmin, double tmax, integer nt, double dt, double t1,
  35. double qmin, double qmax, integer nq, double dq, double q1) {
  36. try {
  37. autoCepstrogram me = Thing_new (Cepstrogram);
  38. Matrix_init (me.get(), tmin, tmax, nt, dt, t1, qmin, qmax, nq, dq, q1);
  39. return me;
  40. } catch (MelderError) {
  41. Melder_throw (U"Cepstrogram not created.");
  42. }
  43. }
  44. autoPowerCepstrogram PowerCepstrogram_create (double tmin, double tmax, integer nt, double dt, double t1,
  45. double qmin, double qmax, integer nq, double dq, double q1) {
  46. try {
  47. autoPowerCepstrogram me = Thing_new (PowerCepstrogram);
  48. Matrix_init (me.get(), tmin, tmax, nt, dt, t1, qmin, qmax, nq, dq, q1);
  49. return me;
  50. } catch (MelderError) {
  51. Melder_throw (U"PowerCepstrogram not created.");
  52. }
  53. }
  54. void PowerCepstrogram_paint (PowerCepstrogram me, Graphics g, double tmin, double tmax, double qmin, double qmax, double dBmaximum, int autoscaling, double dynamicRangedB, double dynamicCompression, int garnish) {
  55. if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; }
  56. if (qmax <= qmin) { qmin = my ymin; qmax = my ymax; }
  57. integer itmin, itmax, ifmin, ifmax;
  58. if (! Matrix_getWindowSamplesX (me, tmin - 0.49999 * my dx, tmax + 0.49999 * my dx, & itmin, & itmax) ||
  59. ! Matrix_getWindowSamplesY (me, qmin - 0.49999 * my dy, qmax + 0.49999 * my dy, & ifmin, & ifmax)) {
  60. return;
  61. }
  62. autoMatrix thee = Data_copy (me);
  63. double min = 1e308, max = -min;
  64. for (integer i = 1; i <= my ny; i ++) {
  65. for (integer j = 1; j <= my nx; j ++) {
  66. double val = TO10LOG (my z [i] [j]);
  67. if (val < min) min = val;
  68. if (val > max) max = val;
  69. thy z [i] [j] = val;
  70. }
  71. }
  72. double dBminimum = dBmaximum - dynamicRangedB;
  73. if (autoscaling) {
  74. dBminimum = min;
  75. dBmaximum = max;
  76. }
  77. for (integer j = 1; j <= my nx; j ++) {
  78. double lmax = thy z [1] [j];
  79. for (integer i = 2; i <= my ny; i ++) {
  80. if (thy z [i] [j] > lmax) {
  81. lmax = thy z [i] [j];
  82. }
  83. }
  84. double factor = dynamicCompression * (max - lmax);
  85. for (integer i = 1; i <= my ny; i ++) {
  86. thy z [i] [j] += factor;
  87. }
  88. }
  89. Graphics_setInner (g);
  90. Graphics_setWindow (g, tmin, tmax, qmin, qmax);
  91. Graphics_image (g, thy z.at,
  92. itmin, itmax,
  93. Matrix_columnToX (thee.get(), itmin - 0.5),
  94. Matrix_columnToX (thee.get(), itmax + 0.5),
  95. ifmin, ifmax,
  96. Matrix_rowToY (thee.get(), ifmin - 0.5),
  97. Matrix_rowToY (thee.get(), ifmax + 0.5),
  98. dBminimum, dBmaximum);
  99. Graphics_unsetInner (g);
  100. if (garnish) {
  101. Graphics_drawInnerBox (g);
  102. Graphics_textBottom (g, true, U"Time (s)");
  103. Graphics_marksBottom (g, 2, true, true, false);
  104. Graphics_marksLeft (g, 2, true, true, false);
  105. Graphics_textLeft (g, true, U"Quefrency (s)");
  106. }
  107. }
  108. void PowerCepstrogram_subtractTilt_inplace (PowerCepstrogram me, double qstartFit, double qendFit, int lineType, int fitMethod) {
  109. try {
  110. autoPowerCepstrum thee = PowerCepstrum_create (my ymax, my ny);
  111. for (integer i = 1; i <= my nx; i ++) {
  112. for (integer j = 1; j <= my ny; j ++) {
  113. thy z [1] [j] = my z [j] [i];
  114. }
  115. PowerCepstrum_subtractTilt_inplace (thee.get(), qstartFit, qendFit, lineType, fitMethod);
  116. for (integer j = 1; j <= my ny; j ++) {
  117. my z [j] [i] = thy z [1] [j];
  118. }
  119. }
  120. } catch (MelderError) {
  121. Melder_throw (me, U": no tilt subtracted (inline).");
  122. }
  123. }
  124. autoPowerCepstrogram PowerCepstrogram_subtractTilt (PowerCepstrogram me, double qstartFit, double qendFit, int lineType, int fitMethod) {
  125. try {
  126. autoPowerCepstrogram thee = Data_copy (me);
  127. PowerCepstrogram_subtractTilt_inplace (thee.get(), qstartFit, qendFit, lineType, fitMethod);
  128. return thee;
  129. } catch (MelderError) {
  130. Melder_throw (me, U": no tilt subtracted.");
  131. }
  132. }
  133. autoTable PowerCepstrogram_to_Table_hillenbrand (PowerCepstrogram me, double pitchFloor, double pitchCeiling) {
  134. try {
  135. autoTable thee = Table_createWithColumnNames (my nx, U"time quefrency cpp f0");
  136. autoPowerCepstrum him = PowerCepstrum_create (my ymax, my ny);
  137. for (integer i = 1; i <= my nx; i ++) {
  138. for (integer j = 1; j <= my ny; j ++) {
  139. his z [1] [j] = my z [j] [i];
  140. }
  141. double qpeak, cpp = PowerCepstrum_getPeakProminence_hillenbrand (him.get(), pitchFloor, pitchCeiling, &qpeak);
  142. double time = Sampled_indexToX (me, i);
  143. Table_setNumericValue (thee.get(), i, 1, time);
  144. Table_setNumericValue (thee.get(), i, 2, qpeak);
  145. Table_setNumericValue (thee.get(), i, 3, cpp); // Cepstrogram_getCPPS depends on this index 3!!
  146. Table_setNumericValue (thee.get(), i, 4, 1.0 / qpeak);
  147. }
  148. return thee;
  149. } catch (MelderError) {
  150. Melder_throw (me, U": no Table with cepstral peak prominence values created.");
  151. }
  152. }
  153. autoTable PowerCepstrogram_to_Table_cpp (PowerCepstrogram me, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, int lineType, int fitMethod) {
  154. try {
  155. autoTable thee = Table_createWithColumnNames (my nx, U"time quefrency cpp f0 rnr");
  156. autoPowerCepstrum him = PowerCepstrum_create (my ymax, my ny);
  157. for (integer i = 1; i <= my nx; i ++) {
  158. for (integer j = 1; j <= my ny; j ++) {
  159. his z [1] [j] = my z [j] [i];
  160. }
  161. double qpeak, cpp = PowerCepstrum_getPeakProminence (him.get(), pitchFloor, pitchCeiling, interpolation,
  162. qstartFit, qendFit, lineType, fitMethod, & qpeak);
  163. double rnr = PowerCepstrum_getRNR (him.get(), pitchFloor, pitchCeiling, deltaF0);
  164. double time = Sampled_indexToX (me, i);
  165. Table_setNumericValue (thee.get(), i, 1, time);
  166. Table_setNumericValue (thee.get(), i, 2, qpeak);
  167. Table_setNumericValue (thee.get(), i, 3, cpp); // Cepstrogram_getCPPS depends on this index!!
  168. Table_setNumericValue (thee.get(), i, 4, 1.0 / qpeak);
  169. Table_setNumericValue (thee.get(), i, 5, rnr);
  170. }
  171. return thee;
  172. } catch (MelderError) {
  173. Melder_throw (me, U": no Table with cepstral peak prominence values created.");
  174. }
  175. }
  176. autoPowerCepstrogram PowerCepstrogram_smooth (PowerCepstrogram me, double timeAveragingWindow, double quefrencyAveragingWindow) {
  177. try {
  178. autoPowerCepstrogram thee = Data_copy (me);
  179. // 1. average across time
  180. integer numberOfFrames = Melder_ifloor (timeAveragingWindow / my dx);
  181. if (numberOfFrames > 1) {
  182. autoVEC qin = VECraw (my nx);
  183. autoVEC qout = VECraw (my nx);
  184. for (integer iq = 1; iq <= my ny; iq ++) {
  185. VECcopy_preallocated (qin.get(), thy z.row(iq));
  186. VECsmoothByMovingAverage_preallocated (qout.get(), qin.get(), numberOfFrames);
  187. VECcopy_preallocated (thy z.row(iq), qout.get());
  188. }
  189. }
  190. // 2. average across quefrencies
  191. integer numberOfQuefrencyBins = Melder_ifloor (quefrencyAveragingWindow / my dy);
  192. if (numberOfQuefrencyBins > 1) {
  193. autoVEC qin = VECraw (thy ny);
  194. autoVEC qout = VECraw (thy ny);
  195. for (integer iframe = 1; iframe <= my nx; iframe ++) {
  196. for (integer iq = 1; iq <= thy ny; iq ++) {
  197. //qin[iq] = TO10LOG (my z[iq][iframe]);
  198. qin [iq] = thy z [iq] [iframe];
  199. }
  200. VECsmoothByMovingAverage_preallocated (qout.get(), qin.get(), numberOfQuefrencyBins);
  201. for (integer iq = 1; iq <= thy ny; iq ++) {
  202. //thy z[iq][iframe] = FROMLOG (qout[iq]);
  203. thy z [iq] [iframe] = qout [iq];
  204. }
  205. }
  206. }
  207. return thee;
  208. } catch (MelderError) {
  209. Melder_throw (me, U": not smoothed.");
  210. }
  211. }
  212. autoMatrix PowerCepstrogram_to_Matrix (PowerCepstrogram me) {
  213. try {
  214. autoMatrix thee = Thing_new (Matrix);
  215. my structMatrix :: v_copy (thee.get());
  216. return thee;
  217. } catch (MelderError) {
  218. Melder_throw (me, U": not converted to Matrix.");
  219. }
  220. }
  221. autoPowerCepstrum PowerCepstrogram_to_PowerCepstrum_slice (PowerCepstrogram me, double time) {
  222. try {
  223. integer iframe = Sampled_xToNearestIndex (me, time);
  224. iframe = iframe < 1 ? 1 : iframe > my nx ? my nx : iframe;
  225. autoPowerCepstrum thee = PowerCepstrum_create (my ymax, my ny);
  226. for (integer i = 1; i <= my ny; i ++) {
  227. thy z [1] [i] = my z [i] [iframe];
  228. }
  229. return thee;
  230. } catch (MelderError) {
  231. Melder_throw (me, U": Cepstrum not extracted.");
  232. }
  233. }
  234. autoPowerCepstrogram Matrix_to_PowerCepstrogram (Matrix me) {
  235. try {
  236. autoPowerCepstrogram thee = Thing_new (PowerCepstrogram);
  237. my structMatrix :: v_copy (thee.get());
  238. return thee;
  239. } catch (MelderError) {
  240. Melder_throw (me, U": not converted to PowerCepstrogram.");
  241. }
  242. }
  243. autoPowerCepstrogram Sound_to_PowerCepstrogram (Sound me, double pitchFloor, double dt, double maximumFrequency, double preEmphasisFrequency) {
  244. try {
  245. // minimum analysis window has 3 periods of lowest pitch
  246. double analysisWidth = 3.0 / pitchFloor;
  247. double windowDuration = 2.0 * analysisWidth; /* gaussian window */
  248. integer nFrames;
  249. // Convenience: analyse the whole sound into one Cepstrogram_frame
  250. if (windowDuration > my dx * my nx) {
  251. windowDuration = my dx * my nx;
  252. }
  253. double t1, samplingFrequency = 2 * maximumFrequency;
  254. autoSound sound = Sound_resample (me, samplingFrequency, 50);
  255. Sound_preEmphasis (sound.get(), preEmphasisFrequency);
  256. Sampled_shortTermAnalysis (me, windowDuration, dt, & nFrames, & t1);
  257. autoSound sframe = Sound_createSimple (1, windowDuration, samplingFrequency);
  258. autoSound window = Sound_createGaussian (windowDuration, samplingFrequency);
  259. // find out the size of the FFT
  260. integer nfft = 2;
  261. while (nfft < sframe -> nx) nfft *= 2;
  262. integer nq = nfft / 2 + 1;
  263. double qmax = 0.5 * nfft / samplingFrequency, dq = qmax / (nq - 1);
  264. autoPowerCepstrogram thee = PowerCepstrogram_create (my xmin, my xmax, nFrames, dt, t1, 0, qmax, nq, dq, 0);
  265. autoMelderProgress progress (U"Cepstrogram analysis");
  266. for (integer iframe = 1; iframe <= nFrames; iframe++) {
  267. double t = Sampled_indexToX (thee.get(), iframe);
  268. Sound_into_Sound (sound.get(), sframe.get(), t - windowDuration / 2);
  269. Vector_subtractMean (sframe.get());
  270. Sounds_multiply (sframe.get(), window.get());
  271. autoSpectrum spec = Sound_to_Spectrum (sframe.get(), true); // FFT yes
  272. autoPowerCepstrum cepstrum = Spectrum_to_PowerCepstrum (spec.get());
  273. for (integer i = 1; i <= nq; i ++) {
  274. thy z [i] [iframe] = cepstrum -> z [1] [i];
  275. }
  276. if ((iframe % 10) == 1) {
  277. Melder_progress ((double) iframe / nFrames, U"PowerCepstrogram analysis of frame ",
  278. iframe, U" out of ", nFrames, U".");
  279. }
  280. }
  281. return thee;
  282. } catch (MelderError) {
  283. Melder_throw (me, U": no PowerCepstrogram created.");
  284. }
  285. }
  286. autoCepstrum Spectrum_to_Cepstrum_hillenbrand (Spectrum me);
  287. autoCepstrum Spectrum_to_Cepstrum_hillenbrand (Spectrum me) {
  288. try {
  289. autoNUMfft_Table fftTable;
  290. // originalNumberOfSamplesProbablyOdd irrelevant
  291. if (my x1 != 0.0) {
  292. Melder_throw (U"A Fourier-transformable Spectrum must have a first frequency of 0 Hz, not ", my x1, U" Hz.");
  293. }
  294. integer numberOfSamples = my nx - 1;
  295. autoCepstrum thee = Cepstrum_create (0.5 / my dx, my nx);
  296. NUMfft_Table_init (& fftTable, my nx);
  297. autoVEC amp = VECraw (my nx);
  298. for (integer i = 1; i <= my nx; i ++) {
  299. amp [i] = my v_getValueAtSample (i, 0, 2);
  300. }
  301. NUMfft_forward (& fftTable, amp.get());
  302. for (integer i = 1; i <= my nx; i ++) {
  303. double val = amp [i] / numberOfSamples;// scaling 1/n because ifft(fft(1))= n;
  304. thy z [1] [i] = val * val; // power cepstrum
  305. }
  306. return thee;
  307. } catch (MelderError) {
  308. Melder_throw (me, U": not converted to Sound.");
  309. }
  310. }
  311. // 1 2 nfftdiv2
  312. // re im re im re im
  313. // ((fft[1],0) (fft[2],fft[3]), (,), (,), (fft[nfft], 0)) nfft even
  314. // ((fft[1],0) (fft[2],fft[3]), (,), (,), (fft[nfft-1], fft[nfft])) nfft uneven
  315. static void complexfftoutput_to_power (constVEC fft, VEC dbs, bool to_db) {
  316. double valsq = fft [1] * fft [1];
  317. dbs[1] = to_db ? TOLOG (valsq) : valsq;
  318. integer nfftdiv2p1 = (fft.size + 2) / 2;
  319. integer nend = fft.size % 2 == 0 ? nfftdiv2p1 : nfftdiv2p1 + 1;
  320. for (integer i = 2; i < nend; i ++) {
  321. double re = fft [i + i - 2], im = fft [i + i - 1];
  322. valsq = re * re + im * im;
  323. dbs [i] = to_db ? TOLOG (valsq) : valsq;
  324. }
  325. if (fft.size % 2 == 0) {
  326. valsq = fft [fft.size] * fft [fft.size];
  327. dbs[nfftdiv2p1] = to_db ? TOLOG (valsq) : valsq;
  328. }
  329. }
  330. autoPowerCepstrogram Sound_to_PowerCepstrogram_hillenbrand (Sound me, double pitchFloor, double dt) {
  331. try {
  332. // minimum analysis window has 3 periods of lowest pitch
  333. double analysisWidth = 3.0 / pitchFloor;
  334. if (analysisWidth > my dx * my nx) {
  335. analysisWidth = my dx * my nx;
  336. }
  337. double samplingFrequency = 1.0 / my dx;
  338. autoSound thee;
  339. if (samplingFrequency > 30000) {
  340. samplingFrequency = samplingFrequency / 2.0;
  341. thee = Sound_resample (me, samplingFrequency, 1);
  342. } else {
  343. thee = Data_copy (me);
  344. }
  345. // pre-emphasis with fixed coefficient 0.9
  346. for (integer i = thy nx; i > 1; i --) {
  347. thy z [1] [i] -= 0.9 * thy z [1] [i - 1];
  348. }
  349. integer nosInWindow = (integer) floorl (analysisWidth * samplingFrequency), numberOfFrames;
  350. if (nosInWindow < 8) {
  351. Melder_throw (U"Analysis window too short.");
  352. }
  353. double t1;
  354. Sampled_shortTermAnalysis (thee.get(), analysisWidth, dt, & numberOfFrames, & t1);
  355. autoNUMvector<double> hamming (1, nosInWindow);
  356. for (integer i = 1; i <= nosInWindow; i ++) {
  357. hamming [i] = 0.54 -0.46 * cos(2 * NUMpi * (i - 1) / (nosInWindow - 1));
  358. }
  359. integer nfft = 8; // minimum possible
  360. while (nfft < nosInWindow) { nfft *= 2; }
  361. integer nfftdiv2 = nfft / 2;
  362. autoVEC fftbuf = VECzero (nfft); // "complex" array
  363. autoVEC spectrum = VECzero (nfftdiv2 + 1); // +1 needed
  364. autoNUMfft_Table fftTable;
  365. NUMfft_Table_init (& fftTable, nfft); // sound to spectrum
  366. double qmax = 0.5 * nfft / samplingFrequency, dq = qmax / (nfftdiv2 + 1);
  367. autoPowerCepstrogram him = PowerCepstrogram_create (my xmin, my xmax, numberOfFrames, dt, t1, 0, qmax, nfftdiv2+1, dq, 0);
  368. autoMelderProgress progress (U"Cepstrogram analysis");
  369. for (integer iframe = 1; iframe <= numberOfFrames; iframe ++) {
  370. double tbegin = t1 + (iframe - 1) * dt - analysisWidth / 2;
  371. tbegin = tbegin < thy xmin ? thy xmin : tbegin;
  372. integer istart = Sampled_xToLowIndex (thee.get(), tbegin); // ppgb: afronding naar beneden?
  373. istart = istart < 1 ? 1 : istart;
  374. integer iend = istart + nosInWindow - 1;
  375. iend = iend > thy nx ? thy nx : iend;
  376. for (integer i = 1; i <= nosInWindow; i ++) {
  377. fftbuf [i] = thy z [1] [istart + i - 1] * hamming [i];
  378. }
  379. for (integer i = nosInWindow + 1; i <= nfft; i ++) {
  380. fftbuf [i] = 0;
  381. }
  382. NUMfft_forward (&fftTable, fftbuf.get());
  383. complexfftoutput_to_power (fftbuf.get(), spectrum.get(), true); // log10(|fft|^2)
  384. // subtract average
  385. double specmean = spectrum [1];
  386. for (integer i = 2; i <= nfftdiv2 + 1; i ++) {
  387. specmean += spectrum [i];
  388. }
  389. specmean /= nfftdiv2 + 1;
  390. for (integer i = 1; i <= nfftdiv2 + 1; i ++) {
  391. spectrum [i] -= specmean;
  392. }
  393. /*
  394. * Here we diverge from Hillenbrand as he takes the fft of half of the spectral values.
  395. * H. forgets that the actual spectrum has nfft/2+1 values. Thefore, we take the inverse
  396. * transform because this keeps the number of samples a power of 2.
  397. * At the same time this results in twice as many numbers in the quefrency domain, i.e. we end up with nfft/2+1
  398. * numbers while H. has only nfft/4!
  399. */
  400. fftbuf [1] = spectrum [1];
  401. for (integer i = 2; i < nfftdiv2 + 1; i ++) {
  402. fftbuf [i+i-2] = spectrum [i];
  403. fftbuf [i+i-1] = 0;
  404. }
  405. fftbuf [nfft] = spectrum [nfftdiv2 + 1];
  406. NUMfft_backward (& fftTable, fftbuf.get());
  407. for (integer i = 1; i <= nfftdiv2 + 1; i ++) {
  408. his z [i] [iframe] = fftbuf [i] * fftbuf [i];
  409. }
  410. if ((iframe % 10) == 1) {
  411. Melder_progress ((double) iframe / numberOfFrames, U"Cepstrogram analysis of frame ",
  412. iframe, U" out of ", numberOfFrames, U".");
  413. }
  414. }
  415. return him;
  416. } catch (MelderError) {
  417. Melder_throw (me, U": no Cepstrogram created.");
  418. }
  419. }
  420. double PowerCepstrogram_getCPPS (PowerCepstrogram me, bool subtractTiltBeforeSmoothing, double timeAveragingWindow, double quefrencyAveragingWindow, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, int lineType, int fitMethod) {
  421. try {
  422. autoPowerCepstrogram flattened;
  423. if (subtractTiltBeforeSmoothing) {
  424. flattened = PowerCepstrogram_subtractTilt (me, qstartFit, qendFit, lineType, fitMethod);
  425. }
  426. autoPowerCepstrogram smooth = PowerCepstrogram_smooth (flattened ? flattened.get() : me, timeAveragingWindow, quefrencyAveragingWindow);
  427. autoTable table = PowerCepstrogram_to_Table_cpp (smooth.get(), pitchFloor, pitchCeiling, deltaF0, interpolation, qstartFit, qendFit, lineType, fitMethod);
  428. double cpps = Table_getMean (table.get(), 3);
  429. return cpps;
  430. } catch (MelderError) {
  431. Melder_throw (me, U": no CPPS value calculated.");
  432. }
  433. }
  434. double PowerCepstrogram_getCPPS_hillenbrand (PowerCepstrogram me, bool subtractTiltBeforeSmoothing, double timeAveragingWindow, double quefrencyAveragingWindow, double pitchFloor, double pitchCeiling) {
  435. try {
  436. autoPowerCepstrogram him;
  437. if (subtractTiltBeforeSmoothing) {
  438. him = PowerCepstrogram_subtractTilt (me, 0.001, 0, 1, 1);
  439. }
  440. autoPowerCepstrogram smooth = PowerCepstrogram_smooth (subtractTiltBeforeSmoothing ? him.get() : me, timeAveragingWindow, quefrencyAveragingWindow);
  441. autoTable table = PowerCepstrogram_to_Table_hillenbrand (smooth.get(), pitchFloor, pitchCeiling);
  442. double cpps = Table_getMean (table.get(), 3);
  443. return cpps;
  444. } catch (MelderError) {
  445. Melder_throw (me, U": no CPPS value calculated.");
  446. }
  447. }
  448. /* End of file Cepstrogram.cpp */