src/spectral/fft.c: 0 and N/2 + 1 phase must carry the sign of respective real components
authorPaul Brossier <piem@piem.org>
Sun, 11 Oct 2009 10:38:43 +0000 (12:38 +0200)
committerPaul Brossier <piem@piem.org>
Sun, 11 Oct 2009 10:38:43 +0000 (12:38 +0200)
src/spectral/fft.c

index 2aea246dd29bc6841d3828d7ee1d4fcd148adb77..c3af6a2d53e8c2126e1ddbdfa5d8ea06a29e2c3a 100644 (file)
@@ -183,12 +183,20 @@ void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec) {
 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) {
   uint_t i, j;
   for (i = 0; i < spectrum->channels; i++) {
-    spectrum->phas[i][0] = 0.;
+    if (compspec->data[i][0] < 0) {
+      spectrum->phas[i][0] = PI;
+    } else {
+      spectrum->phas[i][0] = 0.;
+    }
     for (j=1; j < spectrum->length - 1; j++) {
       spectrum->phas[i][j] = ATAN2(compspec->data[i][compspec->length-j],
           compspec->data[i][j]);
     }
-    spectrum->phas[i][spectrum->length-1] = 0.;
+    if (compspec->data[i][compspec->length/2] < 0) {
+      spectrum->phas[i][spectrum->length - 1] = PI;
+    } else {
+      spectrum->phas[i][spectrum->length - 1] = 0.;
+    }
   }
 }