-
Notifications
You must be signed in to change notification settings - Fork 0
/
libEDM_histogram.cpp
87 lines (70 loc) · 1.71 KB
/
libEDM_histogram.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "libEDM_histogram.h"
using std::ios_base;
using std::setiosflags;
//
// class LogHistogram
//
string LogHistogram::dBType() const
{
switch (_logType)
{
case B:
return string("Bells");
case dB:
return string("dB");
case dBm:
return string("dBm");
case dBW:
return string("dBW");
default:
error("LogHistogram::dBType logType not supported");
}
}
void LogHistogram::print_footer(ostream &file) const
{
file << setiosflags(ios_base::scientific);
file << "Mean Value (dB)";
for (size_t i = 0; i < 4; i++)
file << ", " << linear2dB(mean());
file << endl;
file << "Std. Dev. (dB)";
for (size_t i = 0; i < 4; i++)
file << ", " << linear2dB(stdDev());
file << endl << endl;
file << "Logarithmic Mean Value (" << dBType() << ")";
for (size_t i = 0; i < 4; i++)
file << ", " << dBMean();
file << endl;
file << "Logarithmic Std. Dev. (" << dBType() << ")";
for (size_t i = 0; i < 4; i++)
file << ", " << dBStdDev();
file << endl << endl;
file.flush();
}
void LogHistogram::reset()
{
Histogram<double>::reset();
_dBSum = 0.0;
_dBSumOfSquares = 0.0;
}
void LogHistogram::update (const double sample)
{
Histogram<double>::update(sample);
double logSample;
switch (_logType)
{
case B:
logSample = log10(sample);
break;
case dB:
case dBW:
logSample = linear2dB(sample);
break;
case dBm:
logSample = watts2dBm(sample);
break;
}
_dBSum += logSample;
_dBSumOfSquares += sqr(logSample);
update_histogram(logSample);
}