comparison src/scalar.c @ 196:e764049c0a82

quick fix to xtract_irregularity_j and a sort of working xtract_hps
author Sean Enderby <sean.enderby@gmail.com>
date Mon, 17 Feb 2014 11:20:59 +0000
parents e63fa5ad1902
children 951035634fb1
comparison
equal deleted inserted replaced
195:e63fa5ad1902 196:e764049c0a82
281 } 281 }
282 282
283 int xtract_irregularity_j(const double *data, const int N, const void *argv, double *result) 283 int xtract_irregularity_j(const double *data, const int N, const void *argv, double *result)
284 { 284 {
285 285
286 int n = N; 286 int n = N - 1;
287 287
288 double num = 0.0, den = 0.0; 288 double num = 0.0, den = 0.0;
289 289
290 while(n--) 290 while(n--)
291 { 291 {
806 806
807 return XTRACT_SUCCESS; 807 return XTRACT_SUCCESS;
808 808
809 } 809 }
810 810
811 int xtract_hps(const double *data, const int N, const void *argv, double *result) 811 /*int xtract_hps(const double *data, const int N, const void *argv, double *result)
812 { 812 {
813 813
814 int n = N, M, m, l, peak_index, position1_lwr; 814 int n = N, M, m, l, peak_index, position1_lwr;
815 double *coeffs2, *coeffs3, *product, L, 815 double *coeffs2, *coeffs3, *product, L,
816 largest1_lwr, peak, ratio1, sr; 816 largest1_lwr, peak, ratio1, sr;
874 free(coeffs2); 874 free(coeffs2);
875 free(coeffs3); 875 free(coeffs3);
876 free(product); 876 free(product);
877 877
878 return XTRACT_SUCCESS; 878 return XTRACT_SUCCESS;
879 } 879 }*/
880 880
881 int xtract_hps(const double *data, const int N, const void *argv, double *result)
882 {
883 int numBins, numBinsToUse, i, maxIndex;
884 double tempProduct, currentMax;
885
886 numBins = N / 2;
887
888 numBinsToUse = ceil(numBins / 3.0);
889
890 if (numBinsToUse <= 1)
891 {
892 /* Input data is too short. */
893 *result = 0;
894 return XTRACT_NO_RESULT;
895 }
896
897 tempProduct = currentMax = 0;
898 for (i = 0; i < numBinsToUse; ++i)
899 {
900 tempProduct = data [i] * data [i * 2] * data [i * 3];
901
902 if (tempProduct > currentMax)
903 {
904 currentMax = tempProduct;
905 maxIndex = i;
906 }
907 }
908
909 *result = data [numBins + maxIndex];
910
911 return XTRACT_SUCCESS;
912 }
881 913
882 int xtract_f0(const double *data, const int N, const void *argv, double *result) 914 int xtract_f0(const double *data, const int N, const void *argv, double *result)
883 { 915 {
884 916
885 int M, tau, n; 917 int M, tau, n;