Improve automatic source/receiver calibration, mitigate effect of limited fractional PLL divider

This commit is contained in:
Jan Käberich 2022-06-06 21:51:55 +02:00
parent 228515fd29
commit 18e03d02a4
2 changed files with 31 additions and 12 deletions

View File

@ -424,13 +424,26 @@ void AmplitudeCalDialog::AutomaticMeasurementDialog()
void AmplitudeCalDialog::ReceivedMeasurement(Protocol::SpectrumAnalyzerResult res) void AmplitudeCalDialog::ReceivedMeasurement(Protocol::SpectrumAnalyzerResult res)
{ {
if(res.pointNum == 1) { MeasurementResult m = {.port1 = Util::SparamTodB(res.port1), .port2 = Util::SparamTodB(res.port2)};
// store result in center of sweep of 3 points sweepMeasurements.push_back(m);
if(res.pointNum == automaticSweepPoints - 1) {
// sweep finished, find maximum for each port
double maxPort1 = std::numeric_limits<double>::lowest();
double maxPort2 = std::numeric_limits<double>::lowest();
for(auto s : sweepMeasurements) {
if(s.port1 > maxPort1) {
maxPort1 = s.port1;
}
if(s.port2 > maxPort2) {
maxPort2 = s.port2;
}
}
MeasurementResult max = {.port1 = maxPort1, .port2 = maxPort2};
if(measured.size() >= averages) { if(measured.size() >= averages) {
measured.pop_front(); measured.pop_front();
} }
MeasurementResult m = {.port1 = Util::SparamTodB(res.port1), .port2 = Util::SparamTodB(res.port2)}; measured.push_back(max);
measured.push_back(m); sweepMeasurements.clear();
} }
} }
@ -473,10 +486,12 @@ void AmplitudeCalDialog::SetupNextAutomaticPoint(bool isSourceCal)
p.type = Protocol::PacketType::SpectrumAnalyzerSettings; p.type = Protocol::PacketType::SpectrumAnalyzerSettings;
p.spectrumSettings.RBW = 10000; p.spectrumSettings.RBW = 10000;
p.spectrumSettings.UseDFT = 0; p.spectrumSettings.UseDFT = 0;
// setup 3 points centered around the measurement frequency (zero span not supported yet) // setup points centered around the measurement frequency:
p.spectrumSettings.f_stop = point.frequency + 1.0; // use a span proportional to the center frequency (this makes sure to catch the peak of the excitation signal which
p.spectrumSettings.f_start = point.frequency - 1.0; // might be slightly off due to PLL divider limtis). Also make sure to use at least a span of 2 Hz (zero span not supported yet)
p.spectrumSettings.pointNum = 3; p.spectrumSettings.f_stop = point.frequency * 1.00001 + 1.0;
p.spectrumSettings.f_start = point.frequency / 1.00001 - 1.0;
p.spectrumSettings.pointNum = automaticSweepPoints;
p.spectrumSettings.Detector = 0; p.spectrumSettings.Detector = 0;
p.spectrumSettings.SignalID = 1; p.spectrumSettings.SignalID = 1;
p.spectrumSettings.WindowType = 3; p.spectrumSettings.WindowType = 3;
@ -509,12 +524,14 @@ void AmplitudeCalDialog::SetupNextAutomaticPoint(bool isSourceCal)
} }
automatic.settlingCount = averages + automaticSettling; automatic.settlingCount = averages + automaticSettling;
dev->SendPacket(p); dev->SendPacket(p);
sweepMeasurements.clear();
sweepMeasurements.reserve(automaticSweepPoints);
} }
void AmplitudeCalDialog::ReceivedAutomaticMeasurementResult(Protocol::SpectrumAnalyzerResult res) void AmplitudeCalDialog::ReceivedAutomaticMeasurementResult(Protocol::SpectrumAnalyzerResult res)
{ {
if(res.pointNum != 1) { if(res.pointNum != automaticSweepPoints - 1) {
// ignore first and last point, only use the middle one // ignore everything except end of sweep
return; return;
} }
if(automatic.settlingCount > 0) { if(automatic.settlingCount > 0) {

View File

@ -83,8 +83,9 @@ signals:
void newPointCreated(CorrectionPoint& p); void newPointCreated(CorrectionPoint& p);
protected: protected:
static constexpr double excitationAmplitude = -20.0; static constexpr double excitationAmplitude = -20.0;
static constexpr int averages = 20; static constexpr int automaticSweepPoints = 31;
static constexpr int automaticSettling = 10; static constexpr int averages = 3;
static constexpr int automaticSettling = 1;
bool ConfirmActionIfEdited(); bool ConfirmActionIfEdited();
void UpdateSaveButton(); void UpdateSaveButton();
@ -121,6 +122,7 @@ protected:
struct MeasurementResult { struct MeasurementResult {
double port1, port2; double port1, port2;
}; };
std::vector<MeasurementResult> sweepMeasurements;
std::deque<MeasurementResult> measured; std::deque<MeasurementResult> measured;
MeasurementResult averageMeasurement(); MeasurementResult averageMeasurement();
}; };