| 1 | /* Ltas_extensions.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012-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. |
| 13 | * See the GNU 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 "Ltas_extensions.h"cxx . . $ `<file>/dwtools/Ltas_extensions.h`/ |
| 20 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 21 | |
| 22 | void Ltas_fitTrendLinecxx . . $ Ltas_fitTrendLine(8dd9f9c55d31fd6a). (Ltascxx . . $ Ltas# me, double fmin, double fmax, bool lnf, int method, double *a, double *b) { |
| 23 | try { |
| 24 | if (fmax <= fmin) { |
| 25 | fmin = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 26 | fmax = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 27 | } |
| 28 | integercxx . . $ integer# ifmin, ifmax; |
| 29 | const integercxx . . $ integer# numberOfSamples = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, fmin, fmax, & ifmin, & ifmax); |
| 30 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (numberOfSamples > 1, |
| 31 | U"There should be at least two data points to fit a line."); |
| 32 | autoVECcxx . . $ autoVEC# x = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfSamples); |
| 33 | autoVECcxx . . $ autoVEC# y = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfSamples); |
| 34 | for (integercxx . . $ integer# i = ifmin; i <= ifmax; i ++) { |
| 35 | const integercxx . . $ integer# ixy = i - ifmin + 1; |
| 36 | x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ixy] = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (i - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 37 | if (lnf) |
| 38 | x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ixy] = log10cxx . . $ log10(fee4f1d22bc8e617). (x [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ixy]); // For Ltas always x1 > 0 |
| 39 | y [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ixy] = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 40 | } |
| 41 | NUMlineFitcxx . . $ NUMlineFit(8c21accacb989bfe). (xcxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), ycxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), a, b, method); |
| 42 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 43 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Tilt line not determined."); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /* End of file Ltas_extensions.cpp */ |