Added bode plots to GUI.

This commit is contained in:
2025-10-07 10:18:04 +02:00
parent beefe733c0
commit e71b02477a
10 changed files with 331 additions and 49 deletions

View File

@@ -3,6 +3,8 @@ use std::collections::VecDeque;
use egui_plot::{PlotPoint, PlotPoints};
use bioz_icd_rs::NumberOfPoints;
pub struct TimeSeriesPlot {
pub values: VecDeque<PlotPoint>,
max_points: usize,
@@ -46,4 +48,42 @@ impl TimeSeriesPlot {
.map(|i| PlotPoint::new(i, f64::NAN))
.collect();
}
}
pub struct BodePlot {
pub magnitudes: Vec<PlotPoint>,
pub phases: Vec<PlotPoint>,
}
impl BodePlot {
pub fn new() -> Self {
Self {
magnitudes: Vec::new(),
phases: Vec::new(),
}
}
pub fn update_magnitudes(&mut self, magnitudes: Vec<f32>) {
let freqs = NumberOfPoints::TwentyEight.values().to_vec();
// self.magnitudes = freqs.into_iter().zip(magnitudes.into_iter()).map(|(f, m)| PlotPoint::new(f.log10(), 20.0 * m.log10() as f32)).collect();
self.magnitudes = freqs.into_iter().zip(magnitudes.into_iter()).map(|(f, m)| PlotPoint::new(f.log10(), m as f32)).collect();
}
pub fn update_phases(&mut self, phases: Vec<f32>) {
let freqs = NumberOfPoints::TwentyEight.values().to_vec();
self.phases = freqs.into_iter().zip(phases.into_iter()).map(|(f, p)| PlotPoint::new(f.log10(), p as f64)).collect();
}
pub fn plot_magnitudes(&self) -> PlotPoints {
PlotPoints::Owned(self.magnitudes.clone())
}
pub fn plot_phases(&self) -> PlotPoints {
PlotPoints::Owned(self.phases.clone())
}
pub fn clear(&mut self) {
self.magnitudes.clear();
self.phases.clear();
}
}