aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libxtract.c1
-rw-r--r--src/scalar.c19
2 files changed, 20 insertions, 0 deletions
diff --git a/src/libxtract.c b/src/libxtract.c
index b9a98ef..8202f6d 100644
--- a/src/libxtract.c
+++ b/src/libxtract.c
@@ -29,6 +29,7 @@ int(*xtract[])(float *, int, void *, float *) = {
xtract_average_deviation,
xtract_skewness,
xtract_kurtosis,
+ xtract_centroid,
xtract_irregularity_k,
xtract_irregularity_j,
xtract_tristimulus_1,
diff --git a/src/scalar.c b/src/scalar.c
index 1cc3128..111c300 100644
--- a/src/scalar.c
+++ b/src/scalar.c
@@ -84,6 +84,25 @@ int xtract_kurtosis(float *data, int N, void *argv, float *result){
}
+
+int xtract_centroid(float *data, int N, void *argv, float *result){
+
+ int n = N;
+
+ float *freqs, *amps, FA, A;
+
+ freqs = data;
+ amps = data + (N >> 1);
+
+ while(n--){
+ FA += freqs[n] * amps[n];
+ A += amps[n];
+ }
+
+ *result = FA / A;
+
+}
+
int xtract_irregularity_k(float *data, int N, void *argv, float *result){
int n,