Skip to content

Commit

Permalink
Fix impedance renormalization and honor new reference impedance for t…
Browse files Browse the repository at this point in the history
…races
  • Loading branch information
jankae committed Mar 1, 2024
1 parent 542b07f commit 3588729
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
14 changes: 12 additions & 2 deletions Software/PC_Application/LibreVNA-GUI/Traces/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void Trace::addData(const Trace::Data &d, const DeviceDriver::SASettings &s, int
addData(d, domain, 50.0, index);
}

void Trace::addDeembeddingData(const Trace::Data &d, int index)
void Trace::addDeembeddingData(const Trace::Data &d, double reference_impedance, int index)
{
bool wasAvailable = deembeddingAvailable();
if(index >= 0) {
Expand Down Expand Up @@ -179,6 +179,7 @@ void Trace::addDeembeddingData(const Trace::Data &d, int index)
deembeddingData.insert(lower, d);
}
}
deembedded_reference_impedance = reference_impedance;
if(deembeddingActive) {
emit outputSamplesChanged(index, index + 1);
}
Expand Down Expand Up @@ -687,7 +688,11 @@ void Trace::setModel(TraceModel *model)

double Trace::getReferenceImpedance() const
{
return reference_impedance;
if(deembeddingActive) {
return deembedded_reference_impedance;
} else {
return reference_impedance;
}
}

const std::vector<Trace::MathInfo>& Trace::getMathOperations() const
Expand Down Expand Up @@ -1316,6 +1321,10 @@ bool Trace::deembeddingAvailable()

void Trace::setDeembeddingActive(bool active)
{
if(active == deembeddingActive) {
// no change
return;
}
deembeddingActive = active;
if(deembeddingAvailable()) {
if(active) {
Expand All @@ -1330,6 +1339,7 @@ void Trace::setDeembeddingActive(bool active)
void Trace::clearDeembedding()
{
deembeddingData.clear();
setDeembeddingActive(false);
deembeddingChanged();
}

Expand Down
3 changes: 2 additions & 1 deletion Software/PC_Application/LibreVNA-GUI/Traces/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Trace : public TraceMath
void clear(bool force = false);
void addData(const Data& d, DataType domain, double reference_impedance = 50.0, int index = -1);
void addData(const Data& d, const DeviceDriver::SASettings &s, int index = -1);
void addDeembeddingData(const Data& d, int index = -1);
void addDeembeddingData(const Data& d, double reference_impedance = 50.0, int index = -1);
void setName(QString name);
void setVelocityFactor(double v);
void fillFromTouchstone(Touchstone &t, unsigned int parameter);
Expand Down Expand Up @@ -288,6 +288,7 @@ private slots:
// de-embedding variables
std::vector<Data> deembeddingData;
bool deembeddingActive;
double deembedded_reference_impedance;

std::vector<MathInfo> mathOps;
TraceMath *lastMath;
Expand Down
2 changes: 1 addition & 1 deletion Software/PC_Application/LibreVNA-GUI/Traces/tracemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void TraceModel::addVNAData(const DeviceDriver::VNAMeasurement& d, TraceMath::Da
if(!deembedded) {
t->addData(td, datatype, d.Z0, index);
} else {
t->addDeembeddingData(td, index);
t->addDeembeddingData(td, d.Z0, index);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void ImpedanceRenormalization::transformDatapoint(DeviceDriver::VNAMeasurement &
for(auto i=1;i<=ports;i++) {
auto S11name = "S"+QString::number(i)+QString::number(i);
auto S11 = p.measurements[S11name];
transformed[S11name] = Sparam(ABCDparam(Sparam(S11, 0.0, 0.0, 1.0), p.Z0), impedance).m11;
transformed[S11name] = Sparam(ABCDparam(Sparam(S11, 0.1, 0.1, 1.0), p.Z0), impedance).m11;
for(auto j=i+1;j<=ports;j++) {
auto S12name = "S"+QString::number(i)+QString::number(j);
auto S21name = "S"+QString::number(j)+QString::number(i);
Expand Down
8 changes: 4 additions & 4 deletions Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ VNA::VNA(AppWindow *window, QString name)

connect(calLoad, &QAction::triggered, [=](){
LoadCalibration();
if(window->getDevice() && !cal.validForDevice(window->getDevice()->getSerial())) {
InformationBox::ShowMessage("Invalid calibration", "The selected calibration was created for a different device. You can still load it but the resulting "
"data likely isn't useful.");
}
if(cal.getCaltype().type != Calibration::Type::None) {
if(InformationBox::AskQuestion("Adjust span?", "Do you want to adjust the span to match the loaded calibration file?", false)) {
SpanMatchCal();
Expand Down Expand Up @@ -510,6 +506,10 @@ VNA::VNA(AppWindow *window, QString name)
calApplyToTraces->setEnabled(true);
bMatchCal->setEnabled(true);
saveCal->setEnabled(true);
if(window->getDevice() && !cal.validForDevice(window->getDevice()->getSerial())) {
InformationBox::ShowMessage("Invalid calibration", "The selected calibration was created for a different device. You can still load it but the resulting "
"data likely isn't useful.");
}
});

tb_cal->addWidget(cbType);
Expand Down

0 comments on commit 3588729

Please sign in to comment.