Skip to main content

DsfbParams

Struct DsfbParams 

Source
pub struct DsfbParams {
    pub k_phi: f64,
    pub k_omega: f64,
    pub k_alpha: f64,
    pub rho: f64,
    pub sigma0: f64,
}
Expand description

Parameters for the DSFB observer

Fields§

§k_phi: f64

Gain for phi correction

§k_omega: f64

Gain for omega correction

§k_alpha: f64

Gain for alpha correction

§rho: f64

EMA smoothing factor (0 < rho < 1)

§sigma0: f64

Trust softness parameter

Implementations§

Source§

impl DsfbParams

Source

pub fn new( k_phi: f64, k_omega: f64, k_alpha: f64, rho: f64, sigma0: f64, ) -> Self

Create new DSFB parameters

Examples found in repository?
examples/drift_impulse.rs (lines 76-82)
55fn main() -> std::io::Result<()> {
56    println!("Running DSFB Drift-Impulse Simulation...\n");
57
58    let base_outdir =
59        std::env::var("DSFB_OUTPUT_BASE").unwrap_or_else(|_| "output-dsfb".to_string());
60    let run_outdir = create_run_output_dir(&base_outdir)?;
61
62    // Configure simulation
63    let config = SimConfig {
64        dt: 0.01,
65        steps: 1000,
66        sigma_noise: 0.05,
67        sigma_alpha: 0.01,
68        drift_beta: 0.1,
69        impulse_start: 300,
70        impulse_duration: 100,
71        impulse_amplitude: 1.0,
72        seed: 42,
73    };
74
75    // Configure DSFB parameters
76    let dsfb_params = DsfbParams::new(
77        0.5,  // k_phi
78        0.1,  // k_omega
79        0.01, // k_alpha
80        0.95, // rho
81        0.1,  // sigma0
82    );
83
84    // Run simulation
85    println!("Configuration:");
86    println!("  Time step: {}", config.dt);
87    println!("  Total steps: {}", config.steps);
88    println!("  Noise sigma: {}", config.sigma_noise);
89    println!(
90        "  Impulse start: {} (t={:.2})",
91        config.impulse_start,
92        config.impulse_start as f64 * config.dt
93    );
94    println!("  Impulse duration: {} steps", config.impulse_duration);
95    println!("  Impulse amplitude: {}", config.impulse_amplitude);
96    println!("  Output directory: {}", run_outdir.display());
97    println!();
98
99    let results = run_simulation(config.clone(), dsfb_params);
100
101    // Calculate metrics
102    let errors_mean: Vec<f64> = results.iter().map(|r| r.err_mean).collect();
103    let errors_freqonly: Vec<f64> = results.iter().map(|r| r.err_freqonly).collect();
104    let errors_dsfb: Vec<f64> = results.iter().map(|r| r.err_dsfb).collect();
105
106    let rms_mean = rms_error(&errors_mean);
107    let rms_freqonly = rms_error(&errors_freqonly);
108    let rms_dsfb = rms_error(&errors_dsfb);
109
110    let peak_mean = peak_error_during_impulse(
111        &results,
112        config.impulse_start,
113        config.impulse_duration,
114        |s| s.err_mean,
115    );
116    let peak_freqonly = peak_error_during_impulse(
117        &results,
118        config.impulse_start,
119        config.impulse_duration,
120        |s| s.err_freqonly,
121    );
122    let peak_dsfb = peak_error_during_impulse(
123        &results,
124        config.impulse_start,
125        config.impulse_duration,
126        |s| s.err_dsfb,
127    );
128
129    let impulse_end = config.impulse_start + config.impulse_duration;
130    let recovery_threshold = 0.05;
131    let recovery_mean = recovery_time(&results, impulse_end, recovery_threshold, |s| s.err_mean);
132    let recovery_freqonly = recovery_time(&results, impulse_end, recovery_threshold, |s| {
133        s.err_freqonly
134    });
135    let recovery_dsfb = recovery_time(&results, impulse_end, recovery_threshold, |s| s.err_dsfb);
136
137    // Print metrics
138    println!("METRICS SUMMARY");
139    println!("===============");
140    println!("\nRMS Errors:");
141    println!("  Mean Fusion:    {:.6}", rms_mean);
142    println!("  Freq-Only:      {:.6}", rms_freqonly);
143    println!("  DSFB:           {:.6}", rms_dsfb);
144
145    println!("\nPeak Error During Impulse:");
146    println!("  Mean Fusion:    {:.6}", peak_mean);
147    println!("  Freq-Only:      {:.6}", peak_freqonly);
148    println!("  DSFB:           {:.6}", peak_dsfb);
149
150    println!(
151        "\nRecovery Time (steps after impulse, threshold={}):",
152        recovery_threshold
153    );
154    println!("  Mean Fusion:    {}", recovery_mean);
155    println!("  Freq-Only:      {}", recovery_freqonly);
156    println!("  DSFB:           {}", recovery_dsfb);
157
158    // Write CSV
159    let csv_path = run_outdir.join("sim-dsfb.csv");
160    let mut file = File::create(&csv_path)?;
161
162    writeln!(
163        file,
164        "t,phi_true,phi_mean,phi_freqonly,phi_dsfb,err_mean,err_freqonly,err_dsfb,w2,s2"
165    )?;
166
167    for step in &results {
168        writeln!(
169            file,
170            "{:.6},{:.6},{:.6},{:.6},{:.6},{:.6},{:.6},{:.6},{:.6},{:.6}",
171            step.t,
172            step.phi_true,
173            step.phi_mean,
174            step.phi_freqonly,
175            step.phi_dsfb,
176            step.err_mean,
177            step.err_freqonly,
178            step.err_dsfb,
179            step.w2,
180            step.s2
181        )?;
182    }
183
184    println!("\nCSV output written to: {}", csv_path.display());
185    println!("Done!");
186
187    Ok(())
188}
Source

pub fn default_params() -> Self

Create default parameters suitable for basic simulation

Trait Implementations§

Source§

impl Clone for DsfbParams

Source§

fn clone(&self) -> DsfbParams

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DsfbParams

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DsfbParams

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for DsfbParams

Source§

fn eq(&self, other: &DsfbParams) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for DsfbParams

Source§

impl StructuralPartialEq for DsfbParams

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V