Skip to main content

lib_jsl_dsp/discrete/windows/
general_gaussian.rs

1use super::{extend, len_guard, truncate};
2
3/// The general Gaussian window is defined by a specific mathematical formula that involves an exponential function based on the distance from the center of the window, with an additional parameter `p` that controls the shape of the window. The coefficients are computed based on the position within the window, the total length, and the parameters `p` and `sig`, which control the shape of the window and its spectral properties.
4pub fn general_gaussian(m: usize, p: f64, sig: 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 mut w = vec![0.0; m2];
10    let c = (m2 as f64 - 1.0) / 2.0;
11    for (i, wn) in w.iter_mut().enumerate() {
12        let n = i as f64 - c;
13        *wn = (-0.5 * (n / sig).abs().powf(2.0 * p)).exp();
14    }
15    truncate(w, needs_trunc)
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21    use crate::discrete::windows::test_support::assert_window;
22
23    #[test]
24    fn test_general_gaussian() {
25        assert_window(include_str!("../test_data/general_gaussian.csv"), general_gaussian(7, 1.5, 1.0, true));
26    }
27}