This repository was archived by the owner on Feb 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibrator.cpp
101 lines (79 loc) · 2.28 KB
/
calibrator.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "calibrator.h"
#include <QDir>
#include <QTextStream>
#include <QtGlobal>
#include <QDebug>
Calibrator::Calibrator(QObject *parent) : QObject(parent),
stepHigh(NAN),
stepLow(NAN),
ampMax(NAN),
bandBorder(NAN)
{
}
void Calibrator:: load(QString fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
emit error("Не найден файл грубой калибровки");
QTextStream in(&file);
double f1;
double f2;
double P_dBm;
double amp_V;
double ampMax = -qInf();
in >> f1;
in >> P_dBm;
amp_V = pow(10, ((P_dBm + 30 + 16.99)/ 20) - 3) * sqrt(2);
ampCorrection.push_back(amp_V);
if (amp_V > ampMax)
ampMax = amp_V;
in >> f2;
in >> P_dBm;
amp_V = pow(10, ((P_dBm + 30 + 16.99)/ 20) - 3) * sqrt(2);
ampCorrection.push_back(amp_V);
if (amp_V > ampMax)
ampMax = amp_V;
stepLow = (f2 - f1) * 1e6;
f1 = f2;
double *stepPtr = &stepLow;
while (!in.atEnd())
{
double step;
in >> f2;
in >> P_dBm;
bool eof = ( f2 == 0) && (P_dBm == 0);
if (eof)
break;
amp_V = pow(10, ((P_dBm + 30 + 16.99)/ 20) - 3) * sqrt(2);
ampCorrection.push_back(amp_V);
if (amp_V > ampMax)
ampMax = amp_V;
step = (f2 - f1) * 1e6;
if ( std::fabs((step - *stepPtr)) > 60e3) {
bool err = (f2 * 1e6 < bandBorder ) || (f1 * 1e6 > bandBorder);
if (err)
emit error("Ошибка при загрузки калибровочной характиристики. Не правильная структура файла");
stepHigh = step;
stepPtr = &stepHigh;
}
f1= f2;
}
qDebug() << "Frequency step in low band is: " + QString::number(stepLow);
qDebug() << "Frequency step in high band is: " + QString::number(stepHigh);
}
void Calibrator::setBandBorder(double fHz)
{
bandBorder = fHz;
}
double Calibrator::getAmp(double f)
{
if (std::isnan(f))
return ampCorrection[1];
int ind;
if ( f < bandBorder) {
ind = round(f / stepLow) + 1 ;
} else {
ind = round(bandBorder / stepLow) + round((f - bandBorder) / stepHigh) + 1;
}
return ampCorrection[ind];
}