Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
MarkovProcess.hpp
Go to the documentation of this file.
1// First-Order Gauss-Markov Process
2// Exponentially correlated noise model
3#pragma once
4
5#include <cmath>
6#include <janus/janus.hpp>
7
8namespace vulcan::markov {
9
10// =============================================================================
11// Process State
12// =============================================================================
13
25template <typename Scalar> struct State {
26 Scalar x;
27};
28
35template <typename Scalar> State<Scalar> init_state() {
36 return State<Scalar>{.x = Scalar(0)};
37}
38
48template <typename Scalar>
49State<Scalar> init_state(const Scalar &initial_value) {
50 return State<Scalar>{.x = initial_value};
51}
52
53// =============================================================================
54// Discretized Process Parameters
55// =============================================================================
56
68struct Coeffs {
69 double phi;
70 double q;
71};
72
84inline Coeffs discretize(double tau, double sigma, double dt) {
85 double phi = std::exp(-dt / tau);
86 double q = sigma * std::sqrt(1.0 - phi * phi);
87 return Coeffs{.phi = phi, .q = q};
88}
89
90// =============================================================================
91// Continuous-Time Parameters
92// =============================================================================
93
105inline double process_noise_psd(double tau, double sigma) {
106 return 2.0 * sigma * sigma / tau;
107}
108
118inline double process_noise_intensity(double tau, double sigma) {
119 return std::sqrt(2.0 / tau) * sigma;
120}
121
122// =============================================================================
123// Simulation Step
124// =============================================================================
125
138template <typename Scalar>
139Scalar step(State<Scalar> &state, const Coeffs &coeffs,
140 const Scalar &noise_input) {
141 state.x = coeffs.phi * state.x + coeffs.q * noise_input;
142 return state.x;
143}
144
158template <typename Scalar>
159Scalar step(State<Scalar> &state, double tau, double sigma, double dt,
160 const Scalar &noise_input) {
161 Coeffs coeffs = discretize(tau, sigma, dt);
162 return step(state, coeffs, noise_input);
163}
164
165// =============================================================================
166// Analysis Utilities
167// =============================================================================
168
180inline double autocorrelation(double tau, double sigma, double tau_lag) {
181 return sigma * sigma * std::exp(-std::abs(tau_lag) / tau);
182}
183
197inline double psd_at_frequency(double tau, double sigma, double f) {
198 double omega_tau = 2.0 * M_PI * f * tau;
199 return sigma * sigma * 2.0 * tau / (1.0 + omega_tau * omega_tau);
200}
201
202} // namespace vulcan::markov
Definition MarkovProcess.hpp:8
double autocorrelation(double tau, double sigma, double tau_lag)
Compute autocorrelation at lag τ_lag.
Definition MarkovProcess.hpp:180
double psd_at_frequency(double tau, double sigma, double f)
Compute power spectral density at frequency f.
Definition MarkovProcess.hpp:197
Coeffs discretize(double tau, double sigma, double dt)
Discretize first-order Markov process.
Definition MarkovProcess.hpp:84
Scalar step(State< Scalar > &state, const Coeffs &coeffs, const Scalar &noise_input)
Step the first-order Markov process.
Definition MarkovProcess.hpp:139
double process_noise_psd(double tau, double sigma)
Compute continuous-time process noise PSD.
Definition MarkovProcess.hpp:105
State< Scalar > init_state()
Initialize state to zero.
Definition MarkovProcess.hpp:35
double process_noise_intensity(double tau, double sigma)
Compute continuous-time process noise intensity.
Definition MarkovProcess.hpp:118
Discretized first-order Markov process coefficients.
Definition MarkovProcess.hpp:68
double q
Process noise gain: σ·√(1-φ²).
Definition MarkovProcess.hpp:70
double phi
State transition: exp(-Δt/τ).
Definition MarkovProcess.hpp:69
First-order Gauss-Markov process state.
Definition MarkovProcess.hpp:25
Scalar x
Process state.
Definition MarkovProcess.hpp:26