diff --git a/Software/PC_Application/Calibration/amplitudecaldialog.cpp b/Software/PC_Application/Calibration/amplitudecaldialog.cpp index b75e7df..3c4c3dc 100644 --- a/Software/PC_Application/Calibration/amplitudecaldialog.cpp +++ b/Software/PC_Application/Calibration/amplitudecaldialog.cpp @@ -424,13 +424,26 @@ void AmplitudeCalDialog::AutomaticMeasurementDialog() void AmplitudeCalDialog::ReceivedMeasurement(Protocol::SpectrumAnalyzerResult res) { - if(res.pointNum == 1) { - // store result in center of sweep of 3 points + MeasurementResult m = {.port1 = Util::SparamTodB(res.port1), .port2 = Util::SparamTodB(res.port2)}; + sweepMeasurements.push_back(m); + if(res.pointNum == automaticSweepPoints - 1) { + // sweep finished, find maximum for each port + double maxPort1 = std::numeric_limits::lowest(); + double maxPort2 = std::numeric_limits::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) { measured.pop_front(); } - MeasurementResult m = {.port1 = Util::SparamTodB(res.port1), .port2 = Util::SparamTodB(res.port2)}; - measured.push_back(m); + measured.push_back(max); + sweepMeasurements.clear(); } } @@ -473,10 +486,12 @@ void AmplitudeCalDialog::SetupNextAutomaticPoint(bool isSourceCal) p.type = Protocol::PacketType::SpectrumAnalyzerSettings; p.spectrumSettings.RBW = 10000; p.spectrumSettings.UseDFT = 0; - // setup 3 points centered around the measurement frequency (zero span not supported yet) - p.spectrumSettings.f_stop = point.frequency + 1.0; - p.spectrumSettings.f_start = point.frequency - 1.0; - p.spectrumSettings.pointNum = 3; + // setup points centered around the measurement frequency: + // use a span proportional to the center frequency (this makes sure to catch the peak of the excitation signal which + // 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.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.SignalID = 1; p.spectrumSettings.WindowType = 3; @@ -509,12 +524,14 @@ void AmplitudeCalDialog::SetupNextAutomaticPoint(bool isSourceCal) } automatic.settlingCount = averages + automaticSettling; dev->SendPacket(p); + sweepMeasurements.clear(); + sweepMeasurements.reserve(automaticSweepPoints); } void AmplitudeCalDialog::ReceivedAutomaticMeasurementResult(Protocol::SpectrumAnalyzerResult res) { - if(res.pointNum != 1) { - // ignore first and last point, only use the middle one + if(res.pointNum != automaticSweepPoints - 1) { + // ignore everything except end of sweep return; } if(automatic.settlingCount > 0) { diff --git a/Software/PC_Application/Calibration/amplitudecaldialog.h b/Software/PC_Application/Calibration/amplitudecaldialog.h index c9171ff..0abcbd8 100644 --- a/Software/PC_Application/Calibration/amplitudecaldialog.h +++ b/Software/PC_Application/Calibration/amplitudecaldialog.h @@ -83,8 +83,9 @@ signals: void newPointCreated(CorrectionPoint& p); protected: static constexpr double excitationAmplitude = -20.0; - static constexpr int averages = 20; - static constexpr int automaticSettling = 10; + static constexpr int automaticSweepPoints = 31; + static constexpr int averages = 3; + static constexpr int automaticSettling = 1; bool ConfirmActionIfEdited(); void UpdateSaveButton(); @@ -121,6 +122,7 @@ protected: struct MeasurementResult { double port1, port2; }; + std::vector sweepMeasurements; std::deque measured; MeasurementResult averageMeasurement(); };