This commit is contained in:
Tove 2026-03-05 21:08:32 +01:00
parent 417672e718
commit f6fcd8c3cd
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
2 changed files with 30 additions and 6 deletions

View file

@ -17,6 +17,7 @@ output params are any as follows:
- `channel <x|y|z|multi>` specifies which accelerometer channel to covert. z is default. multi mixes channels
- `integrate` sets integration mode, where the input is integrated first to enhance low frequencies that may not be picked up correctly.
- `autoscale` automatically sets the multiplier based on the input. (this is the default. parameter is still accepted for compatibility)
- `lpf <number>` performs a low pass filter with some strength
when using interp, a low pass filter may be useful to remove the harmonics of the sawtooth-like resulting waveform. audacity has one.
when using integrate mode, multiply may need to be set to a lower number.

View file

@ -14,6 +14,7 @@ struct Params {
multiply: f64,
integrate: bool,
autoscale: bool,
filter: f64,
}
impl Params {
@ -54,6 +55,13 @@ impl Params {
.parse()
.unwrap();
}
"lpf" => {
params.filter = iter
.next()
.expect("filter parameter expects a value.")
.parse()
.unwrap();
}
"integrate" => {
params.integrate = true;
}
@ -76,6 +84,7 @@ impl Default for Params {
multiply: 5.0,
integrate: false,
autoscale: true,
filter: 0.0,
}
}
}
@ -102,6 +111,7 @@ output params are any as follows:
- `channel <x|y|z|multi>` specifies which accelerometer channel to covert. z is default. multi mixes channels
- `integrate` sets integration mode, where the input is integrated first to enhance low frequencies that may not be picked up correctly.
- `autoscale` automatically sets the multiplier based on the input. (this is the default. parameter is still accepted for compatibility)
- `lpf <number>` performs a low pass filter with some strength
when using interp, a low pass filter may be useful to remove the harmonics of the sawtooth-like resulting waveform. audacity has one.
when using integrate mode, multiply may need to be set to a lower number.\
@ -126,6 +136,11 @@ when using integrate mode, multiply may need to be set to a lower number.\
remove_offset(&mut samples);
if params.filter > 0.0 {
println!("infraconv: Filter = {}", params.filter);
filter(&mut samples, params.filter);
}
if params.integrate {
integrate(&mut samples, input_hz);
remove_offset(&mut samples);
@ -215,25 +230,33 @@ fn get_scale(samples: &[f64]) -> f64 {
max
}
fn filter(samples: &mut [f64], filter: f64) {
let mut f = samples[0];
for sample in samples.iter_mut().skip(1) {
f = (f * filter + *sample) / filter + 1.0;
*sample = f;
}
}
fn read_csv(file: &str, channel: Channel) -> Vec<f64> {
let csv = fs::read_to_string(file).expect("no existing input file provided");
csv.trim()
.lines()
.filter(|line| line.contains(',') || !csv.contains(','))
.map(|line| {
.filter_map(|line| {
let values = line.split(',');
let values = values
.into_iter()
.map(|x| x.parse().unwrap())
.filter_map(|x| x.parse().ok())
.collect::<Vec<_>>();
if values.len() > 1 {
Some(if values.len() > 1 {
match channel {
Channel::N(channel) => values[channel],
Channel::N(channel) => *values.get(channel)?,
Channel::VecLen => values.iter().sum::<f64>() / values.len() as f64,
}
} else {
values[0]
}
*values.first()?
})
})
.collect()
}