Normalization for tracking generator

This commit is contained in:
Jan Käberich 2020-11-21 13:27:23 +01:00
parent 7b41f10604
commit 6758420eae
3 changed files with 145 additions and 5 deletions

View file

@ -9,7 +9,6 @@
SIUnitEdit::SIUnitEdit(QString unit, QString prefixes, int precision, QWidget *parent)
: QLineEdit(parent)
{
_value = 0;
this->unit = unit;
this->prefixes = prefixes;
this->precision = precision;
@ -19,6 +18,7 @@ SIUnitEdit::SIUnitEdit(QString unit, QString prefixes, int precision, QWidget *p
connect(this, &QLineEdit::editingFinished, [this]() {
parseNewValue(1.0);
});
setValueQuiet(0);
}
SIUnitEdit::SIUnitEdit(QWidget *parent)

View file

@ -48,6 +48,10 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
{
averages = 1;
settings = {};
normalize.active = false;
normalize.measuring = false;
normalize.points = 0;
normalize.dialog.reset();
// Create default traces
auto tPort1 = new Trace("Port1", Qt::yellow);
@ -180,10 +184,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
// Tracking generator toolbar
auto tb_trackgen = new QToolBar("Tracking Generator");
auto cbTrackGenEnable = new QCheckBox("Tracking Generator");
connect(cbTrackGenEnable, &QCheckBox::toggled, [=](bool enabled) {
settings.trackingGenerator = enabled;
SettingsChanged();
});
connect(cbTrackGenEnable, &QCheckBox::toggled, this, &SpectrumAnalyzer::SetTGEnabled);
tb_trackgen->addWidget(cbTrackGenEnable);
auto cbTrackGenPort = new QComboBox();
@ -218,6 +219,20 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
tb_trackgen->addWidget(new QLabel("Offset:"));
tb_trackgen->addWidget(tgOffset);
normalize.enable = new QCheckBox("Normalize");
tb_trackgen->addWidget(normalize.enable);
connect(normalize.enable, &QCheckBox::toggled, this, &SpectrumAnalyzer::EnableNormalization);
normalize.Level = new SIUnitEdit("dBm", " ", 3);
normalize.Level->setFixedWidth(100);
normalize.Level->setValue(0);
normalize.Level->setToolTip("Level to normalize to");
tb_trackgen->addWidget(new QLabel("To:"));
tb_trackgen->addWidget(normalize.Level);
normalize.measure = new QPushButton("Measure");
normalize.measure->setToolTip("Perform normalization measurement");
connect(normalize.measure, &QPushButton::clicked, this, &SpectrumAnalyzer::MeasureNormalization);
tb_trackgen->addWidget(normalize.measure);
window->addToolBar(tb_trackgen);
toolbars.insert(tb_trackgen);
@ -240,6 +255,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
// Set initial TG settings
SetTGLevel(-20.0);
SetTGOffset(0);
SetTGEnabled(false);
// Set initial sweep settings
auto pref = Preferences::getInstance();
@ -279,6 +295,37 @@ using namespace std;
void SpectrumAnalyzer::NewDatapoint(Protocol::SpectrumAnalyzerResult d)
{
d = average.process(d);
if(normalize.measuring) {
if(average.currentSweep() == averages) {
// this is the last averaging sweep, use values for normalization
if(normalize.port1Correction.size() > 0 || d.pointNum == 0) {
// add measurement
normalize.port1Correction.push_back(d.port1);
normalize.port2Correction.push_back(d.port2);
if(d.pointNum == settings.pointNum - 1) {
// this was the last point
normalize.measuring = false;
normalize.f_start = settings.f_start;
normalize.f_stop = settings.f_stop;
normalize.points = settings.pointNum;
EnableNormalization(true);
qDebug() << "Normalization measuremen complete";
}
}
}
int percentage = (((average.currentSweep() - 1) * 100) + (d.pointNum + 1) * 100 / settings.pointNum) / averages;
normalize.dialog.setValue(percentage);
}
if(normalize.active) {
d.port1 /= normalize.port1Correction[d.pointNum];
d.port2 /= normalize.port2Correction[d.pointNum];
double corr = pow(10.0, normalize.Level->value() / 20.0);
d.port1 *= corr;
d.port2 *= corr;
}
traceModel.addSAData(d, settings);
emit dataChanged();
if(d.pointNum == settings.pointNum - 1) {
@ -331,6 +378,15 @@ void SpectrumAnalyzer::SettingsChanged()
}
}
if(normalize.active) {
// check if normalization is still valid
if(normalize.f_start != settings.f_start || normalize.f_stop != settings.f_stop || normalize.points != settings.pointNum) {
// normalization was taken at different settings, disable
EnableNormalization(false);
InformationBox::ShowMessage("Information", "Normalization was disabled because the span has been changed");
}
}
if(window->getDevice()) {
window->getDevice()->Configure(settings);
}
@ -449,6 +505,21 @@ void SpectrumAnalyzer::SetAveraging(unsigned int averages)
SettingsChanged();
}
void SpectrumAnalyzer::SetTGEnabled(bool enabled)
{
if(enabled != settings.trackingGenerator) {
settings.trackingGenerator = enabled;
SettingsChanged();
}
normalize.Level->setEnabled(enabled);
normalize.enable->setEnabled(enabled);
normalize.measure->setEnabled(enabled);
if(!enabled && normalize.active) {
// disable normalization when TG is turned off
EnableNormalization(false);
}
}
void SpectrumAnalyzer::SetTGLevel(double level)
{
if(level > Device::Info().limits_cdbm_max / 100.0) {
@ -473,6 +544,54 @@ void SpectrumAnalyzer::SetTGOffset(double offset)
}
}
void SpectrumAnalyzer::MeasureNormalization()
{
normalize.active = false;
normalize.port1Correction.clear();
normalize.port2Correction.clear();
normalize.measuring = true;
normalize.dialog.setLabelText("Taking normalization measurement...");
normalize.dialog.setCancelButtonText("Abort");
normalize.dialog.setWindowTitle("Normalization");
normalize.dialog.setValue(0);
normalize.dialog.setWindowModality(Qt::ApplicationModal);
// always show the dialog
normalize.dialog.setMinimumDuration(0);
connect(&normalize.dialog, &QProgressDialog::canceled, this, &SpectrumAnalyzer::AbortNormalization);
// trigger beginning of next sweep
SettingsChanged();
}
void SpectrumAnalyzer::AbortNormalization()
{
EnableNormalization(false);
normalize.measuring = false;
normalize.points = 0;
normalize.dialog.reset();
}
void SpectrumAnalyzer::EnableNormalization(bool enabled)
{
if(enabled != normalize.active) {
if(enabled) {
// check if measurements already taken
if(normalize.f_start == settings.f_start && normalize.f_stop == settings.f_stop && normalize.points == settings.pointNum) {
// same settings as with normalization measurement, can enable
normalize.active = true;
} else {
// needs to take measurement first
MeasureNormalization();
}
} else {
// disabled
normalize.active = false;
}
}
normalize.enable->blockSignals(true);
normalize.enable->setChecked(normalize.active);
normalize.enable->blockSignals(false);
}
void SpectrumAnalyzer::UpdateAverageCount()
{
lAverages->setText(QString::number(average.getLevel()) + "/");

View file

@ -32,8 +32,12 @@ private slots:
void SetRBW(double bandwidth);
void SetAveraging(unsigned int averages);
// TG control
void SetTGEnabled(bool enabled);
void SetTGLevel(double level);
void SetTGOffset(double offset);
void MeasureNormalization();
void AbortNormalization();
void EnableNormalization(bool enabled);
private:
void UpdateAverageCount();
@ -53,6 +57,23 @@ private:
QComboBox *cbWindowType, *cbDetector;
QLabel *lAverages;
struct {
bool active;
bool measuring;
// settings when normalize was measured
double f_start, f_stop, points;
// correction values to get the ports to 0dBm
std::vector<double> port1Correction;
std::vector<double> port2Correction;
// level to normalize to (additional correction factor)
SIUnitEdit *Level;
// GUI elements
QProgressDialog dialog;
QPushButton *measure;
QCheckBox *enable;
} normalize;
signals:
void dataChanged();
void startFreqChanged(double freq);