lib_jsl_dsp/discrete/windows/
bohman.rs1use std::f64::consts::PI;
2
3use super::{extend, len_guard, linspace, truncate};
4
5pub fn bohman(m: usize, sym: bool) -> Vec<f64> {
7 if let Some(w) = len_guard(m) {
8 return w;
9 }
10 let (m2, needs_trunc) = extend(m, sym);
11 let x = linspace(-1.0, 1.0, m2);
12 let mut w = vec![0.0; m2];
13 for i in 1..(m2 - 1) {
14 let fac = x[i].abs();
15 w[i] = (1.0 - fac) * (PI * fac).cos() + (PI * fac).sin() / PI;
16 }
17 truncate(w, needs_trunc)
18}
19
20#[cfg(test)]
21mod tests {
22 use super::*;
23 use crate::discrete::windows::test_support::assert_window;
24
25 #[test]
26 fn test_bohman() {
27 assert_window(include_str!("../test_data/bohman.csv"), bohman(7, true));
28 }
29}