Ltas_extensions.cpp 1.6 KB

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