1 #ifndef _Spectrum_h_ 2 #define _Spectrum_h_ 3 /* Spectrum.h 4 * 5 * Copyright (C) 1992-2005,2007,2011,2015-2017,2019-2021 Paul Boersma 6 * 7 * This code is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or (at 10 * your option) any later version. 11 * 12 * This code is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 * See the GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this work. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 /* Complex spectrum. */ 22 /* If it comes from a sound (expressed in Pa), the values are expressed in Pa/Hz. */ 23 24 #include "Matrix.h" 25 #include "Graphics.h" 26 27 #include "Spectrum_def.h" 28 29 /* 30 xmin // lowest frequency (Hz) 31 xmax // highest frequency (Hz) 32 nx // number of frequencies 33 dx // frequency step (Hz) 34 x1 // first frequency (Hz) 35 ymin = 1.0 // first row: real part 36 ymax = 2.0 // second row: imaginary part 37 ny = 2 // two rows 38 dy = y1 = 1.0 // y is row number 39 */ 40 41 autoSpectrum Spectrum_create (double fmax, integer nf); 42 /* Preconditions: 43 fmax > 0.0; 44 nf >= 2; 45 Postconditions: 46 my xmin == 0.0; 47 my xmax == fmax; 48 my nx == nf; 49 my dx == fmax / (nx - 1); 50 my x1 == 0.0; 51 my ymin == 1; 52 my ymax == 2; 53 my ny == 2; 54 my dy == 1; 55 my y1 == 1; 56 my z [1..ny] [1..nx] == 0.0; 57 */ 58 59 int Spectrum_getPowerDensityRange (Spectrum me, double *minimum, double *maximum); // return 0 if all zeroes 60 double Spectrum_getBandDensity (Spectrum me, double fmin, double fmax); // Pa2 / Hz2 61 double Spectrum_getBandEnergy (Spectrum me, double fmin, double fmax); // Pa2 sec 62 double Spectrum_getBandDensityDifference (Spectrum me, 63 double lowBandMin, double lowBandMax, double highBandMin, double HighBandMax); 64 double Spectrum_getBandEnergyDifference (Spectrum me, 65 double lowBandMin, double lowBandMax, double highBandMin, double highBandMax); 66 67 /* 68 Spectral moments. 69 */ 70 double Spectrum_getCentreOfGravity (Spectrum me, double power); 71 double Spectrum_getCentralMoment (Spectrum me, double moment, double power); 72 double Spectrum_getStandardDeviation (Spectrum me, double power); 73 double Spectrum_getSkewness (Spectrum me, double power); 74 double Spectrum_getKurtosis (Spectrum me, double power); 75 76 void Spectrum_drawInside (Spectrum me, Graphics g, double fmin, double fmax, double minimum, double maximum); 77 void Spectrum_draw (Spectrum me, Graphics g, double fmin, double fmax, double minimum, double maximum, bool garnish); 78 /* 79 Function: 80 draw a Spectrum into a Graphics. 81 Preconditions: 82 maximum > minimum; 83 Arguments: 84 [fmin, fmax]: frequencies in Hz; x domain of drawing; 85 Autowindowing: if fmax <= fmin, x domain of drawing is [my xmin, my xmax]. 86 [minimum, maximum]: power in dB/Hz; y range of drawing. 87 */ 88 void Spectrum_drawLogFreq (Spectrum me, Graphics g, double fmin, double fmax, double minimum, double maximum, bool garnish); 89 90 autoTable Spectrum_tabulate (Spectrum me, bool includeBinNumbers, bool includeFrequency, 91 bool includeRealPart, bool includeImaginaryPart, bool includeEnergyDensity, bool includePowerDensity); 92 autoTable Spectrum_tabulate_verbose (Spectrum me); 93 94 autoSpectrum Matrix_to_Spectrum (Matrix me); 95 96 autoMatrix Spectrum_to_Matrix (Spectrum me); 97 98 autoSpectrum Spectrum_cepstralSmoothing (Spectrum me, double bandWidth); 99 100 void Spectrum_passHannBand (Spectrum me, double fmin, double fmax, double smooth); 101 void Spectrum_stopHannBand (Spectrum me, double fmin, double fmax, double smooth); 102 103 MelderPoint Spectrum_getNearestMaximum (Spectrum me, double frequency); 104 105 /* End of file Spectrum.h */ 106 #endif 107