| 1 | /* Polynomial_to_Spectrum.h |
| 2 | * |
| 3 | * Copyright (C) 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 | */ |
| 14 | |
| 15 | #include "Polynomial_to_Spectrum.h"cxx . . $ `<file>/dwtools/Polynomial_to_Spectrum.h`/ |
| 16 | |
| 17 | static void Polynomial_evaluate_z_cartcxx . . $ Polynomial_evaluate_z_cart(c1089ed4e8332b91). (Polynomialcxx . . $ Polynomial# me, double r, double phi, double *out_re, double *out_im) { |
| 18 | longdoublecxx . . $ longdouble# rn = 1.0; |
| 19 | |
| 20 | longdoublecxx . . $ longdouble# re = mycxx . . $ `melder/melder.h:44:9`! coefficientscxx . . $ structFunctionSeries#coefficients. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 21 | longdoublecxx . . $ longdouble# im = 0.0; |
| 22 | if (r == 0.0) |
| 23 | return; |
| 24 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfCoefficientscxx . . $ structFunctionSeries#numberOfCoefficients.; i ++) { |
| 25 | rn *= r; |
| 26 | const longdoublecxx . . $ longdouble# arg = (i - 1) * phi; |
| 27 | re += mycxx . . $ `melder/melder.h:44:9`! coefficientscxx . . $ structFunctionSeries#coefficients. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * rn * coscxx . . $ cos(cd6880bb7604d12e). (arg); |
| 28 | im += mycxx . . $ `melder/melder.h:44:9`! coefficientscxx . . $ structFunctionSeries#coefficients. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * rn * sincxx . . $ sin(cd6880bb7604d12e). (arg); |
| 29 | } |
| 30 | if (out_re) |
| 31 | *out_re = (double) re; |
| 32 | if (out_im) |
| 33 | *out_im = (double) im; |
| 34 | } |
| 35 | |
| 36 | /* Can be speeded up by doing a FFT */ |
| 37 | autoSpectrumcxx . . $ autoSpectrum# Polynomial_to_Spectrumcxx . . $ Polynomial_to_Spectrum(360e7ebab52179de). (Polynomialcxx . . $ Polynomial# me, double nyquistFrequency, integercxx . . $ integer# numberOfFrequencies, double radius) { |
| 38 | try { |
| 39 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (numberOfFrequencies > 1, |
| 40 | U"Number of frequencies should be greater than 1."); |
| 41 | autoSpectrumcxx . . $ autoSpectrum# thee = Spectrum_createcxx . . $ Spectrum_create(a338b9c326abb5ed). (nyquistFrequency, numberOfFrequencies); |
| 42 | |
| 43 | const double phi = NUMpicxx . . $ NUMpi. / (numberOfFrequencies - 1); |
| 44 | for (integercxx . . $ integer# i = 1; i <= numberOfFrequencies; i ++) { |
| 45 | double re, im; |
| 46 | Polynomial_evaluate_z_cartcxx . . $ Polynomial_evaluate_z_cart(c1089ed4e8332b91). (me, radius, (i - 1) * phi, & re, & im); |
| 47 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = re; |
| 48 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = im; |
| 49 | } |
| 50 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 51 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 52 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no Spectrum calculated."); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /* End of file Polynomial_to_Spectrum.cpp */ |