lib_jsl_dsp/discrete/windows/
exponential.rs1use super::{extend, len_guard, truncate};
2
3pub fn exponential(m: usize, center: Option<f64>, tau: f64, sym: bool) -> Vec<f64> {
5 if let Some(w) = len_guard(m) {
6 return w;
7 }
8 let (m2, needs_trunc) = extend(m, sym);
9 let c = center.unwrap_or((m2 as f64 - 1.0) / 2.0);
10 let mut w = vec![0.0; m2];
11 for (i, wn) in w.iter_mut().enumerate() {
12 *wn = (-(i as f64 - c).abs() / tau).exp();
13 }
14 truncate(w, needs_trunc)
15}
16
17#[cfg(test)]
18mod tests {
19 use super::*;
20 use crate::discrete::windows::test_support::assert_window;
21
22 #[test]
23 fn test_exponential() {
24 assert_window(include_str!("../test_data/exponential.csv"), exponential(7, None, 1.0, true));
25 }
26}