1
0
Fork 0

Add a Hann function for the STFT helper

This commit is contained in:
Robbert van der Helm 2022-03-06 14:41:40 +01:00
parent 3c62670164
commit bf215ef88e
2 changed files with 18 additions and 0 deletions

View file

@ -1,6 +1,7 @@
//! General conversion functions and utilities.
mod stft;
pub mod window;
pub use stft::StftHelper;

17
src/util/window.rs Normal file
View file

@ -0,0 +1,17 @@
//! Windowing functions, useful in conjuction with [`StftHelper`][super::StftHelper].
use std::f32;
/// A Hann window function.
///
/// <https://en.wikipedia.org/wiki/Hann_function>
pub fn hann(size: usize) -> Vec<f32> {
// We want to scale `[0, size]` to `[0, pi]`.
let scale = (size as f32 - 1.0).recip() * f32::consts::PI;
(0..size)
.map(|i| {
let sin = (i as f32 * scale).sin();
sin * sin
})
.collect()
}