mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-07 23:43:42 +00:00
Improve graph divisions and markers
- Added group delay option to markers - Additional configuration for calculation of group delay in the preferences - Specify divisions as amount of divisions instead of spacing - Add option for auto divisions on graph with manual min/max limits
This commit is contained in:
parent
fe08937bb7
commit
b2d07d532d
24 changed files with 462 additions and 243 deletions
|
|
@ -1572,6 +1572,48 @@ double Trace::getNoise(double frequency)
|
|||
return dbm;
|
||||
}
|
||||
|
||||
double Trace::getGroupDelay(double frequency)
|
||||
{
|
||||
if(!isVNAParameter(liveParam) || lastMath->getDataType() != DataType::Frequency) {
|
||||
// data not suitable for group delay calculation
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
|
||||
// get index that matches frequency best
|
||||
unsigned int sample = index(frequency);
|
||||
|
||||
auto &p = Preferences::getInstance();
|
||||
const unsigned int requiredSamples = p.Acquisition.groupDelaySamples;
|
||||
if(size() < requiredSamples) {
|
||||
// unable to calculate
|
||||
return std::numeric_limits<double>::quiet_NaN();
|
||||
|
||||
}
|
||||
// needs at least some samples before/after current sample for calculating the derivative.
|
||||
// For samples too far at either end of the trace, return group delay of "inner" trace sample instead
|
||||
if(sample < requiredSamples / 2) {
|
||||
sample = requiredSamples / 2;
|
||||
} else if(sample >= size() - requiredSamples / 2) {
|
||||
sample = size() - requiredSamples / 2 - 1;
|
||||
}
|
||||
|
||||
// got enough samples at either end to calculate derivative.
|
||||
// acquire phases of the required samples
|
||||
std::vector<double> phases;
|
||||
phases.reserve(requiredSamples);
|
||||
for(unsigned int index = sample - requiredSamples / 2;index <= sample + requiredSamples / 2;index++) {
|
||||
phases.push_back(arg(this->sample(index).y));
|
||||
}
|
||||
// make sure there are no phase jumps
|
||||
Util::unwrapPhase(phases);
|
||||
// calculate linearRegression to get derivative
|
||||
double B_0, B_1;
|
||||
Util::linearRegression(phases, B_0, B_1);
|
||||
// B_1 now contains the derived phase vs. the sample. Scale by frequency to get group delay
|
||||
double freq_step = this->sample(sample).x - this->sample(sample - 1).x;
|
||||
return -B_1 / (2.0*M_PI * freq_step);
|
||||
}
|
||||
|
||||
int Trace::index(double x)
|
||||
{
|
||||
auto lower = lower_bound(lastMath->rData().begin(), lastMath->rData().end(), x, [](const Data &lhs, const double x) -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue