Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
RandomWalk.hpp
Go to the documentation of this file.
1// Random Walk Noise Model
2// Integrated white noise (rate random walk / drift)
3#pragma once
4
5#include <cmath>
6#include <janus/janus.hpp>
7
9
10// =============================================================================
11// Random Walk State
12// =============================================================================
13
22template <typename Scalar> struct State {
23 Scalar value;
24};
25
32template <typename Scalar> State<Scalar> init_state() {
33 return State<Scalar>{.value = Scalar(0)};
34}
35
36// =============================================================================
37// Discretized Coefficients
38// =============================================================================
39
49struct Coeffs {
50 double gain;
51};
52
60inline Coeffs compute_coeffs(double K, double dt) {
61 return Coeffs{.gain = K * std::sqrt(dt)};
62}
63
64// =============================================================================
65// Simulation Step
66// =============================================================================
67
79template <typename Scalar>
80Scalar step(State<Scalar> &state, const Coeffs &coeffs,
81 const Scalar &noise_input) {
82 state.value = state.value + coeffs.gain * noise_input;
83 return state.value;
84}
85
99template <typename Scalar>
100Scalar step(State<Scalar> &state, double K, double dt,
101 const Scalar &noise_input) {
102 Coeffs coeffs = compute_coeffs(K, dt);
103 return step(state, coeffs, noise_input);
104}
105
106// =============================================================================
107// Analysis Utilities
108// =============================================================================
109
120inline double expected_variance(double K, double t) { return K * K * t; }
121
129inline double expected_stddev(double K, double t) { return K * std::sqrt(t); }
130
131} // namespace vulcan::random_walk
Definition RandomWalk.hpp:8
double expected_variance(double K, double t)
Compute expected variance at given time.
Definition RandomWalk.hpp:120
Scalar step(State< Scalar > &state, const Coeffs &coeffs, const Scalar &noise_input)
Step the random walk process.
Definition RandomWalk.hpp:80
State< Scalar > init_state()
Initialize random walk state to zero.
Definition RandomWalk.hpp:32
double expected_stddev(double K, double t)
Compute expected standard deviation at given time.
Definition RandomWalk.hpp:129
Coeffs compute_coeffs(double K, double dt)
Compute random walk coefficients.
Definition RandomWalk.hpp:60
Pre-computed random walk coefficients.
Definition RandomWalk.hpp:49
double gain
Noise input gain: K * √(Δt).
Definition RandomWalk.hpp:50
Random walk process state.
Definition RandomWalk.hpp:22
Scalar value
Accumulated random walk value.
Definition RandomWalk.hpp:23