Interpolate calibration with magnitude/phase instead of real/imag

This commit is contained in:
Jan Käberich 2025-02-26 08:54:45 +01:00
parent 9660b4e58b
commit b6f26eb6dc
3 changed files with 27 additions and 6 deletions

View file

@ -237,3 +237,21 @@ bool Util::firmwareEqualOrHigher(QString firmware, QString compare)
return true;
}
}
std::complex<double> Util::interpolateMagPhase(const std::complex<double> &from, const std::complex<double> &to, double alpha)
{
auto magFrom = abs(from);
auto magTo = abs(to);
auto phaseFrom = arg(from);
auto phaseTo = arg(to);
// unwrap phase
if(phaseTo - phaseFrom > M_PI) {
phaseTo -= 2*M_PI;
} else if(phaseTo - phaseFrom < -M_PI) {
phaseTo += 2*M_PI;
}
auto magInterp = magFrom * (1.0 - alpha) + magTo * alpha;
auto phaseInterp = phaseFrom * (1.0 - alpha) + phaseTo * alpha;
return std::polar<double>(magInterp, phaseInterp);
}