STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
AllanVariance.hpp
Go to the documentation of this file.
1#ifndef ALLAN_VARIANCE_HPP
2#define ALLAN_VARIANCE_HPP
3
4#include <cmath>
5#include <vector>
6
7namespace fsw {
8namespace calibration {
9
10/**
11 * Noise coefficients from Allan variance fit (scripts/calibration/allan_variance.py).
12 * σ²_A(τ) = Q²/(2τ) + 2·ln(2)·B² + K²·τ/6 + R²·τ²/20
13 */
15 double Q = 1e-3;
16 double B = 1e-4;
17 double K = 1e-5;
18 double R = 1e-6;
19 double tau_min = 1.0;
20 double sigma_min = 1e-3;
21};
22
23/** Measurement σ from paper Section 7 (Python measurement_uncertainty). */
24inline double measurement_uncertainty(double tau, const NoiseCoefficients& coeffs,
25 double voltage = 0.0, double sigma_base = 1e-3) {
26 double var = sigma_base * sigma_base;
27 var += coeffs.Q * coeffs.Q / (2.0 * tau);
28 var += 2.0 * std::log(2.0) * coeffs.B * coeffs.B;
29 var += coeffs.K * coeffs.K * tau / 6.0;
30 var += 1e-4 * voltage * voltage;
31 return std::sqrt(std::max(var, 1e-12));
32}
33
34void compute_allan_variance(const std::vector<double>& timeseries, double tau0,
35 std::vector<double>& tau_out, std::vector<double>& sigma2_out);
36
37NoiseCoefficients fit_noise_coefficients(const std::vector<double>& tau_arr,
38 const std::vector<double>& sigma2_arr);
39
40} // namespace calibration
41} // namespace fsw
42
43#endif
Output smoothing for calibrated PT pressure, per sensor uid (ESP32 and LabJack T7 alike).
void compute_allan_variance(const std::vector< double > &timeseries, double tau0, std::vector< double > &tau_out, std::vector< double > &sigma2_out)
NoiseCoefficients fit_noise_coefficients(const std::vector< double > &tau_arr, const std::vector< double > &sigma2_arr)
double measurement_uncertainty(double tau, const NoiseCoefficients &coeffs, double voltage=0.0, double sigma_base=1e-3)
Measurement σ from paper Section 7 (Python measurement_uncertainty).
Motorized ball valve position: raw ADC counts -> % open.
Noise coefficients from Allan variance fit (scripts/calibration/allan_variance.py).