aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Enderby <sean.enderby@gmail.com>2014-02-25 13:19:04 +0000
committerSean Enderby <sean.enderby@gmail.com>2014-02-25 13:19:04 +0000
commit08de2740a76f38d50adaa326c8c6c2f0988316b9 (patch)
treee0cd3ee258c72760b7574c16a0538801bb46abf3 /src
parentee2b29b3b5a0de5e1ed1026ebe5d753469e43201 (diff)
downloadLibXtract-08de2740a76f38d50adaa326c8c6c2f0988316b9.tar.gz
LibXtract-08de2740a76f38d50adaa326c8c6c2f0988316b9.tar.bz2
LibXtract-08de2740a76f38d50adaa326c8c6c2f0988316b9.zip
tristimulus1 correction
Diffstat (limited to 'src')
-rw-r--r--src/scalar.c122
1 files changed, 113 insertions, 9 deletions
diff --git a/src/scalar.c b/src/scalar.c
index 3a9abdf..84c3900 100644
--- a/src/scalar.c
+++ b/src/scalar.c
@@ -298,22 +298,126 @@ int xtract_irregularity_j(const double *data, const int N, const void *argv, dou
return XTRACT_SUCCESS;
}
+/*
+ *int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result)
+ *{
+ *
+ * int n = N;
+ *
+ * double den, p1, temp;
+ *
+ * den = p1 = temp = 0.0;
+ *
+ * for(n = 0; n < N; n++)
+ * {
+ * if((temp = data[n]))
+ * {
+ * den += temp;
+ * if(!p1)
+ * p1 = temp;
+ * }
+ * }
+ *
+ * if(den == 0.0 || p1 == 0.0)
+ * {
+ * *result = 0.0;
+ * return XTRACT_NO_RESULT;
+ * }
+ * else
+ * {
+ * *result = p1 / den;
+ * return XTRACT_SUCCESS;
+ * }
+ *}
+ *
+ *int xtract_tristimulus_2(const double *data, const int N, const void *argv, double *result)
+ *{
+ *
+ * int n = N;
+ *
+ * double den, p2, p3, p4, ps, temp;
+ *
+ * den = p2 = p3 = p4 = ps = temp = 0.0;
+ *
+ * for(n = 0; n < N; n++)
+ * {
+ * if((temp = data[n]))
+ * {
+ * den += temp;
+ * if(!p2)
+ * p2 = temp;
+ * else if(!p3)
+ * p3 = temp;
+ * else if(!p4)
+ * p4 = temp;
+ * }
+ * }
+ *
+ * ps = p2 + p3 + p4;
+ *
+ * if(den == 0.0 || ps == 0.0)
+ * {
+ * *result = 0.0;
+ * return XTRACT_NO_RESULT;
+ * }
+ * else
+ * {
+ * *result = ps / den;
+ * return XTRACT_SUCCESS;
+ * }
+ *
+ *}
+ *
+ *int xtract_tristimulus_3(const double *data, const int N, const void *argv, double *result)
+ *{
+ *
+ * int n = N, count = 0;
+ *
+ * double den, num, temp;
+ *
+ * den = num = temp = 0.0;
+ *
+ * for(n = 0; n < N; n++)
+ * {
+ * if((temp = data[n]))
+ * {
+ * den += temp;
+ * if(count >= 5)
+ * num += temp;
+ * count++;
+ * }
+ * }
+ *
+ * if(den == 0.0 || num == 0.0)
+ * {
+ * *result = 0.0;
+ * return XTRACT_NO_RESULT;
+ * }
+ * else
+ * {
+ * *result = num / den;
+ * return XTRACT_SUCCESS;
+ * }
+ *}
+ */
+
int xtract_tristimulus_1(const double *data, const int N, const void *argv, double *result)
{
+ int n = N >> 1, h = 0, i;
+ double den = 0.0, p1 = 0.0, fund = 0.0, temp = 0.0;
+ const double *freqs;
- int n = N;
-
- double den, p1, temp;
-
- den = p1 = temp = 0.0;
+ fund = *(double *)argv;
+ freqs = data + n;
- for(n = 0; n < N; n++)
+ for(i = 0; i < n; i++)
{
- if((temp = data[n]))
+ if((temp = data[i]))
{
den += temp;
- if(!p1)
- p1 = temp;
+ h = round(freqs[i] / fund);
+ if(h == 1)
+ p1 += temp;
}
}