1 #include "Correlation.h" 3 #include "MainWindow.h" 6 #include <QtTest/QtTest> 7 #include "Test/TestCorrelation.h" 16 void TestCorrelation::cleanupTestCase ()
20 void TestCorrelation::initTestCase ()
22 const QString NO_ERROR_REPORT_LOG_FILE;
23 const QString NO_REGRESSION_OPEN_FILE;
24 const bool NO_GNUPLOT_LOG_FILES =
false;
25 const bool NO_REGRESSION_IMPORT =
false;
26 const bool NO_RESET =
false;
27 const bool DEBUG_FLAG =
false;
28 const QStringList NO_LOAD_STARTUP_FILES;
30 initializeLogging (
"engauge_test",
35 NO_REGRESSION_OPEN_FILE,
39 NO_LOAD_STARTUP_FILES);
43 void TestCorrelation::loadSinusoid (
double function [],
47 for (
int i = 0; i < n; i++) {
52 function [i] = qSin (x) / x;
57 void TestCorrelation::loadThreeTriangles (
double function [],
61 const int PEAK_SEPARATION = 50, PEAK_HALF_WIDTH = 5;
64 for (
int i = 0; i < n; i++) {
68 if (x > PEAK_HALF_WIDTH) {
71 x = i - (center - PEAK_SEPARATION);
72 if (x > PEAK_HALF_WIDTH) {
75 x = i - (center + PEAK_SEPARATION);
79 if (x < PEAK_HALF_WIDTH) {
82 function [i] = (double) (PEAK_HALF_WIDTH - x) / (double) PEAK_HALF_WIDTH;
91 void TestCorrelation::testShiftSinusoidNonPowerOf2 ()
94 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
97 double function1 [N], function2 [N], correlations [N];
104 loadSinusoid (function1, N, INDEX_MAX);
105 loadSinusoid (function2, N, INDEX_MAX + INDEX_SHIFT);
114 QVERIFY ((binStartMax = INDEX_SHIFT));
117 void TestCorrelation::testShiftSinusoidPowerOf2 ()
120 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
123 double function1 [N], function2 [N], correlations [N];
130 loadSinusoid (function1, N, INDEX_MAX);
131 loadSinusoid (function2, N, INDEX_MAX + INDEX_SHIFT);
140 QVERIFY ((binStartMax = INDEX_SHIFT));
143 void TestCorrelation::testShiftThreeTrianglesNonPowerOf2 ()
146 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
149 double function1 [N], function2 [N], correlations [N];
156 loadThreeTriangles (function1, N, INDEX_MAX);
157 loadThreeTriangles (function2, N, INDEX_MAX + INDEX_SHIFT);
166 QVERIFY ((binStartMax = INDEX_SHIFT));
169 void TestCorrelation::testShiftThreeTrianglesPowerOf2 ()
172 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
175 double function1 [N], function2 [N], correlations [N];
182 loadThreeTriangles (function1, N, INDEX_MAX);
183 loadThreeTriangles (function2, N, INDEX_MAX + INDEX_SHIFT);
192 QVERIFY ((binStartMax = INDEX_SHIFT));
Fast cross correlation between two functions.
Unit tests of fast correlation algorithm.
void correlateWithShift(int N, const double function1 [], const double function2 [], int &binStartMax, double &corrMax, double correlations []) const
Return the shift in function1 that best aligns that function with function2.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...