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 DEBUG_FLAG =
false;
27 const QStringList NO_LOAD_STARTUP_FILES;
29 initializeLogging (
"engauge_test",
34 NO_REGRESSION_OPEN_FILE,
37 NO_LOAD_STARTUP_FILES);
41 void TestCorrelation::loadSinusoid (
double function [],
45 for (
int i = 0; i < n; i++) {
50 function [i] = qSin (x) / x;
55 void TestCorrelation::loadThreeTriangles (
double function [],
59 const int PEAK_SEPARATION = 50, PEAK_HALF_WIDTH = 5;
62 for (
int i = 0; i < n; i++) {
66 if (x > PEAK_HALF_WIDTH) {
69 x = i - (center - PEAK_SEPARATION);
70 if (x > PEAK_HALF_WIDTH) {
73 x = i - (center + PEAK_SEPARATION);
77 if (x < PEAK_HALF_WIDTH) {
80 function [i] = (double) (PEAK_HALF_WIDTH - x) / (double) PEAK_HALF_WIDTH;
89 void TestCorrelation::testShiftSinusoidNonPowerOf2 ()
92 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
95 double function1 [N], function2 [N], correlations [N];
102 loadSinusoid (function1, N, INDEX_MAX);
103 loadSinusoid (function2, N, INDEX_MAX + INDEX_SHIFT);
112 QVERIFY (binStartMax = INDEX_SHIFT);
115 void TestCorrelation::testShiftSinusoidPowerOf2 ()
118 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
121 double function1 [N], function2 [N], correlations [N];
128 loadSinusoid (function1, N, INDEX_MAX);
129 loadSinusoid (function2, N, INDEX_MAX + INDEX_SHIFT);
138 QVERIFY (binStartMax = INDEX_SHIFT);
141 void TestCorrelation::testShiftThreeTrianglesNonPowerOf2 ()
144 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
147 double function1 [N], function2 [N], correlations [N];
154 loadThreeTriangles (function1, N, INDEX_MAX);
155 loadThreeTriangles (function2, N, INDEX_MAX + INDEX_SHIFT);
164 QVERIFY (binStartMax = INDEX_SHIFT);
167 void TestCorrelation::testShiftThreeTrianglesPowerOf2 ()
170 const int INDEX_MAX = 200, INDEX_SHIFT = 50;
173 double function1 [N], function2 [N], correlations [N];
180 loadThreeTriangles (function1, N, INDEX_MAX);
181 loadThreeTriangles (function2, N, INDEX_MAX + INDEX_SHIFT);
190 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...