diff options
author | Sean Enderby <sean.enderby@gmail.com> | 2014-02-17 11:20:59 +0000 |
---|---|---|
committer | Sean Enderby <sean.enderby@gmail.com> | 2014-02-17 11:20:59 +0000 |
commit | f669d29aa97931edf1eb5f2f06af834492893076 (patch) | |
tree | d6aceeafd93746857624922e56ad12330b79e4c4 /src/scalar.c | |
parent | b1f7c9f6c440838da18f8c1d7712036c867e7a77 (diff) | |
download | LibXtract-f669d29aa97931edf1eb5f2f06af834492893076.tar.gz LibXtract-f669d29aa97931edf1eb5f2f06af834492893076.tar.bz2 LibXtract-f669d29aa97931edf1eb5f2f06af834492893076.zip |
quick fix to xtract_irregularity_j and a sort of working xtract_hps
Diffstat (limited to 'src/scalar.c')
-rw-r--r-- | src/scalar.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/scalar.c b/src/scalar.c index 07dc77b..b7d3806 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -283,7 +283,7 @@ int xtract_irregularity_k(const double *data, const int N, const void *argv, dou 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_nonzero_count(const double *data, const int N, const void *argv, doub } -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,8 +876,40 @@ int xtract_hps(const double *data, const int N, const void *argv, double *result 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) { |