Compare commits

...

2 Commits

Author SHA1 Message Date
6445949083 Fix FFT scaling 2024-05-12 21:19:18 -04:00
dbbd6ab849 Fix bode plot window always grows to maximum height 2024-05-12 21:14:36 -04:00
2 changed files with 12 additions and 5 deletions

View File

@ -57,7 +57,8 @@ impl AudioFFT {
let output: Vec<u8> = fft_out let output: Vec<u8> = fft_out
.iter() .iter()
.map(|c| { .map(|c| {
(((c.re * c.re) + (c.im * c.im)).sqrt() / size as f32 * 255.0) as u8 (((c.re * c.re) + (c.im * c.im)).sqrt() / output_len as f32 * 255.0)
as u8
}) })
.collect(); .collect();
assert_eq!(output_len, output.len()); assert_eq!(output_len, output.len());

View File

@ -71,7 +71,7 @@ impl DebugPlots {
plot_ui.line(line); plot_ui.line(line);
plot_ui.set_plot_bounds(PlotBounds::from_min_max( plot_ui.set_plot_bounds(PlotBounds::from_min_max(
[-1.0, -1.0], [-1.0, -1.0],
[(v.len() + 1) as f64, 256.0], [(v.len() + 1) as f64, core::u8::MAX as f64 + 1.0],
)); ));
}); });
} }
@ -79,19 +79,25 @@ impl DebugPlots {
ui.heading("Bode Plot"); ui.heading("Bode Plot");
let mag_line = let mag_line =
Line::new(PlotPoints::from_iter(v.iter().enumerate().map(|(i, c)| { Line::new(PlotPoints::from_iter(v.iter().enumerate().map(|(i, c)| {
[i as f64, ((c.re * c.re) + (c.im * c.im)).sqrt() as f64] [
i as f64,
((c.re * c.re) + (c.im * c.im)).sqrt() as f64 / v.len() as f64,
]
}))); })));
let phase_line = Line::new(PlotPoints::from_iter( let phase_line = Line::new(PlotPoints::from_iter(
v.iter() v.iter()
.enumerate() .enumerate()
.map(|(i, c)| [i as f64, c.arg() as f64]), .map(|(i, c)| [i as f64, c.arg() as f64 / core::f64::consts::PI]),
)); ));
let plot = Plot::new(title); let plot = Plot::new(title);
plot.show(ui, |plot_ui| { plot.show(ui, |plot_ui| {
plot_ui.line(mag_line); plot_ui.line(mag_line);
plot_ui.line(phase_line); plot_ui.line(phase_line);
plot_ui.set_plot_bounds(PlotBounds::from_min_max(
[0.0, -1.0],
[(v.len() + 1) as f64, 1.0],
));
}); });
ui.heading("TODO");
} }
}; };
}); });