| 1 |
/* Cepstrum.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1994-2020 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 |
/* |
| 20 |
djmw 20010514 |
| 21 |
djmw 20020812 GPL header |
| 22 |
djmw 20080122 Version 1: float -> double |
| 23 |
djmw 20110304 Thing_new |
| 24 |
*/ |
| 25 |
|
| 26 |
#include "Cepstrum.h" |
| 27 |
#include "NUM2.h" |
| 28 |
#include "Vector.h" |
| 29 |
|
| 30 |
#include "enums_getText.h" |
| 31 |
#include "Cepstrum_enums.h" |
| 32 |
#include "enums_getValue.h" |
| 33 |
#include "Cepstrum_enums.h" |
| 34 |
|
| 35 |
Thing_implement (Cepstrum, Matrix, 2); |
| 36 |
|
| 37 |
double structCepstrum :: v_getValueAtSample (integer isamp, integer which, int units) const { |
| 38 |
if (which == 1) { |
| 39 |
if (units == 0) |
| 40 |
return z [1] [isamp]; |
| 41 |
else |
| 42 |
return 20.0 * log10 (fabs (z [1] [isamp]) + 1e-30); // dB's |
| 43 |
} |
| 44 |
return undefined; |
| 45 |
} |
| 46 |
|
| 47 |
autoCepstrum Cepstrum_create (double qmax, integer nq) { |
| 48 |
try { |
| 49 |
autoCepstrum me = Thing_new (Cepstrum); |
| 50 |
double dq = qmax / (nq - 1); |
| 51 |
|
| 52 |
Matrix_init (me.get(), 0.0, qmax, nq, dq, 0.0, 1.0, 1.0, 1, 1, 1.0); |
| 53 |
return me; |
| 54 |
} catch (MelderError) { |
| 55 |
Melder_throw (U"Cepstrum not created."); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
void Cepstrum_draw (constCepstrum me, Graphics g, double qmin, double qmax, double minimum, double maximum, bool power, bool garnish) { |
| 60 |
Graphics_setInner (g); |
| 61 |
|
| 62 |
if (qmax <= qmin) { |
| 63 |
qmin = my xmin; |
| 64 |
qmax = my xmax; |
| 65 |
} |
| 66 |
|
| 67 |
integer imin, imax; |
| 68 |
integer numberOfSelected = Matrix_getWindowSamplesX (me, qmin, qmax, & imin, & imax); |
| 69 |
if (numberOfSelected == 0) |
| 70 |
return; |
| 71 |
autoVEC y = raw_VEC (numberOfSelected); |
| 72 |
for (integer i = 1; i <= numberOfSelected; i ++) |
| 73 |
y [i] = my v_getValueAtSample (imin + i - 1, 1, (power ? 1 : 0)); |
| 74 |
|
| 75 |
if (minimum >= maximum) // autoscaling |
| 76 |
NUMextrema_u (y.get(), & minimum, & maximum); |
| 77 |
else |
| 78 |
VECclip_inplace (minimum, y.get(), maximum); |
| 79 |
if (isundef (minimum) || isundef (maximum)) |
| 80 |
return; |
| 81 |
if (maximum == minimum) { |
| 82 |
maximum += 1.0; |
| 83 |
minimum -= 1.0; |
| 84 |
} |
| 85 |
Graphics_setWindow (g, qmin, qmax, minimum, maximum); |
| 86 |
Graphics_function (g, y.asArgumentToFunctionThatExpectsOneBasedArray(), 1, numberOfSelected, Matrix_columnToX (me, imin), Matrix_columnToX (me, imax)); |
| 87 |
|
| 88 |
Graphics_unsetInner (g); |
| 89 |
|
| 90 |
if (garnish) { |
| 91 |
Graphics_drawInnerBox (g); |
| 92 |
Graphics_textBottom (g, true, U"Quefrency (s)"); |
| 93 |
Graphics_marksBottom (g, 2, true, true, false); |
| 94 |
Graphics_textLeft (g, true, power ? U"Amplitude (dB)" : U"Amplitude"); |
| 95 |
Graphics_marksLeft (g, 2, true, true, false); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
void Cepstrum_drawLinear (constCepstrum me, Graphics g, double qmin, double qmax, double minimum, double maximum, bool garnish) { |
| 100 |
Cepstrum_draw (me, g, qmin, qmax, minimum, maximum, false, garnish); |
| 101 |
} |
| 102 |
|
| 103 |
/* End of file Cepstrum.cpp */ |