diff 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
line wrap: on
line diff
--- a/src/scalar.c	Wed Feb 12 08:36:58 2014 +0000
+++ b/src/scalar.c	Mon Feb 17 11:20:59 2014 +0000
@@ -283,7 +283,7 @@
 int xtract_irregularity_j(const double *data, const int N, const void *argv, double *result)
 {
 
-    int n = N;
+    int n = N - 1;
 
     double num = 0.0, den = 0.0;
 
@@ -808,7 +808,7 @@
 
 }
 
-int xtract_hps(const double *data, const int N, const void *argv, double *result)
+/*int xtract_hps(const double *data, const int N, const void *argv, double *result)
 {
 
     int n = N, M, m, l, peak_index, position1_lwr;
@@ -876,9 +876,41 @@
     free(product);
 
     return XTRACT_SUCCESS;
+}*/
+
+int xtract_hps(const double *data, const int N, const void *argv, double *result)
+{
+    int numBins, numBinsToUse, i, maxIndex;
+    double tempProduct, currentMax;
+
+    numBins = N / 2;
+
+    numBinsToUse = ceil(numBins / 3.0);
+
+    if (numBinsToUse <= 1)
+    {
+        /* Input data is too short. */
+        *result = 0;
+        return XTRACT_NO_RESULT;
+    }
+
+    tempProduct = currentMax = 0;
+    for (i = 0; i < numBinsToUse; ++i)
+    {
+        tempProduct = data [i] * data [i * 2] * data [i * 3];
+
+        if (tempProduct > currentMax)
+        {
+            currentMax = tempProduct;
+            maxIndex = i;
+        }
+    }
+
+    *result = data [numBins + maxIndex];
+
+    return XTRACT_SUCCESS;
 }
 
-
 int xtract_f0(const double *data, const int N, const void *argv, double *result)
 {