changeset 11:81eb5810a301

Added spectral centroid
author Jamie Bullock <jamie@postlude.co.uk>
date Sun, 08 Oct 2006 15:31:40 +0000
parents 998623a98706
children 1aec087ddfca
files examples/puredata/xtract~.c src/libxtract.c src/scalar.c xtract/libxtract.h xtract/xtract_scalar.h
diffstat 5 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/examples/puredata/xtract~.c	Sun Oct 08 15:05:02 2006 +0000
+++ b/examples/puredata/xtract~.c	Sun Oct 08 15:31:40 2006 +0000
@@ -101,6 +101,7 @@
     else if(tmp == gensym("average_deviation")) x->feature = AVERAGE_DEVIATION;
     else if(tmp == gensym("skewness")) x->feature = SKEWNESS;
     else if(tmp == gensym("kurtosis")) x->feature = KURTOSIS;
+    else if(tmp == gensym("centroid")) x->feature = CENTROID;
     else if(tmp == gensym("irregularity_k")) x->feature = IRREGULARITY_K;
     else if(tmp == gensym("irregularity_j")) x->feature = IRREGULARITY_J;
     else if(tmp == gensym("tristimulus_1")) x->feature = TRISTIMULUS_1;
--- a/src/libxtract.c	Sun Oct 08 15:05:02 2006 +0000
+++ b/src/libxtract.c	Sun Oct 08 15:31:40 2006 +0000
@@ -29,6 +29,7 @@
     xtract_average_deviation,
     xtract_skewness,
     xtract_kurtosis,
+    xtract_centroid,
     xtract_irregularity_k,
     xtract_irregularity_j,
     xtract_tristimulus_1,
--- a/src/scalar.c	Sun Oct 08 15:05:02 2006 +0000
+++ b/src/scalar.c	Sun Oct 08 15:31:40 2006 +0000
@@ -84,6 +84,25 @@
     
 }
 
+
+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,
--- a/xtract/libxtract.h	Sun Oct 08 15:05:02 2006 +0000
+++ b/xtract/libxtract.h	Sun Oct 08 15:31:40 2006 +0000
@@ -38,7 +38,7 @@
 #include "xtract_types.h"
 #include "xtract_macros.h"
 
-#define XTRACT_FEATURES 42
+#define XTRACT_FEATURES 43
 #define LOG_LIMIT 10e-10
 #define VERY_BIG_NUMBER 2e10
 #define SR_LIMIT 192000
@@ -52,6 +52,7 @@
     AVERAGE_DEVIATION,
     SKEWNESS,
     KURTOSIS,
+	CENTROID,
     IRREGULARITY_K,
     IRREGULARITY_J,
     TRISTIMULUS_1,
--- a/xtract/xtract_scalar.h	Sun Oct 08 15:05:02 2006 +0000
+++ b/xtract/xtract_scalar.h	Sun Oct 08 15:31:40 2006 +0000
@@ -82,6 +82,15 @@
  */
 int xtract_kurtosis(float *data, int N, void *argv,  float *result);
 
+/** \brief Extract the kurtosis of an input vector
+ * 
+ * \param *data: a pointer to the first element in an array of floats represeting a frequency spectrum of size N/2 and a magnitude peak spectrum of size N/2 (This is the output format of xtract_peaks)
+ * \param N: the number of elements to be considered
+ * \param *argv: a pointer to NULL
+ * \param *result: the centroid of the values pointed to by *data
+ */
+int xtract_centroid(float *data, int N, void *argv,  float *result);
+
 /** \brief Calculate the Irregularity of an input vector using a method described by Krimphoff (1994)
  * 
  * \param *data: a pointer to the first element in an array of floats representing the magnitude spectrum of an audio vector