MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / appendDecimated

Method appendDecimated

app/src/DSP.h:433–501  ·  view source on GitHub ↗

* @brief Appends one (time, value), decimating to a min/max envelope pair per cell on an * absolute time grid, replacing the drifting peak-pick that aliased high-rate * bipolar signals into shimmer. The open cell's slots update in place so the * newest sample is visible immediately at any input rate. */

Source from the content-addressed store, hash-verified

431 * newest sample is visible immediately at any input rate.
432 */
433 void appendDecimated(double t, double v)
434 {
435 Q_ASSERT(interval > 0.0);
436 Q_ASSERT(time.capacity() == value.capacity());
437
438 if (time.raw() == nullptr || value.raw() == nullptr) [[unlikely]]
439 return;
440
441 if (!std::isfinite(t) || !std::isfinite(v)) [[unlikely]]
442 return;
443
444 if (time.size() > 0 && t < time[time.size() - 1]) [[unlikely]]
445 t = time[time.size() - 1];
446
447 if (cellSlots > static_cast<int>(time.size())) [[unlikely]]
448 cellSlots = static_cast<int>(time.size());
449
450 if (time.size() == 0 || t >= nextEmit) {
451 nextEmit = (std::floor(t / interval) + 1.0) * interval;
452 accMin = v;
453 accMax = v;
454 accMinTime = t;
455 accMaxTime = t;
456 cellSlots = 1;
457 time.push(t);
458 value.push(v);
459 return;
460 }
461
462 bool changed = false;
463 if (v < accMin) {
464 accMin = v;
465 accMinTime = t;
466 changed = true;
467 }
468
469 if (v > accMax) {
470 accMax = v;
471 accMaxTime = t;
472 changed = true;
473 }
474
475 if (!changed)
476 return;
477
478 const bool minFirst = accMinTime <= accMaxTime;
479 const double t0 = minFirst ? accMinTime : accMaxTime;
480 const double v0 = minFirst ? accMin : accMax;
481 const double t1 = minFirst ? accMaxTime : accMinTime;
482 const double v1 = minFirst ? accMax : accMin;
483
484 if (cellSlots == 1 && (t1 > t0 || v1 != v0) && time.capacity() > 1) {
485 time.push(t1);
486 value.push(v1);
487 cellSlots = 2;
488 }
489
490 const std::size_t n = time.size();

Callers 3

updateDataSeriesMethod · 0.80
updateLineSeriesMethod · 0.80
replayTimeRingFunction · 0.80

Calls 6

isfiniteFunction · 0.85
floorFunction · 0.85
rawMethod · 0.80
pushMethod · 0.80
capacityMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected