-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathACT.cpp
More file actions
62 lines (48 loc) · 1.24 KB
/
ACT.cpp
File metadata and controls
62 lines (48 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "ACT.h"
autoTest::autoTest(Generator * _generator, int _sampleCount, int _lag): Test(_generator, _sampleCount), lag(_lag), autoCorrel(0.0)
{
if (lag > sampleCount)
lag = 1;
}
autoTest::~autoTest()
{
}
double autoTest::countMean()
{
double mean = 0.0;
for (int i = 0; i < sampleCount; i++)
mean += samples[i];
mean /= sampleCount;
return mean;
}
double autoTest::countAutocorr()
{
double mean = countMean();
double sum1 = 0.0, sum2 = 0.0;
for (int i = lag; i < sampleCount; i++)
{
sum1 += ((samples[i] - mean) * samples[i - lag]);
sum2 += pow((samples[i] - mean), 2);
}
autoCorrel = sum1 / sum2;
return autoCorrel;
}
void autoTest::displayResult(ostream & output)
{
output << "Autocorrelation test!" << endl << "Sample: " << endl;
for (int i = 0; i < sampleCount; i++)
{
output << samples[i] << "\t";
if ((i % 10 == 0) && (i > 0))
{
output << endl;
}
}
output << endl << "Autocorrelation:\t" << autoCorrel << endl << "Lag:\t" << lag << endl << endl;
}
void autoTest::runTest(ostream & output)
{
drawSamples();
countAutocorr();
displayResult(output);
}