Skip to content

Commit

Permalink
drop ndarray
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Sep 19, 2023
1 parent d8fca99 commit e59dbd7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 70 deletions.
30 changes: 0 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ eframe = { version = "0.22", default-features = false, features = ["glow", "defa
# image = { version = "0.24", default-features = false, features = ["png"] }
# rfd = "0.11.0"
env_logger = "0.10"
ndarray = "0.15.6"
bytemuck = "1.13.1"
thiserror = "1.0.47"
anyhow = "1.0.75"
Expand Down
1 change: 1 addition & 0 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl eframe::App for FLS {
.width(600.0)
.height(400.0)
// .x_grid_spacer(log_grid_spacer(10))
// .x_axis_formatter(log_axis_formatter())
.legend(Legend::default());
plot.show(ui, |plot_ui| {
if let Some(traces) = &mut self.current {
Expand Down
67 changes: 28 additions & 39 deletions src/de/data.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use ndarray::{ArrayView, Axis, ShapeError};
use thiserror::Error;

#[derive(Error, Debug, Clone)]
pub enum FormatError {
#[error("Invalid frame payload size")]
InvalidSize(#[from] ShapeError),
}
pub enum FormatError {}

pub trait Payload {
fn new(batches: usize, data: &[u8]) -> Result<Self, FormatError>
Expand All @@ -27,14 +23,8 @@ impl Payload for AdcDac {
/// * `batch_size` - The size of each batch in samples.
/// * `data` - The binary data composing the stream frame.
fn new(batches: usize, data: &[u8]) -> Result<Self, FormatError> {
let channels = 4;
let samples = data.len() / batches / channels / core::mem::size_of::<i16>();
let mut data = ArrayView::from_shape(
(batches, channels, samples, core::mem::size_of::<i16>()),
data,
)?;
data.swap_axes(0, 1); // FIXME: non-contig
let data = data.into_shape((channels, samples * batches, core::mem::size_of::<i16>()))?;
const CHANNELS: usize = 4;
const BATCH_SIZE: usize = 8;

// The DAC output range in bipolar mode (including the external output op-amp) is +/- 4.096
// V with 16-bit resolution. The anti-aliasing filter has an additional gain of 2.5.
Expand All @@ -44,36 +34,35 @@ impl Payload for AdcDac {
const ADC_VOLT_PER_LSB: f32 = 5.0 / 2.0 * 4.096 / (1u16 << 15) as f32;
assert_eq!(DAC_VOLT_PER_LSB, ADC_VOLT_PER_LSB);

let traces: [Vec<f32>; 4] = [
data.index_axis(Axis(0), 0)
.axis_iter(Axis(0))
.map(|x| {
i16::from_le_bytes([x[0], x[1]]).wrapping_add(i16::MIN) as f32
* DAC_VOLT_PER_LSB
})
.collect(),
data.index_axis(Axis(0), 1)
.axis_iter(Axis(0))
.map(|x| {
i16::from_le_bytes([x[0], x[1]]).wrapping_add(i16::MIN) as f32
* DAC_VOLT_PER_LSB
})
.collect(),
data.index_axis(Axis(0), 2)
.axis_iter(Axis(0))
.map(|x| i16::from_le_bytes([x[0], x[1]]) as f32 * ADC_VOLT_PER_LSB)
.collect(),
data.index_axis(Axis(0), 3)
.axis_iter(Axis(0))
.map(|x| i16::from_le_bytes([x[0], x[1]]) as f32 * ADC_VOLT_PER_LSB)
.collect(),
];

let v = Vec::with_capacity(data.len() * BATCH_SIZE);
let mut traces = [v.clone(), v.clone(), v.clone(), v];
let data: &[[[[u8; 2]; BATCH_SIZE]; CHANNELS]] = bytemuck::cast_slice(data);
assert_eq!(data.len(), batches);
for b in data.iter() {
traces[0].extend(
b[0].into_iter()
.map(|x| i16::from_le_bytes(x) as f32 * ADC_VOLT_PER_LSB),
);
traces[1].extend(
b[1].into_iter()
.map(|x| i16::from_le_bytes(x) as f32 * ADC_VOLT_PER_LSB),
);
traces[2].extend(
b[2].into_iter().map(|x| {
i16::from_le_bytes(x).wrapping_add(i16::MIN) as f32 * DAC_VOLT_PER_LSB
}),
);
traces[3].extend(
b[3].into_iter().map(|x| {
i16::from_le_bytes(x).wrapping_add(i16::MIN) as f32 * DAC_VOLT_PER_LSB
}),
);
}
Ok(Self { traces })
}

fn traces(&self) -> &[Vec<f32>] {
&self.traces[..]
&self.traces
}

fn traces_mut(&mut self) -> &mut [Vec<f32>] {
Expand Down

0 comments on commit e59dbd7

Please sign in to comment.