From 05ca7e64349995f0e02a4e14e013ac944e7e688d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Tue, 23 Feb 2021 21:02:04 +0100 Subject: [PATCH] Bugfix?: changed sign detection of root calculation --- Software/PC_Application/VNA/Deembedding/twothru.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Software/PC_Application/VNA/Deembedding/twothru.cpp b/Software/PC_Application/VNA/Deembedding/twothru.cpp index 3160b9c..caef40a 100644 --- a/Software/PC_Application/VNA/Deembedding/twothru.cpp +++ b/Software/PC_Application/VNA/Deembedding/twothru.cpp @@ -306,9 +306,15 @@ std::vector TwoThru::calculateErrorBoxes(std::vector 0) { - if(arg(test) - arg(last_test) > 0) { + // according to the octave script, the next line should be if(arg(test) - arg(last_test) > 0) + // but that leads to 180° degree phase shift and also doesn't make much sense: + // we want to figure out the correct sign for the root so that no phase jumps occur. The + // phase difference from one to the next point is allowed to be positive, it just should be smaller + // than PI/2 (otherwise we got the wrong sign for the root) + if(abs(arg(test) - arg(last_test)) > M_PI / 2) { k = -k; } + qDebug() << "angle at point" << i << "(" << arg(test) - arg(last_test) << ")"; } last_test = test; p211x.push_back(k*test); @@ -362,7 +368,7 @@ std::vector TwoThru::calculateErrorBoxes(std::vector 0) { - if(arg(test) - arg(last_test) > 0) { + if(abs(arg(test) - arg(last_test)) > M_PI / 2) { k = -k; } } @@ -555,7 +561,7 @@ std::vector TwoThru::calculateErrorBoxes(std::vector 0) { - if(arg(test) - arg(last_test) > 0) { + if(abs(arg(test) - arg(last_test)) > M_PI / 2) { k = -k; } }