| 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" |
| 20 |
#include "NUM2.h" |
| 21 |
|
| 22 |
void Ltas_fitTrendLine (Ltas me, double fmin, double fmax, bool lnf, int method, double *a, double *b) { |
| 23 |
try { |
| 24 |
if (fmax <= fmin) { |
| 25 |
fmin = my xmin; |
| 26 |
fmax = my xmax; |
| 27 |
} |
| 28 |
integer ifmin, ifmax; |
| 29 |
const integer numberOfSamples = Sampled_getWindowSamples (me, fmin, fmax, & ifmin, & ifmax); |
| 30 |
Melder_require (numberOfSamples > 1, |
| 31 |
U"There should be at least two data points to fit a line."); |
| 32 |
autoVEC x = raw_VEC (numberOfSamples); |
| 33 |
autoVEC y = raw_VEC (numberOfSamples); |
| 34 |
for (integer i = ifmin; i <= ifmax; i ++) { |
| 35 |
const integer ixy = i - ifmin + 1; |
| 36 |
x [ixy] = my x1 + (i - 1) * my dx; |
| 37 |
if (lnf) |
| 38 |
x [ixy] = log10 (x [ixy]); // For Ltas always x1 > 0 |
| 39 |
y [ixy] = my z [1] [i]; |
| 40 |
} |
| 41 |
NUMlineFit (x.get(), y.get(), a, b, method); |
| 42 |
} catch (MelderError) { |
| 43 |
Melder_throw (U"Tilt line not determined."); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/* End of file Ltas_extensions.cpp */ |