mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-07 23:43:42 +00:00
WIP: make de-embedding and calibration work with arbitrary number of ports
This commit is contained in:
parent
8301448343
commit
9cf76c9681
30 changed files with 478 additions and 193 deletions
|
|
@ -55,6 +55,7 @@ void TraceWidgetVNA::importDialog()
|
|||
if (!filename.isEmpty()) {
|
||||
try {
|
||||
std::vector<Trace*> traces;
|
||||
int touchstonePorts = 0;
|
||||
QString prefix = QString();
|
||||
if(filename.endsWith(".csv")) {
|
||||
auto csv = CSV::fromFile(filename);
|
||||
|
|
@ -63,6 +64,7 @@ void TraceWidgetVNA::importDialog()
|
|||
// must be a touchstone file
|
||||
auto t = Touchstone::fromFile(filename.toStdString());
|
||||
traces = Trace::createFromTouchstone(t);
|
||||
touchstonePorts = t.ports();
|
||||
}
|
||||
// contruct prefix from filename
|
||||
prefix = filename;
|
||||
|
|
@ -78,44 +80,51 @@ void TraceWidgetVNA::importDialog()
|
|||
if(AppWindow::showGUI()) {
|
||||
i->show();
|
||||
}
|
||||
if(filename.endsWith(".s2p")) {
|
||||
// potential candidate to process via calibration/de-embedding
|
||||
connect(i, &TraceImportDialog::importFinsished, [=](const std::vector<Trace*> &traces) {
|
||||
if(traces.size() == 4) {
|
||||
// all traces imported, can calculate calibration/de-embedding
|
||||
bool calAvailable = cal.getNumPoints() > 0;
|
||||
bool deembedAvailable = deembed.getOptions().size() > 0;
|
||||
if(calAvailable || deembedAvailable) {
|
||||
// check if user wants to apply either one to the imported traces
|
||||
auto dialog = new QDialog();
|
||||
auto ui = new Ui::s2pImportOptions;
|
||||
ui->setupUi(dialog);
|
||||
connect(dialog, &QDialog::finished, [=](){
|
||||
delete ui;
|
||||
});
|
||||
ui->applyCal->setEnabled(calAvailable);
|
||||
ui->deembed->setEnabled(deembedAvailable);
|
||||
bool applyCal = false;
|
||||
bool applyDeembed = false;
|
||||
connect(ui->applyCal, &QCheckBox::toggled, [&](bool checked) {
|
||||
applyCal = checked;
|
||||
});
|
||||
connect(ui->deembed, &QCheckBox::toggled, [&](bool checked) {
|
||||
applyDeembed = checked;
|
||||
});
|
||||
if(AppWindow::showGUI()) {
|
||||
dialog->exec();
|
||||
}
|
||||
if(applyCal) {
|
||||
// cal.correctTraces(*traces[0], *traces[1], *traces[2], *traces[3]); // TODO
|
||||
}
|
||||
if(applyDeembed) {
|
||||
deembed.Deembed(*traces[0], *traces[1], *traces[2], *traces[3]);
|
||||
// potential candidate to process via calibration/de-embedding
|
||||
connect(i, &TraceImportDialog::importFinsished, [=](const std::vector<Trace*> &traces) {
|
||||
if(traces.size() == touchstonePorts*touchstonePorts) {
|
||||
// all traces imported, can calculate calibration/de-embedding
|
||||
bool calAvailable = cal.getNumPoints() > 0;
|
||||
bool deembedAvailable = deembed.getOptions().size() > 0;
|
||||
if(calAvailable || deembedAvailable) {
|
||||
// check if user wants to apply either one to the imported traces
|
||||
auto dialog = new QDialog();
|
||||
auto ui = new Ui::s2pImportOptions;
|
||||
ui->setupUi(dialog);
|
||||
connect(dialog, &QDialog::finished, [=](){
|
||||
delete ui;
|
||||
});
|
||||
ui->applyCal->setEnabled(calAvailable);
|
||||
ui->deembed->setEnabled(deembedAvailable);
|
||||
bool applyCal = false;
|
||||
bool applyDeembed = false;
|
||||
connect(ui->applyCal, &QCheckBox::toggled, [&](bool checked) {
|
||||
applyCal = checked;
|
||||
});
|
||||
connect(ui->deembed, &QCheckBox::toggled, [&](bool checked) {
|
||||
applyDeembed = checked;
|
||||
});
|
||||
if(AppWindow::showGUI()) {
|
||||
dialog->exec();
|
||||
}
|
||||
// assemble trace set
|
||||
std::map<QString, Trace*> set;
|
||||
for(int i=1;i<=touchstonePorts;i++) {
|
||||
for(int j=1;j<=touchstonePorts;j++) {
|
||||
QString name = "S"+QString::number(i)+QString::number(j);
|
||||
int index = (i-1)*touchstonePorts+(j-1);
|
||||
set[name] = traces[index];
|
||||
}
|
||||
}
|
||||
if(applyCal) {
|
||||
cal.correctTraces(set);
|
||||
}
|
||||
if(applyDeembed) {
|
||||
deembed.Deembed(set);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(const std::exception& e) {
|
||||
InformationBox::ShowError("Failed to import file", QString("Attempt to import file ended with error: \"") + e.what()+"\"");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue