Add a Hann function for the STFT helper
This commit is contained in:
parent
3c62670164
commit
bf215ef88e
|
@ -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
17
src/util/window.rs
Normal 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()
|
||||
}
|
Loading…
Reference in a new issue