LPC_to_Spectrogram.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* LPC_to_Spectrogram.cpp
  2. *
  3. * Copyright (C) 1994-2018 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 20020812 GPL header
  20. djmw 20080122 float -> double
  21. */
  22. #include "LPC_to_Spectrogram.h"
  23. autoSpectrogram LPC_to_Spectrogram (LPC me, double dfMin, double bandwidthReduction, double deEmphasisFrequency) {
  24. try {
  25. double samplingFrequency = 1.0 / my samplingPeriod;
  26. integer nfft = 2;
  27. if (dfMin <= 0.0) {
  28. nfft = 512;
  29. dfMin = samplingFrequency / nfft;
  30. }
  31. while (samplingFrequency / nfft > dfMin || nfft <= my maxnCoefficients) nfft *= 2;
  32. double freqStep = samplingFrequency / nfft;
  33. autoSpectrogram thee = Spectrogram_create (my xmin, my xmax, my nx, my dx, my x1, 0.0, samplingFrequency / 2.0, nfft / 2 + 1, freqStep, 0.0);
  34. for (integer i = 1; i <= my nx; i ++) {
  35. double t = Sampled_indexToX (me, i);
  36. autoSpectrum spec = LPC_to_Spectrum (me, t, dfMin, bandwidthReduction, deEmphasisFrequency);
  37. for (integer j = 1; j <= spec -> nx; j ++) {
  38. double re = spec -> z [1] [j], im = spec -> z [2] [j];
  39. thy z [j] [i] = re * re + im * im;
  40. }
  41. }
  42. return thee;
  43. } catch (MelderError) {
  44. Melder_throw (me, U": no Spectrogram created.");
  45. }
  46. }
  47. /* End of file LPC_to_Spectrogram.cpp */