Additional YAxisType: Unwrapped phase

This commit is contained in:
Jan Käberich 2022-01-09 15:41:40 +01:00
parent 4ba02a810f
commit 4d959598b5
7 changed files with 48 additions and 6 deletions

View file

@ -2,12 +2,17 @@
#include <QVector2D>
void Util::unwrapPhase(std::vector<double> &phase)
void Util::unwrapPhase(std::vector<double> &phase, unsigned int start_index)
{
for (unsigned int i = 1; i < phase.size(); i++) {
double d = phase[i] - phase[i-1];
d = d > M_PI ? d - 2 * M_PI : (d < -M_PI ? d + 2 * M_PI : d);
phase[i] = phase[i-1] + d;
for (unsigned int i = start_index + 1; i < phase.size(); i++) {
int d = trunc(phase[i] - phase[i-1]) / M_PI;
if(d > 0) {
// there is larger than a 180° shift between this and the previous phase
phase[i] -= 2*M_PI*(int)((d+1)/2);
} else if(d < 0) {
// there is larger than a -180° shift between this and the previous phase
phase[i] -= 2*M_PI*(int)((d-1)/2);
}
}
}

View file

@ -66,7 +66,7 @@ namespace Util {
return brightness > 0.6 ? Qt::black : Qt::white;
}
void unwrapPhase(std::vector<double> &phase);
void unwrapPhase(std::vector<double> &phase, unsigned int start_index = 0);
// input values are Y coordinates, assumes evenly spaced linear X values from 0 to input.size() - 1
void linearRegression(const std::vector<double> &input, double &B_0, double &B_1);