-
Notifications
You must be signed in to change notification settings - Fork 0
/
measurements.cpp
62 lines (45 loc) · 1.25 KB
/
measurements.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
#include "measurements.h"
#include "yin.h"
#include <QDebug>
#include <QElapsedTimer>
#include <algorithm>
Measurements::Measurements(QObject *parent) : QObject(parent)
{
}
void Measurements::setWaveform(const WaveformPointsVector& m_points)
{
this->points = m_points;
yValues.resize(points.length());
for(int i = 0; i < points.length(); i++)
{
yValues[i] = points[i].y();
}
}
MeasurementResult Measurements::Frequency(int sampleRate)
{
MeasurementResult result;
Yin yin(sampleRate, points.length());
result.value = yin.getPitch(points);
return result;
}
MeasurementResult Measurements::Vmin()
{
MeasurementResult result;
int minValueIndex = std::distance(yValues.constBegin(), std::min_element(yValues.constBegin(), yValues.constEnd()));
result.value = yValues[minValueIndex];
return result;
}
MeasurementResult Measurements::Vmax()
{
MeasurementResult result;
int minValueIndex = std::distance(yValues.constBegin(), std::max_element(yValues.constBegin(), yValues.constEnd()));
result.value = yValues[minValueIndex];
return result;
}
MeasurementResult Measurements::Vavg()
{
MeasurementResult result;
double average = std::accumulate(yValues.constBegin(), yValues.constEnd(), 0.0) / yValues.size();
result.value = average;
return result;
}