Skip to main content

lib_jsl_dsp/discrete/windows/
hamming.rs

1use super::general_cosine::general_cosine;
2
3/// The general Hamming window is a two-term cosine window with coefficients `[alpha, 1 - alpha]`.
4pub fn general_hamming(m: usize, alpha: f64, sym: bool) -> Vec<f64> {
5    general_cosine(m, &[alpha, 1.0 - alpha], sym)
6}
7
8/// The Hamming window is the general Hamming window with `alpha = 0.54`, which places a zero near the first side lobe of the rectangular window's spectrum.
9pub fn hamming(m: usize, sym: bool) -> Vec<f64> {
10    general_hamming(m, 0.54, sym)
11}
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16    use crate::discrete::windows::test_support::assert_window;
17
18    #[test]
19    fn test_hamming() {
20        assert_window(include_str!("../test_data/hamming.csv"), hamming(7, true));
21    }
22
23    #[test]
24    fn test_general_hamming() {
25        assert_window(include_str!("../test_data/general_hamming.csv"), general_hamming(7, 0.54, true));
26    }
27}