diff --git a/docs/Project.toml b/docs/Project.toml index ce9aa3290..618b7e55f 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,3 +1,6 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +FLAC = "abae9e3b-a9a0-4778-b5c6-ca109b507d99" +FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" +UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" diff --git a/docs/make.jl b/docs/make.jl index 599aaf9dc..6b06f971e 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -3,17 +3,19 @@ using Documenter, NNlib DocMeta.setdocmeta!(NNlib, :DocTestSetup, :(using NNlib); recursive = true) makedocs(modules = [NNlib], - sitename = "NNlib.jl", - doctest = false, - pages = ["Home" => "index.md", - "Reference" => "reference.md"], - format = Documenter.HTML( - canonical = "https://fluxml.ai/NNlib.jl/stable/", - # analytics = "UA-36890222-9", - assets = ["assets/flux.css"], - prettyurls = get(ENV, "CI", nothing) == "true"), - warnonly=[:missing_docs,] - ) + sitename = "NNlib.jl", + doctest = true, + pages = ["Home" => "index.md", + "Reference" => "reference.md", + "Audio" => "audio.md"], + format = Documenter.HTML( + canonical = "https://fluxml.ai/NNlib.jl/stable/", + # analytics = "UA-36890222-9", + assets = ["assets/flux.css"], + prettyurls = get(ENV, "CI", nothing) == "true", + size_threshold=nothing), + warnonly=[:missing_docs,] +) deploydocs(repo = "github.com/FluxML/NNlib.jl.git", target = "build", diff --git a/docs/src/assets/jfk.flac b/docs/src/assets/jfk.flac new file mode 100644 index 000000000..24841d55a Binary files /dev/null and b/docs/src/assets/jfk.flac differ diff --git a/docs/src/audio.md b/docs/src/audio.md new file mode 100644 index 000000000..e6df815a8 --- /dev/null +++ b/docs/src/audio.md @@ -0,0 +1,43 @@ +# Reference + +## Window functions + +```@docs +hann_window +hamming_window +``` + +## Spectral + +```@docs +stft +istft +NNlib.power_to_db +NNlib.db_to_power +``` + +## Spectrogram + +```@docs +spectrogram +``` + +Example: + +```@example 1 +using NNlib +using FileIO, FLAC +using UnicodePlots + +waveform, sampling_rate = load("./assets/jfk.flac") +lineplot(waveform[50000:51000, 1]; + width=50, compact=true, padding=0, margin=0, color=:white) +``` + +```@example 1 +spec = spectrogram(waveform; n_fft=256, hop_length=64, window=hann_window(256)) + +heatmap(NNlib.power_to_db(spec)[:, :, 1]; + width=80, height=30, compact=true, grid=true, + colorbar_border=:none, border=:none, padding=0, margin=0) +``` diff --git a/docs/src/reference.md b/docs/src/reference.md index d9769e396..4f90db762 100644 --- a/docs/src/reference.md +++ b/docs/src/reference.md @@ -163,15 +163,3 @@ NNlib.glu NNlib.within_gradient bias_act! ``` - -## Spectral - -```@docs -hann_window -hamming_window -stft -istft -spectrogram -NNlib.power_to_db -NNlib.db_to_power -``` diff --git a/src/audio/spectrogram.jl b/src/audio/spectrogram.jl index 0b600a6ef..8e8bdcb0d 100644 --- a/src/audio/spectrogram.jl +++ b/src/audio/spectrogram.jl @@ -1,4 +1,9 @@ """ + spectrogram(waveform; + pad::Int = 0, n_fft::Int, hop_length::Int, window, + center::Bool = true, power::Real = 2.0, + normalized::Bool = false, window_normalized::Bool = false, + ) Create a spectrogram or a batch of spectrograms from a raw audio signal. @@ -6,10 +11,8 @@ Create a spectrogram or a batch of spectrograms from a raw audio signal. - `pad::Int`: Then amount of padding to apply on both sides. - Default is `0`. - `window_normalized::Bool`: Whether to normalize the waveform by the window’s L2 energy. - Default is `false`. - `power::Real`: Exponent for the magnitude spectrogram (must be ≥ 0) e.g., `1` for magnitude, `2` for power, etc. @@ -21,19 +24,6 @@ See [`stft`](@ref) for other arguments. Spectrogram in the shape `(T, F, B)`, where `T` is the number of window hops and `F = n_fft ÷ 2 + 1`. - -# Example - -```julia -julia> waveform, sampling_rate = load("test.flac"); - -julia> spec = spectrogram(waveform; - n_fft=1024, hop_length=128, window=hann_window(1024)); - -julia> spec_db = NNlib.power_to_db(spec); - -julia> Makie.heatmap(spec_db[:, :, 1]) -``` """ function spectrogram(waveform; pad::Int = 0, n_fft::Int, hop_length::Int, window, @@ -65,10 +55,10 @@ Convert a power spectrogram (amplitude squared) to decibel (dB) units. # Arguments - `s`: Input power. -- `ref`: Scalar w.r.t. which the input is scaled. Default is `1`. -- `amin`: Minimum threshold for `s`. Default is `1f-10`. +- `ref`: Scalar w.r.t. which the input is scaled. +- `amin`: Minimum threshold for `s`. - `top_db`: Threshold the output at `top_db` below the peak: - `max.(s_db, maximum(s_db) - top_db)`. Default is `80`. + `max.(s_db, maximum(s_db) - top_db)`. # Returns diff --git a/src/audio/stft.jl b/src/audio/stft.jl index b7447033d..8dac93b5a 100644 --- a/src/audio/stft.jl +++ b/src/audio/stft.jl @@ -1,40 +1,38 @@ """ - hann_window( + hamming_window( window_length::Int, ::Type{T} = Float32; periodic::Bool = true, + α::T = T(0.54), β::T = T(0.46), ) where T <: Real -Hann window function. +Hamming window function +(ref: https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows). +Generalized version of `hann_window`. -``w[n] = \\frac{1}{2}[1 - cos(\\frac{2 \\pi n}{N - 1})]`` +``w[n] = \\alpha - \\beta cos(\\frac{2 \\pi n}{N - 1})`` Where ``N`` is the window length. ```julia -julia> lineplot(hann_window(100)) - ┌────────────────────────────────────────┐ - 1 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠎⠉⠉⠉⠣⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠎⠀⠀⠀⠀⠀⠀⠀⠣⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢇⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⡜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢇⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡆⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⡰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡄⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⡠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡄⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⡰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢄⠀⠀⠀⠀│ - │⠀⠀⠀⠀⡔⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢆⠀⠀⠀│ - 0 │⣀⣀⡔⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⢆⣀│ - └────────────────────────────────────────┘ - ⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀100⠀ +julia> lineplot(hamming_window(100); width=30, height=10) + ┌──────────────────────────────┐ + 1 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠚⠉⠉⠉⠢⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠎⠁⠀⠀⠀⠀⠀⠈⢢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⡀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⢰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⣠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠳⡀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⢰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡄⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⡰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠱⡀⠀⠀⠀⠀│ + │⠀⠀⠀⢀⠴⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢄⠀⠀⠀│ + │⠀⢀⡠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠳⣀⠀│ + 0 │⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉│ + └──────────────────────────────┘ + ⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀100⠀ ``` # Arguments: - `window_length::Int`: Size of the window. -- `::Type{T}`: Elemet type of the window. Default is `Float32`. +- `::Type{T}`: Elemet type of the window. # Keyword Arguments: @@ -43,63 +41,64 @@ julia> lineplot(hann_window(100)) Following always holds: -```julia -hann_window(N; periodic=true) ≈ hann_window(N + 1; periodic=false)[1:end - 1] +```jldoctest +julia> N = 256; + +julia> hamming_window(N; periodic=true) ≈ hamming_window(N + 1; periodic=false)[1:end - 1] +true ``` +- `α::Real`: Coefficient α in the equation above. +- `β::Real`: Coefficient β in the equation above. # Returns: Vector of length `window_length` and eltype `T`. """ -function hann_window( +function hamming_window( window_length::Int, ::Type{T} = Float32; periodic::Bool = true, + α::T = T(0.54), β::T = T(0.46), ) where T <: Real window_length < 1 && throw(ArgumentError( "`window_length` must be > 0, instead: `$window_length`.")) n::T = ifelse(periodic, window_length, window_length - 1) scale = T(2) * π / n - [T(0.5) * (T(1) - cos(scale * T(k))) for k in 0:(window_length - 1)] + return [α - β * cos(scale * T(k)) for k in 0:(window_length - 1)] end """ - hamming_window( + hann_window( window_length::Int, ::Type{T} = Float32; periodic::Bool = true, - α::T = T(0.54), β::T = T(0.46), ) where T <: Real -Hamming window function. Generalized version of `hann_window`. +Hann window function +(ref: https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows). -``w[n] = \\alpha - \\beta cos(\\frac{2 \\pi n}{N - 1})`` +``w[n] = \\frac{1}{2}[1 - cos(\\frac{2 \\pi n}{N - 1})]`` Where ``N`` is the window length. ```julia -julia> lineplot(hamming_window(100)) - ┌────────────────────────────────────────┐ - 1 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠊⠉⠉⠉⠓⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠎⠀⠀⠀⠀⠀⠀⠀⠣⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡴⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⡄⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⢠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⡄⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⣠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⡄⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⡠⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⡄⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⡰⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢄⠀⠀⠀⠀│ - │⠀⠀⠀⢀⠎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠣⡀⠀⠀│ - │⣀⠤⠖⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠢⠤│ - 0 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - └────────────────────────────────────────┘ - ⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀100⠀ +julia> lineplot(hann_window(100); width=30, height=10) + ┌──────────────────────────────┐ + 1 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠚⠉⠉⠉⠢⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡔⠁⠀⠀⠀⠀⠀⠘⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠞⠀⠀⠀⠀⠀⠀⠀⠀⠈⢆⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⢀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢣⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢦⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⢀⠞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢆⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⢀⡜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢇⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⢀⠎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢦⠀⠀⠀⠀│ + │⠀⠀⠀⢠⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠣⡀⠀⠀│ + 0 │⣀⣀⠔⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢤⣀│ + └──────────────────────────────┘ + ⠀0⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀100⠀ ``` # Arguments: - `window_length::Int`: Size of the window. -- `::Type{T}`: Elemet type of the window. Default is `Float32`. +- `::Type{T}`: Elemet type of the window. # Keyword Arguments: @@ -108,26 +107,24 @@ julia> lineplot(hamming_window(100)) Following always holds: -```julia -hamming_window(N; periodic=true) ≈ hamming_window(N + 1; periodic=false)[1:end - 1] +```jldoctest +julia> N = 256; + +julia> hann_window(N; periodic=true) ≈ hann_window(N + 1; periodic=false)[1:end - 1] +true + +julia> hann_window(N) ≈ hamming_window(N; α=0.5f0, β=0.5f0) +true ``` -- `α::Real`: Coefficient α in the equation above. -- `β::Real`: Coefficient β in the equation above. # Returns: Vector of length `window_length` and eltype `T`. """ -function hamming_window( +function hann_window( window_length::Int, ::Type{T} = Float32; periodic::Bool = true, - α::T = T(0.54), β::T = T(0.46), ) where T <: Real - window_length < 1 && throw(ArgumentError( - "`window_length` must be > 0, instead: `$window_length`.")) - - n::T = ifelse(periodic, window_length, window_length - 1) - scale = T(2) * π / n - [α - β * cos(scale * T(k)) for k in 0:(window_length - 1)] + hamming_window(window_length, T; periodic, α=T(0.5), β=T(0.5)) end """ @@ -156,14 +153,13 @@ and ``m`` is the index of the sliding window. - `n_fft::Int`: Size of Fourier transform. - `hop_length::Int`: Distance between neighboring sliding window frames. - Default is `n_fft ÷ 4`. - `window`: Optional window function to apply. Must be 1D vector `0 < length(window) ≤ n_fft`. If window is shorter than `n_fft`, it is padded with zeros on both sides. If `nothing` (default), then no window is applied. - `center::Bool`: Whether to pad input on both sides so that ``t``-th frame is centered at time ``t \\times \\text{hop length}``. - Default is `true`. Padding is done with `pad_reflect` function. + Padding is done with `pad_reflect` function. - `normalized::Bool`: Whether to return normalized STFT, i.e. multiplied with ``\\text{n fft}^{-0.5}``. @@ -247,16 +243,14 @@ Return the least squares estimation of the original signal - `n_fft::Int`: Size of Fourier transform. - `hop_length::Int`: Distance between neighboring sliding window frames. - Default is `n_fft ÷ 4`. - `window`: Window function that was applied to the input of `stft`. If `nothing` (default), then no window was applied. - `center::Bool`: Whether input to `stft` was padded on both sides so that ``t``-th frame is centered at time ``t \\times \\text{hop length}``. - Default is `true`. Padding is done with `pad_reflect` function. + Padding is done with `pad_reflect` function. - `normalized::Bool`: Whether input to `stft` was normalized. - `return_complex::Bool`: Whether the output should be complex, or if the input should be assumed to derive from a real signal and window. - Default `false`. - `original_length::Union{Nothing, Int}`: Optional size of the first dimension of the input to `stft`. Helps restoring the exact `stft` input size. Otherwise, the array might be a bit shorter.