mirror of
https://github.com/jankae/LibreVNA.git
synced 2025-12-06 07:12:10 +01:00
add unit tests for lin/log calibration detection
This commit is contained in:
parent
8e917faed4
commit
2f256117db
|
|
@ -14,6 +14,7 @@ class Calibration : public QObject, public Savable, public SCPINode
|
|||
Q_OBJECT
|
||||
|
||||
friend class LibreCALDialog;
|
||||
friend class CalibrationTests;
|
||||
public:
|
||||
Calibration();
|
||||
|
||||
|
|
@ -130,7 +131,7 @@ private:
|
|||
void createDefaultMeasurements(DefaultMeasurements dm);
|
||||
void deleteMeasurements();
|
||||
|
||||
bool hasFrequencyOverlap(std::vector<CalibrationMeasurement::Base*> m, double *startFreq = nullptr, double *stopFreq = nullptr, int *points = nullptr, bool *isLog = nullptr);
|
||||
static bool hasFrequencyOverlap(std::vector<CalibrationMeasurement::Base*> m, double *startFreq = nullptr, double *stopFreq = nullptr, int *points = nullptr, bool *isLog = nullptr);
|
||||
// returns all measurements that match the paramaters
|
||||
std::vector<CalibrationMeasurement::Base*> findMeasurements(CalibrationMeasurement::Base::Type type, int port1 = 0, int port2 = 0);
|
||||
// returns the first measurement in the list that matches the parameters
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ SOURCES += \
|
|||
../LibreVNA-GUI/streamingserver.cpp \
|
||||
../LibreVNA-GUI/touchstone.cpp \
|
||||
../LibreVNA-GUI/unit.cpp \
|
||||
calibrationtests.cpp \
|
||||
ffttests.cpp \
|
||||
impedancerenormalizationtests.cpp \
|
||||
main.cpp \
|
||||
|
|
@ -352,6 +353,7 @@ HEADERS += \
|
|||
../LibreVNA-GUI/streamingserver.h \
|
||||
../LibreVNA-GUI/touchstone.h \
|
||||
../LibreVNA-GUI/unit.h \
|
||||
calibrationtests.h \
|
||||
ffttests.h \
|
||||
impedancerenormalizationtests.h \
|
||||
parametertests.h \
|
||||
|
|
|
|||
136
Software/PC_Application/LibreVNA-Test/calibrationtests.cpp
Normal file
136
Software/PC_Application/LibreVNA-Test/calibrationtests.cpp
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
#include "calibrationtests.h"
|
||||
|
||||
#include "calibration.h"
|
||||
|
||||
CalibrationTests::CalibrationTests() {}
|
||||
|
||||
void CalibrationTests::LinearDetection()
|
||||
{
|
||||
// create some measurements
|
||||
std::vector<CalibrationMeasurement::Base*> m;
|
||||
double startFreq = 100000;
|
||||
double stopFreq = 6000000000;
|
||||
int points = 1001;
|
||||
Calibration cal;
|
||||
cal.getKit().setIdealDefault();
|
||||
auto open = new CalibrationMeasurement::Open(&cal);
|
||||
open->setPort(1);
|
||||
m.push_back(open);
|
||||
auto _short = new CalibrationMeasurement::Short(&cal);
|
||||
_short->setPort(1);
|
||||
m.push_back(_short);
|
||||
auto load = new CalibrationMeasurement::Load(&cal);
|
||||
load->setPort(1);
|
||||
m.push_back(load);
|
||||
|
||||
for(int i=0;i<points;i++) {
|
||||
double f = startFreq + (stopFreq - startFreq) * i / (points-1);
|
||||
DeviceDriver::VNAMeasurement meas;
|
||||
meas.frequency = f;
|
||||
meas.measurements["S11"] = 0.0;
|
||||
m[0]->addPoint(meas);
|
||||
m[1]->addPoint(meas);
|
||||
m[2]->addPoint(meas);
|
||||
}
|
||||
|
||||
// verify correct detection
|
||||
double detectedStart;
|
||||
double detectedStop;
|
||||
int detectedPoints;
|
||||
bool detectedLog;
|
||||
Calibration::hasFrequencyOverlap(m, &detectedStart, &detectedStop, &detectedPoints, &detectedLog);
|
||||
|
||||
QVERIFY(qFuzzyCompare(detectedStart, startFreq));
|
||||
QVERIFY(qFuzzyCompare(detectedStop, stopFreq));
|
||||
QVERIFY(detectedPoints == points);
|
||||
QVERIFY(detectedLog == false);
|
||||
}
|
||||
|
||||
void CalibrationTests::LogDetection()
|
||||
{
|
||||
// create some measurements
|
||||
std::vector<CalibrationMeasurement::Base*> m;
|
||||
double startFreq = 100000;
|
||||
double stopFreq = 6000000000;
|
||||
int points = 1001;
|
||||
Calibration cal;
|
||||
cal.getKit().setIdealDefault();
|
||||
auto open = new CalibrationMeasurement::Open(&cal);
|
||||
open->setPort(1);
|
||||
m.push_back(open);
|
||||
auto _short = new CalibrationMeasurement::Short(&cal);
|
||||
_short->setPort(1);
|
||||
m.push_back(_short);
|
||||
auto load = new CalibrationMeasurement::Load(&cal);
|
||||
load->setPort(1);
|
||||
m.push_back(load);
|
||||
|
||||
for(int i=0;i<points;i++) {
|
||||
double f = startFreq * pow(10.0, i * log10(stopFreq / startFreq) / (points - 1));
|
||||
DeviceDriver::VNAMeasurement meas;
|
||||
meas.frequency = f;
|
||||
meas.measurements["S11"] = 0.0;
|
||||
m[0]->addPoint(meas);
|
||||
m[1]->addPoint(meas);
|
||||
m[2]->addPoint(meas);
|
||||
}
|
||||
|
||||
// verify correct detection
|
||||
double detectedStart;
|
||||
double detectedStop;
|
||||
int detectedPoints;
|
||||
bool detectedLog;
|
||||
Calibration::hasFrequencyOverlap(m, &detectedStart, &detectedStop, &detectedPoints, &detectedLog);
|
||||
|
||||
QVERIFY(qFuzzyCompare(detectedStart, startFreq));
|
||||
QVERIFY(qFuzzyCompare(detectedStop, stopFreq));
|
||||
QVERIFY(detectedPoints == points);
|
||||
QVERIFY(detectedLog == true);
|
||||
}
|
||||
|
||||
void CalibrationTests::MixedDetection()
|
||||
{
|
||||
// create some measurements
|
||||
std::vector<CalibrationMeasurement::Base*> m;
|
||||
double startFreq = 100000;
|
||||
double stopFreq = 6000000000;
|
||||
int points = 1001;
|
||||
Calibration cal;
|
||||
cal.getKit().setIdealDefault();
|
||||
auto open = new CalibrationMeasurement::Open(&cal);
|
||||
open->setPort(1);
|
||||
m.push_back(open);
|
||||
auto _short = new CalibrationMeasurement::Short(&cal);
|
||||
_short->setPort(1);
|
||||
m.push_back(_short);
|
||||
auto load = new CalibrationMeasurement::Load(&cal);
|
||||
load->setPort(1);
|
||||
m.push_back(load);
|
||||
|
||||
for(int i=0;i<points;i++) {
|
||||
// one linear measurement, two log measurement
|
||||
double flin = startFreq + (stopFreq - startFreq) * i / (points-1);
|
||||
double flog = startFreq * pow(10.0, i * log10(stopFreq / startFreq) / (points - 1));
|
||||
DeviceDriver::VNAMeasurement measlin;
|
||||
measlin.frequency = flin;
|
||||
measlin.measurements["S11"] = 0.0;
|
||||
DeviceDriver::VNAMeasurement measlog;
|
||||
measlog.frequency = flog;
|
||||
measlog.measurements["S11"] = 0.0;
|
||||
m[0]->addPoint(measlin);
|
||||
m[1]->addPoint(measlog);
|
||||
m[2]->addPoint(measlog);
|
||||
}
|
||||
|
||||
// verify correct detection
|
||||
double detectedStart;
|
||||
double detectedStop;
|
||||
int detectedPoints;
|
||||
bool detectedLog;
|
||||
Calibration::hasFrequencyOverlap(m, &detectedStart, &detectedStop, &detectedPoints, &detectedLog);
|
||||
|
||||
QVERIFY(qFuzzyCompare(detectedStart, startFreq));
|
||||
QVERIFY(qFuzzyCompare(detectedStop, stopFreq));
|
||||
QVERIFY(detectedPoints == points);
|
||||
QVERIFY(detectedLog == true);
|
||||
}
|
||||
18
Software/PC_Application/LibreVNA-Test/calibrationtests.h
Normal file
18
Software/PC_Application/LibreVNA-Test/calibrationtests.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef CALIBRATIONTESTS_H
|
||||
#define CALIBRATIONTESTS_H
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
class CalibrationTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CalibrationTests();
|
||||
|
||||
private slots:
|
||||
void LinearDetection();
|
||||
void LogDetection();
|
||||
void MixedDetection();
|
||||
};
|
||||
|
||||
#endif // CALIBRATIONTESTS_H
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
#include "parametertests.h"
|
||||
#include "ffttests.h"
|
||||
#include "impedancerenormalizationtests.h"
|
||||
#include "calibrationtests.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ int main(int argc, char *argv[])
|
|||
status |= QTest::qExec(new ParameterTests, argc, argv);
|
||||
status |= QTest::qExec(new fftTests, argc, argv);
|
||||
status |= QTest::qExec(new ImpedanceRenormalizationTests, argc, argv);
|
||||
status |= QTest::qExec(new CalibrationTests, argc, argv);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue