use crate::config::*;
use strum::EnumMessage;
use strum_macros::Display;
#[cfg_attr(feature = "python-bindings", pyclass(eq))]
#[derive(Clone, Copy, Debug, PartialEq, Display)]
pub enum TimeWeighting {
Slow {},
Fast {},
Impulse {},
CustomSymmetric {
t: Flt,
},
CustomAsymmetric {
tup: Flt,
tdown: Flt,
},
}
#[cfg(feature = "python-bindings")]
#[cfg_attr(feature = "python-bindings", pymethods)]
impl TimeWeighting {
fn __str__(&self) -> String {
format!("{self}")
}
#[staticmethod]
fn all_standards() -> Vec<TimeWeighting> {
use TimeWeighting::*;
vec![Slow {}, Fast {}, Impulse {}]
}
#[pyo3(name = "getLowpassPoles")]
fn getLowpassPoles_py(&self) -> (Flt, Option<Flt>) {
self.getLowpassPoles()
}
}
impl Default for TimeWeighting {
fn default() -> Self {
TimeWeighting::Fast {}
}
}
impl TimeWeighting {
pub fn getLowpassPoles(&self) -> (Flt, Option<Flt>) {
use TimeWeighting::*;
match self {
Slow {} => (-1.0, None),
Fast {} =>
{
(-8., None)
}
Impulse {} => {
(-1. / 35e-3, Some(-1. / 1.5))
}
CustomSymmetric { t } => {
assert!(*t > 0.);
(-*t, None)
}
CustomAsymmetric { tup, tdown } => {
assert!(*tup > 0.);
assert!(*tdown > 0.);
(-1. / (*tup), Some(-1. / (*tdown)))
}
}
}
}
#[cfg(test)]
mod test {
use crate::slm::TimeWeighting;
#[test]
fn test_tw() {
println!("Impulse: {}", TimeWeighting::Impulse {});
println!("Fast : {}", TimeWeighting::Fast {});
println!("Slow : {}", TimeWeighting::Slow {});
}
}