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: f64Gain for phi correction
k_omega: f64Gain for omega correction
k_alpha: f64Gain for alpha correction
rho: f64EMA smoothing factor (0 < rho < 1)
sigma0: f64Trust softness parameter
Implementations§
Source§impl DsfbParams
impl DsfbParams
Sourcepub fn new(
k_phi: f64,
k_omega: f64,
k_alpha: f64,
rho: f64,
sigma0: f64,
) -> Self
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}Sourcepub fn default_params() -> Self
pub fn default_params() -> Self
Create default parameters suitable for basic simulation
Trait Implementations§
Source§impl Clone for DsfbParams
impl Clone for DsfbParams
Source§fn clone(&self) -> DsfbParams
fn clone(&self) -> DsfbParams
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DsfbParams
impl Debug for DsfbParams
Source§impl Default for DsfbParams
impl Default for DsfbParams
Source§impl PartialEq for DsfbParams
impl PartialEq for DsfbParams
impl Copy for DsfbParams
impl StructuralPartialEq for DsfbParams
Auto Trait Implementations§
impl Freeze for DsfbParams
impl RefUnwindSafe for DsfbParams
impl Send for DsfbParams
impl Sync for DsfbParams
impl Unpin for DsfbParams
impl UnsafeUnpin for DsfbParams
impl UnwindSafe for DsfbParams
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more