| 1 | /* Roots_to_Spectrum.cpp |
| 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 | * 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 | #include "Roots_to_Spectrum.h" |
| 20 | |
| 21 | autoSpectrum Roots_to_Spectrum (constRoots me, double nyquistFrequency, integer numberOfFrequencies, double radius) { |
| 22 | try { |
| 23 | Melder_require (numberOfFrequencies > 1, |
| 24 | U"Number of frequencies should be greater than 1."); |
| 25 | autoSpectrum thee = Spectrum_create (nyquistFrequency, numberOfFrequencies); |
| 26 | |
| 27 | const double phi = NUMpi / (numberOfFrequencies - 1); |
| 28 | dcomplex z; |
| 29 | for (integer i = 1; i <= numberOfFrequencies; i ++) { |
| 30 | z. real (radius * cos ((i - 1) * phi)); |
| 31 | z. imag (radius * sin ((i - 1) * phi)); |
| 32 | const dcomplex s = Roots_evaluate_z (me, z); |
| 33 | thy z [1] [i] = s.real(); |
| 34 | thy z [2] [i] = s.imag(); |
| 35 | } |
| 36 | return thee; |
| 37 | } catch (MelderError) { |
| 38 | Melder_throw (me, U": no Spectrum calculated."); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /* End of file Roots.cpp */ |