mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-06 15:04:11 +00:00
group delay option for Y axis
This commit is contained in:
parent
75f4ee245f
commit
0d6dac4969
6 changed files with 99 additions and 36 deletions
26
Software/PC_Application/Util/util.cpp
Normal file
26
Software/PC_Application/Util/util.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#include "util.h"
|
||||
|
||||
void Util::unwrapPhase(std::vector<double> &phase)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void Util::linearRegression(const std::vector<double> &input, double &B_0, double &B_1)
|
||||
{
|
||||
double x_mean = (input.size() - 1.0) / 2.0;
|
||||
double y_mean = std::accumulate(input.begin(), input.end(), 0.0) / input.size();
|
||||
double ss_xy = 0.0;
|
||||
for(unsigned int i=0;i<input.size();i++) {
|
||||
ss_xy += input[i] * i;
|
||||
}
|
||||
ss_xy -= input.size() * x_mean * y_mean;
|
||||
int n = input.size() - 1;
|
||||
double ss_xx = (1.0/6.0) * n * (n + 1) * (2*n + 1) - input.size() * x_mean * x_mean;
|
||||
|
||||
B_1 = ss_xy / ss_xx;
|
||||
B_0 = y_mean - B_1 * x_mean;
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include <complex>
|
||||
#include <math.h>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
#include <QColor>
|
||||
|
||||
|
|
@ -55,6 +56,11 @@ namespace Util {
|
|||
auto brightness = q.redF() * 0.299 + q.greenF() * 0.587 + q.blueF() * 0.114;
|
||||
return brightness > 0.6 ? Qt::black : Qt::white;
|
||||
}
|
||||
|
||||
void unwrapPhase(std::vector<double> &phase);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
#endif // UTILH_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue