src/spectral/fft.c: fix horrible bug where norm[0] and norm[n/2+1] could be negative
authorPaul Brossier <piem@piem.org>
Mon, 21 Sep 2009 16:15:05 +0000 (18:15 +0200)
committerPaul Brossier <piem@piem.org>
Mon, 21 Sep 2009 16:15:05 +0000 (18:15 +0200)
src/spectral/fft.c

index 31159a5..7c77083 100644 (file)
@@ -169,12 +169,13 @@ void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) {
 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) {
   uint_t i, j = 0;
   for (i = 0; i < spectrum->channels; i++) {
-    spectrum->norm[i][0] = compspec->data[i][0];
+    spectrum->norm[i][0] = ABS(compspec->data[i][0]);
     for (j=1; j < spectrum->length - 1; j++) {
       spectrum->norm[i][j] = SQRT(SQR(compspec->data[i][j]) 
           + SQR(compspec->data[i][compspec->length - j]) );
     }
-    spectrum->norm[i][spectrum->length-1] = compspec->data[i][compspec->length/2];
+    spectrum->norm[i][spectrum->length-1] = 
+      ABS(compspec->data[i][compspec->length/2]);
   }
 }