Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,22 +348,22 @@ fn generate_window<T: Float + FromPrimitive>(window_type: WindowType, size: usiz
let half = T::from(0.5).unwrap();
let one = T::one();
let i_t = T::from(i).unwrap();
let size_m1 = T::from(size - 1).unwrap();
half * (one - (two * pi * i_t / size_m1).cos())
let size_t = T::from(size).unwrap(); // Use N, not N-1 for periodic window
half * (one - (two * pi * i_t / size_t).cos())
})
.collect(),
WindowType::Hamming => (0..size)
.map(|i| {
let i_t = T::from(i).unwrap();
let size_m1 = T::from(size - 1).unwrap();
T::from(0.54).unwrap() - T::from(0.46).unwrap() * (two * pi * i_t / size_m1).cos()
let size_t = T::from(size).unwrap(); // Use N, not N-1 for periodic window
T::from(0.54).unwrap() - T::from(0.46).unwrap() * (two * pi * i_t / size_t).cos()
})
.collect(),
Comment on lines 355 to 361
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the Hann window, constant values can be calculated outside the map closure for better performance. Also, using named constants for magic numbers like 0.54 and 0.46 improves readability.

        WindowType::Hamming => {
            let size_t = T::from(size).unwrap(); // Use N, not N-1 for periodic window
            let a0 = T::from(0.54).unwrap();
            let a1 = T::from(0.46).unwrap();
            (0..size)
                .map(|i| {
                    let i_t = T::from(i).unwrap();
                    a0 - a1 * (two * pi * i_t / size_t).cos()
                })
                .collect()
        },

WindowType::Blackman => (0..size)
.map(|i| {
let i_t = T::from(i).unwrap();
let size_m1 = T::from(size - 1).unwrap();
let angle = two * pi * i_t / size_m1;
let size_t = T::from(size).unwrap(); // Use N, not N-1 for periodic window
let angle = two * pi * i_t / size_t;
T::from(0.42).unwrap() - T::from(0.5).unwrap() * angle.cos()
+ T::from(0.08).unwrap() * (two * angle).cos()
})
Expand Down