mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2025-12-06 05:11:17 +00:00
Added bode plots to GUI.
This commit is contained in:
40
src/plot.rs
40
src/plot.rs
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user