Fix test signals for order 1 tests, and enable these tests.
o For signal type 2, the expected FFT was incorrect; it should be all zeros
because the input is all zeroes.
o For signal type 3, the expected FFT was incorrect.
o A few optimizations to remove round-off errors in computing sin(pi).
BUG=
R=andrew@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/2819004
git-svn-id: http://webrtc.googlecode.com/svn/deps/third_party/openmax@5034 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/dl/sp/src/test/gensig.c b/dl/sp/src/test/gensig.c
index c019bf2..17bee53 100644
--- a/dl/sp/src/test/gensig.c
+++ b/dl/sp/src/test/gensig.c
@@ -80,6 +80,11 @@
fft[k].Re = factor * -size / 2;
fft[k].Im = factor * size / 2 * (sin(phase) / (1 - cos(phase)));
}
+
+ /*
+ * Remove any roundoff for k = N/2 since sin(2*pi/N*N/2) = 0.
+ */
+ fft[size / 2].Im = 0;
}
break;
case 2:
@@ -94,12 +99,23 @@
x[k].Im = 0;
}
+ /*
+ * Remove any roundoff for k = N/2 since sin(2*pi/N*N/2) = 0.
+ */
+ x[size / 2 ].Re = 0;
+
for (k = 0; k < size; ++k) {
fft[k].Re = 0;
fft[k].Im = 0;
}
- fft[1].Im = -signal_value * (size / 2);
- fft[size - 1].Im = signal_value * (size / 2);
+
+ /*
+ * When size == 2, x[k] is identically zero, so the FFT is also zero.
+ */
+ if (size != 2) {
+ fft[1].Im = -signal_value * (size / 2);
+ fft[size - 1].Im = signal_value * (size / 2);
+ }
}
break;
case 3:
@@ -117,9 +133,21 @@
x[1].Im = -signal_value;
x[size-1].Im = signal_value;
- for (k = 0; k < size; ++k) {
- fft[k].Re = -2 * signal_value * sin(omega * k);
- fft[k].Im = 0;
+ if (size == 2) {
+ fft[0].Re = 0;
+ fft[0].Im = signal_value;
+ fft[1].Re = 0;
+ fft[1].Im = -signal_value;
+ } else {
+ for (k = 0; k < size; ++k) {
+ fft[k].Re = -2 * signal_value * sin(omega * k);
+ fft[k].Im = 0;
+ }
+
+ /*
+ * Remove any roundoff for k = N/2 since sin(2*pi/N*N/2) = 0.
+ */
+ fft[size / 2].Re = 0;
}
break;
}
diff --git a/dl/sp/src/test/test_util.c b/dl/sp/src/test/test_util.c
index 69830b6..8f0e3b7 100644
--- a/dl/sp/src/test/test_util.c
+++ b/dl/sp/src/test/test_util.c
@@ -88,7 +88,7 @@
options->test_mode_ = 1;
options->do_forward_tests_ = 1;
options->do_inverse_tests_ = 1;
- options->min_fft_order_ = 2;
+ options->min_fft_order_ = 1;
options->max_fft_order_ = max_fft_order;
/*