Spectrum.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef _Spectrum_h_
  2. #define _Spectrum_h_
  3. /* Spectrum.h
  4. *
  5. * Copyright (C) 1992-2011,2015,2017 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. /* Complex spectrum. */
  21. /* If it comes from a sound (expressed in Pa), the values are expressed in Pa/Hz. */
  22. #include "Matrix.h"
  23. #include "Graphics.h"
  24. #include "Spectrum_def.h"
  25. /*
  26. xmin // lowest frequency (Hz)
  27. xmax // highest frequency (Hz)
  28. nx // number of frequencies
  29. dx // frequency step (Hz)
  30. x1 // first frequency (Hz)
  31. ymin = 1.0 // first row: real part
  32. ymax = 2.0 // second row: imaginary part
  33. ny = 2 // two rows
  34. dy = y1 = 1.0 // y is row number
  35. */
  36. autoSpectrum Spectrum_create (double fmax, integer nf);
  37. /* Preconditions:
  38. fmax > 0.0;
  39. nf >= 2;
  40. Postconditions:
  41. my xmin == 0.0;
  42. my xmax == fmax;
  43. my nx == nf;
  44. my dx == fmax / (nx - 1);
  45. my x1 == 0.0;
  46. my ymin == 1;
  47. my ymax == 2;
  48. my ny == 2;
  49. my dy == 1;
  50. my y1 == 1;
  51. my z [1..ny] [1..nx] == 0.0;
  52. */
  53. int Spectrum_getPowerDensityRange (Spectrum me, double *minimum, double *maximum); // return 0 if all zeroes
  54. double Spectrum_getBandDensity (Spectrum me, double fmin, double fmax); // Pa2 / Hz2
  55. double Spectrum_getBandEnergy (Spectrum me, double fmin, double fmax); // Pa2 sec
  56. double Spectrum_getBandDensityDifference (Spectrum me,
  57. double lowBandMin, double lowBandMax, double highBandMin, double HighBandMax);
  58. double Spectrum_getBandEnergyDifference (Spectrum me,
  59. double lowBandMin, double lowBandMax, double highBandMin, double highBandMax);
  60. /*
  61. Spectral moments.
  62. */
  63. double Spectrum_getCentreOfGravity (Spectrum me, double power);
  64. double Spectrum_getCentralMoment (Spectrum me, double moment, double power);
  65. double Spectrum_getStandardDeviation (Spectrum me, double power);
  66. double Spectrum_getSkewness (Spectrum me, double power);
  67. double Spectrum_getKurtosis (Spectrum me, double power);
  68. void Spectrum_drawInside (Spectrum me, Graphics g, double fmin, double fmax, double minimum, double maximum);
  69. void Spectrum_draw (Spectrum me, Graphics g, double fmin, double fmax, double minimum, double maximum, int garnish);
  70. /*
  71. Function:
  72. draw a Spectrum into a Graphics.
  73. Preconditions:
  74. maximum > minimum;
  75. Arguments:
  76. [fmin, fmax]: frequencies in Hz; x domain of drawing;
  77. Autowindowing: if fmax <= fmin, x domain of drawing is [my xmin, my xmax].
  78. [minimum, maximum]: power in dB/Hz; y range of drawing.
  79. */
  80. void Spectrum_drawLogFreq (Spectrum me, Graphics g, double fmin, double fmax, double minimum, double maximum, int garnish);
  81. autoTable Spectrum_downto_Table (Spectrum me, bool includeBinNumbers, bool includeFrequency,
  82. bool includeRealPart, bool includeImaginaryPart, bool includeEnergyDensity, bool includePowerDensity);
  83. void Spectrum_list (Spectrum me, bool includeBinNumbers, bool includeFrequency,
  84. bool includeRealPart, bool includeImaginaryPart, bool includeEnergyDensity, bool includePowerDensity);
  85. autoSpectrum Matrix_to_Spectrum (Matrix me);
  86. autoMatrix Spectrum_to_Matrix (Spectrum me);
  87. autoSpectrum Spectrum_cepstralSmoothing (Spectrum me, double bandWidth);
  88. void Spectrum_passHannBand (Spectrum me, double fmin, double fmax, double smooth);
  89. void Spectrum_stopHannBand (Spectrum me, double fmin, double fmax, double smooth);
  90. void Spectrum_getNearestMaximum (Spectrum me, double frequency, double *frequencyOfMaximum, double *heightOfMaximum);
  91. /* End of file Spectrum.h */
  92. #endif