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